[llvm] r325214 - [SCEV] Favor isKnownViaSimpleReasoning over constant ranges check
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 14 23:09:00 PST 2018
Author: mkazantsev
Date: Wed Feb 14 23:09:00 2018
New Revision: 325214
URL: http://llvm.org/viewvc/llvm-project?rev=325214&view=rev
Log:
[SCEV] Favor isKnownViaSimpleReasoning over constant ranges check
There is a more powerful but still simple function `isKnownViaSimpleReasoning ` that
does constant range check and few more additional checks. We use it some places (e.g.
when proving implications) and in some other places we only check constant ranges.
Currently, indvar simplifier fails to remove the check in following loop:
int inc = ...;
for (int i = inc, j = inc - 1; i < 200; ++i, ++j)
if (i > j) { ... }
This patch replaces all usages of `isKnownPredicateViaConstantRanges` with
`isKnownViaSimpleReasoning` to have smarter proofs. In particular, it fixes the
case above.
Reviewed-By: sanjoy
Differential Revision: https://reviews.llvm.org/D43175
Modified:
llvm/trunk/lib/Analysis/ScalarEvolution.cpp
llvm/trunk/test/Transforms/IndVarSimplify/loop-invariant-conditions.ll
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=325214&r1=325213&r2=325214&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Wed Feb 14 23:09:00 2018
@@ -8693,8 +8693,8 @@ bool ScalarEvolution::isKnownPredicate(I
if (isKnownPredicateViaSplitting(Pred, LHS, RHS))
return true;
- // Otherwise see what can be done with known constant ranges.
- return isKnownPredicateViaConstantRanges(Pred, LHS, RHS);
+ // Otherwise see what can be done with some simple reasoning.
+ return isKnownViaSimpleReasoning(Pred, LHS, RHS);
}
bool ScalarEvolution::isMonotonicPredicate(const SCEVAddRecExpr *LHS,
@@ -8961,7 +8961,7 @@ ScalarEvolution::isLoopBackedgeGuardedBy
// (interprocedural conditions notwithstanding).
if (!L) return true;
- if (isKnownPredicateViaConstantRanges(Pred, LHS, RHS))
+ if (isKnownViaSimpleReasoning(Pred, LHS, RHS))
return true;
BasicBlock *Latch = L->getLoopLatch();
@@ -9072,7 +9072,7 @@ ScalarEvolution::isLoopEntryGuardedByCon
assert(isAvailableAtLoopEntry(RHS, L) &&
"RHS is not available at Loop Entry");
- if (isKnownPredicateViaConstantRanges(Pred, LHS, RHS))
+ if (isKnownViaSimpleReasoning(Pred, LHS, RHS))
return true;
// If we cannot prove strict comparison (e.g. a > b), maybe we can prove
@@ -9087,9 +9087,9 @@ ScalarEvolution::isLoopEntryGuardedByCon
if (ProvingStrictComparison) {
ProvedNonStrictComparison =
- isKnownPredicateViaConstantRanges(NonStrictPredicate, LHS, RHS);
+ isKnownViaSimpleReasoning(NonStrictPredicate, LHS, RHS);
ProvedNonEquality =
- isKnownPredicateViaConstantRanges(ICmpInst::ICMP_NE, LHS, RHS);
+ isKnownViaSimpleReasoning(ICmpInst::ICMP_NE, LHS, RHS);
if (ProvedNonStrictComparison && ProvedNonEquality)
return true;
}
Modified: llvm/trunk/test/Transforms/IndVarSimplify/loop-invariant-conditions.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/loop-invariant-conditions.ll?rev=325214&r1=325213&r2=325214&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/loop-invariant-conditions.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/loop-invariant-conditions.ll Wed Feb 14 23:09:00 2018
@@ -355,6 +355,38 @@ exit:
ret void
}
+; check that we can prove that a recurrency is greater than another recurrency
+; in the same loop, with the same step, and with smaller starting value.
+define void @test12(i64* %inc_ptr) {
+; CHECK-LABEL: @test12
+entry:
+ %inc = load i64, i64* %inc_ptr, !range !0
+ %inc.minus.1 = sub i64 %inc, 1
+ br label %loop
+
+loop:
+ %iv = phi i64 [ %inc, %entry ], [ %iv.next, %backedge ]
+ %iv.minus.1 = phi i64 [ %inc.minus.1, %entry ], [ %iv.minus.1.next, %backedge ]
+ %iv.next = add i64 %iv, 1
+ %iv.minus.1.next = add i64 %iv.minus.1, 1
+ %brcond = icmp sgt i64 %iv.next, %iv.minus.1.next
+ ; CHECK: br i1 true, label %if.true, label %if.false
+ br i1 %brcond, label %if.true, label %if.false
+
+if.true:
+ br label %backedge
+
+if.false:
+ br label %backedge
+
+backedge:
+ %loopcond = icmp slt i64 %iv, 200
+ br i1 %loopcond, label %loop, label %exit
+
+exit:
+ ret void
+}
+
!1 = !{i64 -1, i64 100}
More information about the llvm-commits
mailing list