diff options
author | Andrew Kaylor <andrew.kaylor@intel.com> | 2016-08-10 18:56:35 +0000 |
---|---|---|
committer | Andrew Kaylor <andrew.kaylor@intel.com> | 2016-08-10 18:56:35 +0000 |
commit | 498d3113c35d8d4f80e4d79ac9b75c3980bfc8c3 (patch) | |
tree | dd331bbaed723ea0aa51d36d35fcc60e8aca7c96 /llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | |
parent | 02d784172c40325a12e481b4ffcb0618dcd13e78 (diff) | |
download | llvm-498d3113c35d8d4f80e4d79ac9b75c3980bfc8c3.zip llvm-498d3113c35d8d4f80e4d79ac9b75c3980bfc8c3.tar.gz llvm-498d3113c35d8d4f80e4d79ac9b75c3980bfc8c3.tar.bz2 |
[IndVarSimplify] Eliminate zext of a signed IV when the IV is known to be non-negative
Patch by Li Huang
Differential Revision: https://reviews.llvm.org/D18867
llvm-svn: 278269
Diffstat (limited to 'llvm/lib/Transforms/Scalar/IndVarSimplify.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index 4f6dbd9..4cb2d0d 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -36,6 +36,7 @@ #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" +#include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CFG.h" #include "llvm/IR/Constants.h" @@ -1281,7 +1282,8 @@ Instruction *WidenIV::widenIVUse(NarrowIVDefUse DU, SCEVExpander &Rewriter) { } } // Our raison d'etre! Eliminate sign and zero extension. - if (IsSigned ? isa<SExtInst>(DU.NarrowUse) : isa<ZExtInst>(DU.NarrowUse)) { + if ((isa<SExtInst>(DU.NarrowUse) && (IsSigned || DU.NeverNegative)) || + (isa<ZExtInst>(DU.NarrowUse) && (!IsSigned || DU.NeverNegative))) { Value *NewDef = DU.WideDef; if (DU.NarrowUse->getType() != WideType) { unsigned CastWidth = SE->getTypeSizeInBits(DU.NarrowUse->getType()); @@ -1370,9 +1372,12 @@ Instruction *WidenIV::widenIVUse(NarrowIVDefUse DU, SCEVExpander &Rewriter) { /// void WidenIV::pushNarrowIVUsers(Instruction *NarrowDef, Instruction *WideDef) { const SCEV *NarrowSCEV = SE->getSCEV(NarrowDef); + // isKnownPredicate is enough for most cases but still need isKnownNonNegative + // here to work around conservatism in ScalarEvolution about no-wrap flags. bool NeverNegative = SE->isKnownPredicate(ICmpInst::ICMP_SGE, NarrowSCEV, - SE->getConstant(NarrowSCEV->getType(), 0)); + SE->getConstant(NarrowSCEV->getType(), 0)) || + isKnownNonNegative(NarrowDef, NarrowDef->getModule()->getDataLayout()); for (User *U : NarrowDef->users()) { Instruction *NarrowUser = cast<Instruction>(U); |