1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2; RUN: opt -analyze -enable-new-pm=0 -scalar-evolution < %s | FileCheck %s
3; RUN: opt -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s
4
5; The semanics of this example are a bit subtle.  The loop is required
6; execute some number of times up to 1999.  The compiler is free to reduce
7; the number of said iterations to zero (or any value in between) if desired,
8; but if it does so, the return value and the last value stored to G must
9; agree.  For SCEV, this translates as widenable conditions preventing exact
10; exit counts from being computed, but not restricting max exit counts.
11; It's tempting to say that SCEV should return a precise exit count here, but
12; would result in miscompiles if transformations such as RLEV ran before
13; widening of the WC.
14define i32 @wc_max() {
15; CHECK-LABEL: 'wc_max'
16; CHECK-NEXT:  Classifying expressions for: @wc_max
17; CHECK-NEXT:    %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
18; CHECK-NEXT:    --> {0,+,1}<%loop> U: [0,2000) S: [0,2000) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
19; CHECK-NEXT:    %iv.next = add i32 %iv, 1
20; CHECK-NEXT:    --> {1,+,1}<%loop> U: [1,2001) S: [1,2001) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
21; CHECK-NEXT:    %widenable_cond3 = call i1 @llvm.experimental.widenable.condition()
22; CHECK-NEXT:    --> %widenable_cond3 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
23; CHECK-NEXT:    %exiplicit_guard_cond4 = and i1 %cond_1, %widenable_cond3
24; CHECK-NEXT:    --> %exiplicit_guard_cond4 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
25; CHECK-NEXT:  Determining loop execution counts for: @wc_max
26; CHECK-NEXT:  Loop %loop: Unpredictable backedge-taken count.
27; CHECK-NEXT:  Loop %loop: max backedge-taken count is 1999
28; CHECK-NEXT:  Loop %loop: Unpredictable predicated backedge-taken count.
29;
30entry:
31  br label %loop
32loop:
33  %iv = phi i32 [0, %entry], [%iv.next, %loop]
34  %iv.next = add i32 %iv, 1
35  store i32 %iv, i32 *@G
36  %cond_1 = icmp slt i32 %iv.next, 2000
37  %widenable_cond3 = call i1 @llvm.experimental.widenable.condition()
38  %exiplicit_guard_cond4 = and i1 %cond_1, %widenable_cond3
39  br i1 %exiplicit_guard_cond4, label %loop, label %exit
40
41exit:
42  ret i32 %iv
43}
44
45@G = external global i32
46declare i1 @llvm.experimental.widenable.condition()
47