summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorKrzysztof Parzyszek <kparzysz@codeaurora.org>2018-06-08 20:43:07 +0000
committerKrzysztof Parzyszek <kparzysz@codeaurora.org>2018-06-08 20:43:07 +0000
commitb10ea3927091da2c5b4798df5d49a35fbbec20c8 (patch)
treef0e0c544ef42995bf2d6603b8c4e5dc48838c837 /llvm/lib/Analysis/ScalarEvolution.cpp
parent189c2cf1142239bf1e344cd090143a15127f268a (diff)
downloadbcm5719-llvm-b10ea3927091da2c5b4798df5d49a35fbbec20c8.tar.gz
bcm5719-llvm-b10ea3927091da2c5b4798df5d49a35fbbec20c8.zip
[SCEV] Look through zero-extends in howFarToZero
An expression like (zext i2 {(trunc i32 (1 + %B) to i2),+,1}<%while.body> to i32) will become zero exactly when the nested value becomes zero in its type. Strip injective operations from the input value in howFarToZero to make the value simpler. Differential Revision: https://reviews.llvm.org/D47951 llvm-svn: 334318
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 7cc72c6c1ea..840861653be 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -8150,6 +8150,14 @@ const SCEV *ScalarEvolution::getSCEVAtScope(Value *V, const Loop *L) {
return getSCEVAtScope(getSCEV(V), L);
}
+const SCEV *ScalarEvolution::stripInjectiveFunctions(const SCEV *S) const {
+ if (const SCEVZeroExtendExpr *ZExt = dyn_cast<SCEVZeroExtendExpr>(S))
+ return stripInjectiveFunctions(ZExt->getOperand());
+ if (const SCEVSignExtendExpr *SExt = dyn_cast<SCEVSignExtendExpr>(S))
+ return stripInjectiveFunctions(SExt->getOperand());
+ return S;
+}
+
/// Finds the minimum unsigned root of the following equation:
///
/// A * X = B (mod N)
@@ -8279,7 +8287,9 @@ ScalarEvolution::howFarToZero(const SCEV *V, const Loop *L, bool ControlsExit,
return getCouldNotCompute(); // Otherwise it will loop infinitely.
}
- const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(V);
+ const SCEVAddRecExpr *AddRec =
+ dyn_cast<SCEVAddRecExpr>(stripInjectiveFunctions(V));
+
if (!AddRec && AllowPredicates)
// Try to make this an AddRec using runtime tests, in the first X
// iterations of this loop, where X is the SCEV expression found by the
OpenPOWER on IntegriCloud