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