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 ; '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: --> %or.cond 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: max backedge-taken count is 2
28 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
31 %conv = zext i1 %boolcond to i32
35 %iv = phi i32 [ 0, %entry ], [ %inc, %backedge ]
36 %cmp = icmp ult i32 %iv, 2
37 br i1 %cmp, label %backedge, label %for.end
40 %cond.false.on.first.iter = icmp ne i32 %iv, 0
41 %cond.false.on.second.iter = icmp eq i32 %iv, %conv
42 %or.cond = and i1 %cond.false.on.first.iter, %cond.false.on.second.iter
43 %inc = add nuw nsw i32 %iv, 1
44 br i1 %or.cond, label %exit, label %loop
53 ; When %boolcond = false and %cond = 0:
54 ; - %cond.true.on.first.iter is true on 1st iteration;
55 ; - %cond.true.on.second.iter is true on 2nd iteration;
56 ; - Therefore, their OR is true on first two iterations, and the backedge is taken twice.
57 ; 'max backedge-taken count is 1' is a bug caused by wrong treatment of OR
58 ; condition in the computation logic. It should be 2.
59 define void @test_or(i1 %boolcond) {
60 ; CHECK-LABEL: 'test_or'
61 ; CHECK-NEXT: Classifying expressions for: @test_or
62 ; CHECK-NEXT: %conv = zext i1 %boolcond to i32
63 ; CHECK-NEXT: --> (zext i1 %boolcond to i32) U: [0,2) S: [0,2)
64 ; CHECK-NEXT: %iv = phi i32 [ 0, %entry ], [ %inc, %backedge ]
65 ; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%loop> U: [0,3) S: [0,3) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
66 ; CHECK-NEXT: %or.cond = or i1 %cond.true.on.first.iter, %cond.true.on.second.iter
67 ; CHECK-NEXT: --> %or.cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
68 ; CHECK-NEXT: %inc = add nuw nsw i32 %iv, 1
69 ; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%loop> U: [1,4) S: [1,4) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
70 ; CHECK-NEXT: Determining loop execution counts for: @test_or
71 ; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
72 ; CHECK-NEXT: exit count for loop: 2
73 ; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE***
74 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 2
75 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
78 %conv = zext i1 %boolcond to i32
82 %iv = phi i32 [ 0, %entry ], [ %inc, %backedge ]
83 %cmp = icmp ult i32 %iv, 2
84 br i1 %cmp, label %backedge, label %for.end
87 %cond.true.on.first.iter = icmp eq i32 %iv, 0
88 %cond.true.on.second.iter = icmp ne i32 %iv, %conv
89 %or.cond = or i1 %cond.true.on.first.iter, %cond.true.on.second.iter
90 %inc = add nuw nsw i32 %iv, 1
91 br i1 %or.cond, label %loop, label %exit