[PATCH] D39590: [IRCE][NFC] Make range check's End a non-null SCEV
Max Kazantsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 11 23:00:22 PST 2018
mkazantsev updated this revision to Diff 129582.
mkazantsev added a comment.
Rebased.
https://reviews.llvm.org/D39590
Files:
lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
test/Transforms/IRCE/only-lower-check.ll
Index: test/Transforms/IRCE/only-lower-check.ll
===================================================================
--- test/Transforms/IRCE/only-lower-check.ll
+++ test/Transforms/IRCE/only-lower-check.ll
@@ -3,7 +3,7 @@
; CHECK: irce: loop has 1 inductive range checks:
; CHECK-NEXT: InductiveRangeCheck:
; CHECK-NEXT: Kind: RANGE_CHECK_LOWER
-; CHECK-NEXT: Begin: (-1 + %n) Step: -1 End: (null)
+; CHECK-NEXT: Begin: (-1 + %n) Step: -1 End: 2147483647
; CHECK-NEXT: CheckUse: br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1 Operand: 0
; CHECK-NEXT: irce: in function only_lower_check: constrained Loop at depth 1 containing: %loop<header><exiting>,%in.bounds<latch><exiting>
Index: lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
===================================================================
--- lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
@@ -179,10 +179,7 @@
OS << " Step: ";
Step->print(OS);
OS << " End: ";
- if (End)
- End->print(OS);
- else
- OS << "(null)";
+ End->print(OS);
OS << "\n CheckUse: ";
getCheckUse()->getUser()->print(OS);
OS << " Operand: " << getCheckUse()->getOperandNo() << "\n";
@@ -394,8 +391,23 @@
if (!IsAffineIndex)
return;
+ const SCEV *End = nullptr;
+ // We strengthen "0 <= I" to "0 <= I < INT_SMAX" and "I < L" to "0 <= I < L".
+ // We can potentially do much better here.
+ if (Length)
+ End = SE.getSCEV(Length);
+ else {
+ assert(RCKind == InductiveRangeCheck::RANGE_CHECK_LOWER && "invariant!");
+ // So far we can only reach this point for Signed range check. This may
+ // change in future. In this case we will need to pick Unsigned max for the
+ // unsigned range check.
+ unsigned BitWidth = cast<IntegerType>(IndexAddRec->getType())->getBitWidth();
+ const SCEV *SIntMax = SE.getConstant(APInt::getSignedMaxValue(BitWidth));
+ End = SIntMax;
+ }
+
InductiveRangeCheck IRC;
- IRC.End = Length ? SE.getSCEV(Length) : nullptr;
+ IRC.End = End;
IRC.Begin = IndexAddRec->getStart();
IRC.Step = IndexAddRec->getStepRecurrence(SE);
IRC.CheckUse = &ConditionUse;
@@ -1663,17 +1675,7 @@
const SCEV *M = SE.getMinusSCEV(C, A);
const SCEV *Zero = SE.getZero(M->getType());
const SCEV *Begin = ClampedSubstract(Zero, M);
- const SCEV *L = nullptr;
-
- // We strengthen "0 <= I" to "0 <= I < INT_SMAX" and "I < L" to "0 <= I < L".
- // We can potentially do much better here.
- if (const SCEV *EndLimit = getEnd())
- L = EndLimit;
- else {
- assert(Kind == InductiveRangeCheck::RANGE_CHECK_LOWER && "invariant!");
- L = SIntMax;
- }
- const SCEV *End = ClampedSubstract(L, M);
+ const SCEV *End = ClampedSubstract(getEnd(), M);
return InductiveRangeCheck::Range(Begin, End);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39590.129582.patch
Type: text/x-patch
Size: 2872 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180112/17397591/attachment.bin>
More information about the llvm-commits
mailing list