summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorEli Friedman <efriedma@codeaurora.org>2017-04-20 23:59:05 +0000
committerEli Friedman <efriedma@codeaurora.org>2017-04-20 23:59:05 +0000
commitd0e6ae56785b7ebf2688f71a146c81962efe9ece (patch)
tree3103475219190da09bb96b8f41647b953b4b90ff /llvm/lib/Analysis/ScalarEvolution.cpp
parent358cd9ae3a9b6f99054ea43af54ec08a39c28265 (diff)
downloadbcm5719-llvm-d0e6ae56785b7ebf2688f71a146c81962efe9ece.tar.gz
bcm5719-llvm-d0e6ae56785b7ebf2688f71a146c81962efe9ece.zip
Revert r300746 (SCEV analysis for or instructions).
There have been multiple reports of this causing problems: a compile-time explosion on the LLVM testsuite, and a stack overflow for an opencl kernel. llvm-svn: 300928
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp28
1 files changed, 22 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 700c383a9dd..593f78b4777 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -5328,12 +5328,28 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
break;
case Instruction::Or:
- // Use ValueTracking to check whether this is actually an add.
- if (haveNoCommonBitsSet(BO->LHS, BO->RHS, getDataLayout(), &AC,
- nullptr, &DT)) {
- // There aren't any common bits set, so the add can't wrap.
- auto Flags = SCEV::NoWrapFlags(SCEV::FlagNUW | SCEV::FlagNSW);
- return getAddExpr(getSCEV(BO->LHS), getSCEV(BO->RHS), Flags);
+ // If the RHS of the Or is a constant, we may have something like:
+ // X*4+1 which got turned into X*4|1. Handle this as an Add so loop
+ // optimizations will transparently handle this case.
+ //
+ // In order for this transformation to be safe, the LHS must be of the
+ // form X*(2^n) and the Or constant must be less than 2^n.
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(BO->RHS)) {
+ const SCEV *LHS = getSCEV(BO->LHS);
+ const APInt &CIVal = CI->getValue();
+ if (GetMinTrailingZeros(LHS) >=
+ (CIVal.getBitWidth() - CIVal.countLeadingZeros())) {
+ // Build a plain add SCEV.
+ const SCEV *S = getAddExpr(LHS, getSCEV(CI));
+ // If the LHS of the add was an addrec and it has no-wrap flags,
+ // transfer the no-wrap flags, since an or won't introduce a wrap.
+ if (const SCEVAddRecExpr *NewAR = dyn_cast<SCEVAddRecExpr>(S)) {
+ const SCEVAddRecExpr *OldAR = cast<SCEVAddRecExpr>(LHS);
+ const_cast<SCEVAddRecExpr *>(NewAR)->setNoWrapFlags(
+ OldAR->getNoWrapFlags());
+ }
+ return S;
+ }
}
break;
OpenPOWER on IntegriCloud