[llvm] r329907 - [IRCE] isKnownNonNegative helper function
Sam Parker via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 12 05:49:40 PDT 2018
Author: sam_parker
Date: Thu Apr 12 05:49:40 2018
New Revision: 329907
URL: http://llvm.org/viewvc/llvm-project?rev=329907&view=rev
Log:
[IRCE] isKnownNonNegative helper function
Created a helper function to query for non negative SCEVs. Uses the
SGE predicate to catch constants that could be interpreted as
negative.
Differential Revision: https://reviews.llvm.org/D45481
Modified:
llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
llvm/trunk/test/Transforms/IRCE/variable-loop-bounds.ll
Modified: llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp?rev=329907&r1=329906&r2=329907&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp Thu Apr 12 05:49:40 2018
@@ -804,6 +804,13 @@ static bool CannotBeMinInLoop(const SCEV
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 @@ LoopStructure::parseLoopStructure(Scalar
// 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;
Modified: llvm/trunk/test/Transforms/IRCE/variable-loop-bounds.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IRCE/variable-loop-bounds.ll?rev=329907&r1=329906&r2=329907&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IRCE/variable-loop-bounds.ll (original)
+++ llvm/trunk/test/Transforms/IRCE/variable-loop-bounds.ll Thu Apr 12 05:49:40 2018
@@ -55,7 +55,7 @@ for.inc:
; 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:
More information about the llvm-commits
mailing list