1 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2 ; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" 2>&1 | FileCheck %s
4 ; Tests demonstrate the bug reported as PR48225 by Congzhe Cao.
6 ; When %boolcond = false and %cond = 0:
7 ; - %cond.false.on.first.iter is false on 1st iteration;
8 ; - %cond.false.on.second.iter is false on 2nd iteration;
9 ; - Therefore, their AND is false on first two iterations, and the backedge is taken twice.
10 ; 'constant max backedge-taken count is 1' is a bug caused by wrong treatment of AND
11 ; condition in the computation logic. It should be 2.
12 define void @test_and(i1 %boolcond) {
13 ; CHECK-LABEL: 'test_and'
14 ; CHECK-NEXT: Classifying expressions for: @test_and
15 ; CHECK-NEXT: %conv = zext i1 %boolcond to i32
16 ; CHECK-NEXT: --> (zext i1 %boolcond to i32) U: [0,2) S: [0,2)
17 ; CHECK-NEXT: %iv = phi i32 [ 0, %entry ], [ %inc, %backedge ]
18 ; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%loop> U: [0,3) S: [0,3) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
19 ; CHECK-NEXT: %or.cond = and i1 %cond.false.on.first.iter, %cond.false.on.second.iter
20 ; CHECK-NEXT: --> (%cond.false.on.first.iter umin %cond.false.on.second.iter) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
21 ; CHECK-NEXT: %inc = add nuw nsw i32 %iv, 1
22 ; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%loop> U: [1,4) S: [1,4) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
23 ; CHECK-NEXT: Determining loop execution counts for: @test_and
24 ; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
25 ; CHECK-NEXT: exit count for loop: 2
26 ; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE***
27 ; CHECK-NEXT: Loop %loop: constant max backedge-taken count is 2
28 ; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is 2
29 ; CHECK-NEXT: symbolic max exit count for loop: 2
30 ; CHECK-NEXT: symbolic max exit count for backedge: ***COULDNOTCOMPUTE***
31 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
34 %conv = zext i1 %boolcond to i32
38 %iv = phi i32 [ 0, %entry ], [ %inc, %backedge ]
39 %cmp = icmp ult i32 %iv, 2
40 br i1 %cmp, label %backedge, label %for.end
43 %cond.false.on.first.iter = icmp ne i32 %iv, 0
44 %cond.false.on.second.iter = icmp eq i32 %iv, %conv
45 %or.cond = and i1 %cond.false.on.first.iter, %cond.false.on.second.iter
46 %inc = add nuw nsw i32 %iv, 1
47 br i1 %or.cond, label %exit, label %loop
56 ; When %boolcond = false and %cond = 0:
57 ; - %cond.true.on.first.iter is true on 1st iteration;
58 ; - %cond.true.on.second.iter is true on 2nd iteration;
59 ; - Therefore, their OR is true on first two iterations, and the backedge is taken twice.
60 ; 'constant max backedge-taken count is 1' is a bug caused by wrong treatment of OR
61 ; condition in the computation logic. It should be 2.
62 define void @test_or(i1 %boolcond) {
63 ; CHECK-LABEL: 'test_or'
64 ; CHECK-NEXT: Classifying expressions for: @test_or
65 ; CHECK-NEXT: %conv = zext i1 %boolcond to i32
66 ; CHECK-NEXT: --> (zext i1 %boolcond to i32) U: [0,2) S: [0,2)
67 ; CHECK-NEXT: %iv = phi i32 [ 0, %entry ], [ %inc, %backedge ]
68 ; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%loop> U: [0,3) S: [0,3) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
69 ; CHECK-NEXT: %or.cond = or i1 %cond.true.on.first.iter, %cond.true.on.second.iter
70 ; CHECK-NEXT: --> (%cond.true.on.first.iter umax %cond.true.on.second.iter) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
71 ; CHECK-NEXT: %inc = add nuw nsw i32 %iv, 1
72 ; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%loop> U: [1,4) S: [1,4) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
73 ; CHECK-NEXT: Determining loop execution counts for: @test_or
74 ; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
75 ; CHECK-NEXT: exit count for loop: 2
76 ; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE***
77 ; CHECK-NEXT: Loop %loop: constant max backedge-taken count is 2
78 ; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is 2
79 ; CHECK-NEXT: symbolic max exit count for loop: 2
80 ; CHECK-NEXT: symbolic max exit count for backedge: ***COULDNOTCOMPUTE***
81 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
84 %conv = zext i1 %boolcond to i32
88 %iv = phi i32 [ 0, %entry ], [ %inc, %backedge ]
89 %cmp = icmp ult i32 %iv, 2
90 br i1 %cmp, label %backedge, label %for.end
93 %cond.true.on.first.iter = icmp eq i32 %iv, 0
94 %cond.true.on.second.iter = icmp ne i32 %iv, %conv
95 %or.cond = or i1 %cond.true.on.first.iter, %cond.true.on.second.iter
96 %inc = add nuw nsw i32 %iv, 1
97 br i1 %or.cond, label %loop, label %exit