summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
diff options
context:
space:
mode:
authorMax Kazantsev <max.kazantsev@azul.com>2017-10-11 06:53:07 +0000
committerMax Kazantsev <max.kazantsev@azul.com>2017-10-11 06:53:07 +0000
commit25d8655dc22cae27c2c5190577370e558c5afff5 (patch)
tree795734c4af71ff9a59be27c86b004a5a660bd477 /llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
parenta2212f846b143c49754663057cb4d313526e018d (diff)
downloadbcm5719-llvm-25d8655dc22cae27c2c5190577370e558c5afff5.tar.gz
bcm5719-llvm-25d8655dc22cae27c2c5190577370e558c5afff5.zip
[IRCE] Do not process empty safe ranges
IRCE should not apply when the safe iteration range is proved to be empty. In this case we do unneeded job creating pre/post loops and then never go to the main loop. This patch makes IRCE not apply to empty safe ranges, adds test for this situation and also modifies one of existing tests where it used to happen slightly. Reviewed By: anna Differential Revision: https://reviews.llvm.org/D38577 llvm-svn: 315437
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
index cc0f2c5bb48..9cdc1d18963 100644
--- a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
@@ -176,6 +176,7 @@ public:
Type *getType() const { return Begin->getType(); }
const SCEV *getBegin() const { return Begin; }
const SCEV *getEnd() const { return End; }
+ bool isEmpty() const { return Begin == End; }
};
/// This is the value the condition of the branch needs to evaluate to for the
@@ -1654,8 +1655,11 @@ static Optional<InductiveRangeCheck::Range>
IntersectRange(ScalarEvolution &SE,
const Optional<InductiveRangeCheck::Range> &R1,
const InductiveRangeCheck::Range &R2) {
- if (!R1.hasValue())
- return R2;
+ if (!R1.hasValue()) {
+ if (!R2.isEmpty())
+ return R2;
+ return None;
+ }
auto &R1Value = R1.getValue();
// TODO: we could widen the smaller range and have this work; but for now we
@@ -1666,7 +1670,11 @@ IntersectRange(ScalarEvolution &SE,
const SCEV *NewBegin = SE.getSMaxExpr(R1Value.getBegin(), R2.getBegin());
const SCEV *NewEnd = SE.getSMinExpr(R1Value.getEnd(), R2.getEnd());
- return InductiveRangeCheck::Range(NewBegin, NewEnd);
+ // If the resulting range is empty, just return None.
+ auto Ret = InductiveRangeCheck::Range(NewBegin, NewEnd);
+ if (Ret.isEmpty())
+ return None;
+ return Ret;
}
bool InductiveRangeCheckElimination::runOnLoop(Loop *L, LPPassManager &LPM) {
@@ -1735,6 +1743,8 @@ bool InductiveRangeCheckElimination::runOnLoop(Loop *L, LPPassManager &LPM) {
auto MaybeSafeIterRange =
IntersectRange(SE, SafeIterRange, Result.getValue());
if (MaybeSafeIterRange.hasValue()) {
+ assert(!MaybeSafeIterRange.getValue().isEmpty() &&
+ "We should never return empty ranges!");
RangeChecksToEliminate.push_back(IRC);
SafeIterRange = MaybeSafeIterRange.getValue();
}
OpenPOWER on IntegriCloud