[PATCH] D45481: [IRCE] isKnownNonNegative helper

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 12 05:52:52 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL329907: [IRCE] isKnownNonNegative helper function (authored by sam_parker, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45481?vs=141817&id=142157#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45481

Files:
  llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
  llvm/trunk/test/Transforms/IRCE/variable-loop-bounds.ll


Index: llvm/trunk/test/Transforms/IRCE/variable-loop-bounds.ll
===================================================================
--- llvm/trunk/test/Transforms/IRCE/variable-loop-bounds.ll
+++ llvm/trunk/test/Transforms/IRCE/variable-loop-bounds.ll
@@ -55,7 +55,7 @@
 ; CHECK-LABEL: test_inc_ne
 ; CHECK: main.exit.selector:
 ; CHECK: [[PSEUDO_PHI:%[^ ]+]] = phi i32 [ %inc, %for.inc ]
-; CHECK: [[COND:%[^ ]+]] = icmp slt i32 [[PSEUDO_PHI]], %N
+; CHECK: [[COND:%[^ ]+]] = icmp ult i32 [[PSEUDO_PHI]], %N
 ; CHECK: br i1 [[COND]], label %main.pseudo.exit, label %for.cond.cleanup.loopexit
 define void @test_inc_ne(i32* nocapture %a, i32* nocapture readonly %b, i32* nocapture readonly %c, i32 %N) {
 entry:
Index: llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
@@ -804,6 +804,13 @@
                                      SE.getConstant(Min));
 }
 
+static bool isKnownNonNegativeInLoop(const SCEV *BoundSCEV, Loop *L,
+                                     ScalarEvolution &SE) {
+  const SCEV *Zero = SE.getZero(BoundSCEV->getType());
+  return SE.isAvailableAtLoopEntry(BoundSCEV, L) &&
+         SE.isLoopEntryGuardedByCond(L, ICmpInst::ICMP_SGE, BoundSCEV, Zero);
+}
+
 Optional<LoopStructure>
 LoopStructure::parseLoopStructure(ScalarEvolution &SE,
                                   BranchProbabilityInfo *BPI, Loop &L,
@@ -963,8 +970,8 @@
         // If both parts are known non-negative, it is profitable to use
         // unsigned comparison in increasing loop. This allows us to make the
         // comparison check against "RightSCEV + 1" more optimistic.
-        if (SE.isKnownNonNegative(IndVarStart) &&
-            SE.isKnownNonNegative(RightSCEV))
+        if (isKnownNonNegativeInLoop(IndVarStart, &L, SE) &&
+            isKnownNonNegativeInLoop(RightSCEV, &L, SE))
           Pred = ICmpInst::ICMP_ULT;
         else
           Pred = ICmpInst::ICMP_SLT;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45481.142157.patch
Type: text/x-patch
Size: 2112 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180412/074fa9a9/attachment.bin>


More information about the llvm-commits mailing list