[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
Fri Jan 12 02:04:20 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL322364: [IRCE][NFC] Make range check's End a non-null SCEV (authored by mkazantsev, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D39590?vs=129582&id=129592#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39590

Files:
  llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
  llvm/trunk/test/Transforms/IRCE/only-lower-check.ll


Index: llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ llvm/trunk/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);
 }
 
Index: llvm/trunk/test/Transforms/IRCE/only-lower-check.ll
===================================================================
--- llvm/trunk/test/Transforms/IRCE/only-lower-check.ll
+++ llvm/trunk/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>
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39590.129592.patch
Type: text/x-patch
Size: 2938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180112/e5307c43/attachment.bin>


More information about the llvm-commits mailing list