[llvm] r355259 - [SCEV] Handle case where MaxBECount is less precise than ExactBECount for OR.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 1 18:31:45 PST 2019
Author: fhahn
Date: Fri Mar 1 18:31:44 2019
New Revision: 355259
URL: http://llvm.org/viewvc/llvm-project?rev=355259&view=rev
Log:
[SCEV] Handle case where MaxBECount is less precise than ExactBECount for OR.
In some cases, MaxBECount can be less precise than ExactBECount for AND
and OR (the AND case was PR26207). In the OR test case, both ExactBECounts are
undef, but MaxBECount are different, so we hit the assertion below. This
patch uses the same solution the AND case already uses.
Assertion failed:
((isa<SCEVCouldNotCompute>(ExactNotTaken) || !isa<SCEVCouldNotCompute>(MaxNotTaken))
&& "Exact is not allowed to be less precise than Max"), function ExitLimit
This patch also consolidates test cases for both AND and OR in a single
test case.
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=13245
Reviewers: sanjoy, efriedma, mkazantsev
Reviewed By: sanjoy
Differential Revision: https://reviews.llvm.org/D58853
Added:
llvm/trunk/test/Analysis/ScalarEvolution/exact-exit-count-more-precise.ll
Removed:
llvm/trunk/test/Transforms/IndVarSimplify/pr26207.ll
Modified:
llvm/trunk/lib/Analysis/ScalarEvolution.cpp
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=355259&r1=355258&r2=355259&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Fri Mar 1 18:31:44 2019
@@ -7272,6 +7272,14 @@ ScalarEvolution::ExitLimit ScalarEvoluti
if (EL0.ExactNotTaken == EL1.ExactNotTaken)
BECount = EL0.ExactNotTaken;
}
+ // There are cases (e.g. PR26207) where computeExitLimitFromCond is able
+ // to be more aggressive when computing BECount than when computing
+ // MaxBECount. In these cases it is possible for EL0.ExactNotTaken and
+ // EL1.ExactNotTaken to match, but for EL0.MaxNotTaken and EL1.MaxNotTaken
+ // to not.
+ if (isa<SCEVCouldNotCompute>(MaxBECount) &&
+ !isa<SCEVCouldNotCompute>(BECount))
+ MaxBECount = getConstant(getUnsignedRangeMax(BECount));
return ExitLimit(BECount, MaxBECount, false,
{&EL0.Predicates, &EL1.Predicates});
Added: llvm/trunk/test/Analysis/ScalarEvolution/exact-exit-count-more-precise.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/exact-exit-count-more-precise.ll?rev=355259&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/exact-exit-count-more-precise.ll (added)
+++ llvm/trunk/test/Analysis/ScalarEvolution/exact-exit-count-more-precise.ll Fri Mar 1 18:31:44 2019
@@ -0,0 +1,49 @@
+; RUN: opt -analyze -scalar-evolution %s | FileCheck %s
+
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @test_and(i16 %in) {
+ br label %bb2
+
+bb2: ; preds = %bb1.i, %bb2, %0
+ %_tmp44.i = icmp slt i16 %in, 2
+ br i1 %_tmp44.i, label %bb1.i, label %bb2
+
+bb1.i: ; preds = %bb1.i, %bb2
+ %_tmp25.i = phi i16 [ %in, %bb2 ], [ %_tmp6.i, %bb1.i ]
+ %_tmp6.i = add nsw i16 %_tmp25.i, 1
+ %_tmp10.i = icmp sge i16 %_tmp6.i, 2
+ %exitcond.i = icmp eq i16 %_tmp6.i, 2
+ %or.cond = and i1 %_tmp10.i, %exitcond.i
+ br i1 %or.cond, label %bb2, label %bb1.i
+}
+
+; CHECK-LABEL: Determining loop execution counts for: @test_and
+; CHECK-NEXT: Loop %bb1.i: backedge-taken count is (1 + (-1 * %in))
+; CHECK-NEXT: Loop %bb1.i: max backedge-taken count is -1
+; CHECK-NEXT: Loop %bb1.i: Predicated backedge-taken count is (1 + (-1 * %in))
+
+
+define void @test_or() {
+ %C10 = icmp slt i1 undef, undef
+ br i1 %C10, label %BB, label %exit
+
+BB: ; preds = %BB, %0
+ %indvars.iv = phi i64 [ -1, %BB ], [ -1, %0 ]
+ %sum.01 = phi i32 [ %2, %BB ], [ undef, %0 ]
+ %1 = trunc i64 %indvars.iv to i32
+ %2 = add nsw i32 %1, %sum.01
+ %B3 = add i32 %1, %2
+ %C11 = icmp ult i32 %2, %1
+ %C5 = icmp sle i32 %1, %B3
+ %B = or i1 %C5, %C11
+ br i1 %B, label %BB, label %exit
+
+exit: ; preds = %BB, %0
+ ret void
+}
+
+; CHECK-LABEL: Determining loop execution counts for: @test_or
+; CHECK-NEXT: Loop %BB: backedge-taken count is undef
+; CHECK-NEXT: Loop %BB: max backedge-taken count is -1
+; CHECK-NEXT: Loop %BB: Predicated backedge-taken count is undef
Removed: llvm/trunk/test/Transforms/IndVarSimplify/pr26207.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/pr26207.ll?rev=355258&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/pr26207.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/pr26207.ll (removed)
@@ -1,20 +0,0 @@
-; RUN: opt -S -indvars < %s | FileCheck %s
-
-target triple = "x86_64-unknown-linux-gnu"
-
-define void @main(i16 %in) {
-; CHECK-LABEL: @main(
- br label %bb2
-
-bb2: ; preds = %bb1.i, %bb2, %0
- %_tmp44.i = icmp slt i16 %in, 2
- br i1 %_tmp44.i, label %bb1.i, label %bb2
-
-bb1.i: ; preds = %bb1.i, %bb2
- %_tmp25.i = phi i16 [ %in, %bb2 ], [ %_tmp6.i, %bb1.i ]
- %_tmp6.i = add nsw i16 %_tmp25.i, 1
- %_tmp10.i = icmp sge i16 %_tmp6.i, 2
- %exitcond.i = icmp eq i16 %_tmp6.i, 2
- %or.cond = and i1 %_tmp10.i, %exitcond.i
- br i1 %or.cond, label %bb2, label %bb1.i
-}
More information about the llvm-commits
mailing list