InstCombine: propagate nonNull through assume

Make assume (load (call|invoke) != null) set nonNull return attribute
for the call and invoke. Also include tests.

Differential Revision: http://reviews.llvm.org/D7107

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228556 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ramkumar Ramachandra
2015-02-09 01:13:13 +00:00
parent 218eccd638
commit 5439a80dca
2 changed files with 45 additions and 1 deletions

View File

@@ -1081,12 +1081,19 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
cast<Constant>(RHS)->isNullValue()) {
LoadInst* LI = cast<LoadInst>(LHS);
if (isValidAssumeForContext(II, LI, DL, DT)) {
// assume( load (call|invoke) != null ) -> add 'nonnull' return
// attribute
Value *LIOperand = LI->getOperand(0);
if (CallInst *I = dyn_cast<CallInst>(LIOperand))
I->addAttribute(AttributeSet::ReturnIndex, Attribute::NonNull);
else if (InvokeInst *I = dyn_cast<InvokeInst>(LIOperand))
I->addAttribute(AttributeSet::ReturnIndex, Attribute::NonNull);
MDNode *MD = MDNode::get(II->getContext(), None);
LI->setMetadata(LLVMContext::MD_nonnull, MD);
return EraseInstFromFunction(*II);
}
}
// TODO: apply nonnull return attributes to calls and invokes
// TODO: apply range metadata for range check patterns?
}
// If there is a dominating assume with the same condition as this one,