diff options
author | Igor Laevsky <igmyrj@gmail.com> | 2015-09-15 17:51:50 +0000 |
---|---|---|
committer | Igor Laevsky <igmyrj@gmail.com> | 2015-09-15 17:51:50 +0000 |
commit | bdc1eafe20e60362a5ee712b0beee0229ac66de5 (patch) | |
tree | c8dd56ade449c96ab947579ff60185f0a712cde5 /llvm/lib/Transforms | |
parent | ecb156aba2cecd53f5153ca2f36d22e36b6f836d (diff) | |
download | bcm5719-llvm-bdc1eafe20e60362a5ee712b0beee0229ac66de5.tar.gz bcm5719-llvm-bdc1eafe20e60362a5ee712b0beee0229ac66de5.zip |
[CorrelatedValuePropagation] Infer nonnull attributes
LazuValueInfo can prove that value is nonnull based on the context information.
Make use of this ability to infer nonnull attributes for the call arguments.
Differential Revision: http://reviews.llvm.org/D12836
llvm-svn: 247707
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index 8706dfee73d..ac12427015d 100644 --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -44,6 +44,7 @@ namespace { bool processMemAccess(Instruction *I); bool processCmp(CmpInst *C); bool processSwitch(SwitchInst *SI); + bool processCallSite(CallSite CS); public: static char ID; @@ -309,6 +310,32 @@ bool CorrelatedValuePropagation::processSwitch(SwitchInst *SI) { return Changed; } +/// processCallSite - Infer nonnull attributes for the arguments at the +/// specified callsite. +bool CorrelatedValuePropagation::processCallSite(CallSite CS) { + bool Changed = false; + + unsigned ArgNo = 0; + for (Value *V : CS.args()) { + PointerType *Type = dyn_cast<PointerType>(V->getType()); + + if (Type && !CS.paramHasAttr(ArgNo + 1, Attribute::NonNull) && + LVI->getPredicateAt(ICmpInst::ICMP_EQ, V, + ConstantPointerNull::get(Type), + CS.getInstruction()) == LazyValueInfo::False) { + AttributeSet AS = CS.getAttributes(); + AS = AS.addAttribute(CS.getInstruction()->getContext(), ArgNo + 1, + Attribute::NonNull); + CS.setAttributes(AS); + Changed = true; + } + ArgNo++; + } + assert(ArgNo == CS.arg_size() && "sanity check"); + + return Changed; +} + bool CorrelatedValuePropagation::runOnFunction(Function &F) { if (skipOptnoneFunction(F)) return false; @@ -336,6 +363,10 @@ bool CorrelatedValuePropagation::runOnFunction(Function &F) { case Instruction::Store: BBChanged |= processMemAccess(II); break; + case Instruction::Call: + case Instruction::Invoke: + BBChanged |= processCallSite(CallSite(II)); + break; } } |