From 25d8655dc22cae27c2c5190577370e558c5afff5 Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Wed, 11 Oct 2017 06:53:07 +0000 Subject: [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 --- .../Transforms/Scalar/InductiveRangeCheckElimination.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp') 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 IntersectRange(ScalarEvolution &SE, const Optional &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(); } -- cgit v1.2.3