llvm.org GIT mirror llvm / 4ee8739
When analyzing loop exit conditions combined with and and or, don't make any assumptions about when the two conditions will agree on when to permit the loop to exit. This fixes PR7845. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110758 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 9 years ago
2 changed file(s) with 52 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
38533853 else
38543854 MaxBECount = getUMinFromMismatchedTypes(BTI0.Max, BTI1.Max);
38553855 } else {
3856 // Both conditions must be true for the loop to exit.
3856 // Both conditions must be true at the same time for the loop to exit.
3857 // For now, be conservative.
38573858 assert(L->contains(FBB) && "Loop block has no successor in loop!");
3858 if (BTI0.Exact != getCouldNotCompute() &&
3859 BTI1.Exact != getCouldNotCompute())
3860 BECount = getUMaxFromMismatchedTypes(BTI0.Exact, BTI1.Exact);
3861 if (BTI0.Max != getCouldNotCompute() &&
3862 BTI1.Max != getCouldNotCompute())
3863 MaxBECount = getUMaxFromMismatchedTypes(BTI0.Max, BTI1.Max);
3859 if (BTI0.Max == BTI1.Max)
3860 MaxBECount = BTI0.Max;
3861 if (BTI0.Exact == BTI1.Exact)
3862 BECount = BTI0.Exact;
38643863 }
38653864
38663865 return BackedgeTakenInfo(BECount, MaxBECount);
38883887 else
38893888 MaxBECount = getUMinFromMismatchedTypes(BTI0.Max, BTI1.Max);
38903889 } else {
3891 // Both conditions must be false for the loop to exit.
3890 // Both conditions must be false at the same time for the loop to exit.
3891 // For now, be conservative.
38923892 assert(L->contains(TBB) && "Loop block has no successor in loop!");
3893 if (BTI0.Exact != getCouldNotCompute() &&
3894 BTI1.Exact != getCouldNotCompute())
3895 BECount = getUMaxFromMismatchedTypes(BTI0.Exact, BTI1.Exact);
3896 if (BTI0.Max != getCouldNotCompute() &&
3897 BTI1.Max != getCouldNotCompute())
3898 MaxBECount = getUMaxFromMismatchedTypes(BTI0.Max, BTI1.Max);
3893 if (BTI0.Max == BTI1.Max)
3894 MaxBECount = BTI0.Max;
3895 if (BTI0.Exact == BTI1.Exact)
3896 BECount = BTI0.Exact;
38993897 }
39003898
39013899 return BackedgeTakenInfo(BECount, MaxBECount);
None ; RUN: opt < %s -analyze -scalar-evolution \
1 ; RUN: | grep {\{%d,+,\[^\{\}\]\*\}<%bb>}
0 ; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s
21
32 ; ScalarEvolution should be able to understand the loop and eliminate the casts.
3
4 ; CHECK: {%d,+,sizeof(i32)}
45
56 define void @foo(i32* nocapture %d, i32 %n) nounwind {
67 entry:
3132 return: ; preds = %bb1.return_crit_edge, %entry
3233 ret void
3334 }
35
36 ; ScalarEvolution should be able to find the maximum tripcount
37 ; of this multiple-exit loop, and if it doesn't know the exact
38 ; count, it should say so.
39
40 ; PR7845
41 ; CHECK: Loop %for.cond: Unpredictable backedge-taken count.
42 ; CHECK: Loop %for.cond: max backedge-taken count is 5
43
44 @.str = private constant [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=2]
45
46 define i32 @main() nounwind {
47 entry:
48 br label %for.cond
49
50 for.cond: ; preds = %for.inc, %entry
51 %g_4.0 = phi i32 [ 0, %entry ], [ %add, %for.inc ] ; [#uses=5]
52 %cmp = icmp slt i32 %g_4.0, 5 ; [#uses=1]
53 br i1 %cmp, label %for.body, label %for.end
54
55 for.body: ; preds = %for.cond
56 %conv = trunc i32 %g_4.0 to i16 ; [#uses=1]
57 %tobool.not = icmp eq i16 %conv, 0 ; [#uses=1]
58 %tobool3 = icmp ne i32 %g_4.0, 0 ; [#uses=1]
59 %or.cond = and i1 %tobool.not, %tobool3 ; [#uses=1]
60 br i1 %or.cond, label %for.end, label %for.inc
61
62 for.inc: ; preds = %for.body
63 %add = add nsw i32 %g_4.0, 1 ; [#uses=1]
64 br label %for.cond
65
66 for.end: ; preds = %for.body, %for.cond
67 %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x i8]* @.str, i64 0, i64 0), i32 %g_4.0) nounwind ; [#uses=0]
68 ret i32 0
69 }
70
71 declare i32 @printf(i8*, ...)