1 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2 ; RUN: opt < %s -S -scalar-evolution-use-expensive-range-sharpening -analyze -scalar-evolution -enable-new-pm=0 | FileCheck %s
3 ; RUN: opt < %s -S -scalar-evolution-use-expensive-range-sharpening -passes='print<scalar-evolution>' 2>&1 | FileCheck %s
5 define i32 @test_01(i32 %start, i32* %p, i32* %q) {
6 ; CHECK-LABEL: 'test_01'
7 ; CHECK-NEXT: Classifying expressions for: @test_01
8 ; CHECK-NEXT: %0 = zext i32 %start to i64
9 ; CHECK-NEXT: --> (zext i32 %start to i64) U: [0,4294967296) S: [0,4294967296)
10 ; CHECK-NEXT: %indvars.iv = phi i64 [ %indvars.iv.next, %backedge ], [ %0, %entry ]
11 ; CHECK-NEXT: --> {(zext i32 %start to i64),+,-1}<nsw><%loop> U: [0,4294967296) S: [0,4294967296) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
12 ; CHECK-NEXT: %iv = phi i32 [ %start, %entry ], [ %iv.next, %backedge ]
13 ; CHECK-NEXT: --> {%start,+,-1}<%loop> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
14 ; CHECK-NEXT: %iv.next = add i32 %iv, -1
15 ; CHECK-NEXT: --> {(-1 + %start),+,-1}<%loop> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
16 ; CHECK-NEXT: %index = zext i32 %iv.next to i64
17 ; CHECK-NEXT: --> (zext i32 {(-1 + %start),+,-1}<%loop> to i64) U: [0,4294967296) S: [0,4294967296) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
18 ; CHECK-NEXT: %store.addr = getelementptr i32, i32* %p, i64 %index
19 ; CHECK-NEXT: --> ((4 * (zext i32 {(-1 + %start),+,-1}<%loop> to i64))<nuw><nsw> + %p) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
20 ; CHECK-NEXT: %load.addr = getelementptr i32, i32* %q, i64 %index
21 ; CHECK-NEXT: --> ((4 * (zext i32 {(-1 + %start),+,-1}<%loop> to i64))<nuw><nsw> + %q) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
22 ; CHECK-NEXT: %stop = load i32, i32* %load.addr, align 4
23 ; CHECK-NEXT: --> %stop U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
24 ; CHECK-NEXT: %indvars.iv.next = add nsw i64 %indvars.iv, -1
25 ; CHECK-NEXT: --> {(-1 + (zext i32 %start to i64))<nsw>,+,-1}<nsw><%loop> U: [-4294967296,4294967295) S: [-1,4294967295) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
26 ; CHECK-NEXT: Determining loop execution counts for: @test_01
27 ; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
28 ; CHECK-NEXT: exit count for loop: (zext i32 %start to i64)
29 ; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE***
30 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 4294967295
31 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
34 %0 = zext i32 %start to i64
37 loop: ; preds = %backedge, %entry
38 %indvars.iv = phi i64 [ %indvars.iv.next, %backedge ], [ %0, %entry ]
39 %iv = phi i32 [ %start, %entry ], [ %iv.next, %backedge ]
40 %cond = icmp eq i64 %indvars.iv, 0
41 br i1 %cond, label %exit, label %backedge
43 backedge: ; preds = %loop
44 %iv.next = add i32 %iv, -1
45 %index = zext i32 %iv.next to i64
46 %store.addr = getelementptr i32, i32* %p, i64 %index
47 store i32 1, i32* %store.addr, align 4
48 %load.addr = getelementptr i32, i32* %q, i64 %index
49 %stop = load i32, i32* %load.addr, align 4
50 %loop.cond = icmp eq i32 %stop, 0
51 %indvars.iv.next = add nsw i64 %indvars.iv, -1
52 br i1 %loop.cond, label %loop, label %failure
57 failure: ; preds = %backedge
61 ; Check that we do not mess up with wrapping ranges.
62 define i32 @test_02(i32 %start, i32* %p, i32* %q) {
63 ; CHECK-LABEL: 'test_02'
64 ; CHECK-NEXT: Classifying expressions for: @test_02
65 ; CHECK-NEXT: %zext = zext i32 %start to i64
66 ; CHECK-NEXT: --> (zext i32 %start to i64) U: [0,4294967296) S: [0,4294967296)
67 ; CHECK-NEXT: %shl = shl i64 %zext, 31
68 ; CHECK-NEXT: --> (2147483648 * (zext i32 %start to i64))<nuw><nsw> U: [0,9223372034707292161) S: [0,9223372034707292161)
69 ; CHECK-NEXT: %indvars.iv = phi i64 [ %indvars.iv.next, %loop ], [ %shl, %entry ]
70 ; CHECK-NEXT: --> {(2147483648 * (zext i32 %start to i64))<nuw><nsw>,+,-1}<nsw><%loop> U: [-9223372036854775808,9223372034707292161) S: [-9223372036854775808,9223372034707292161) Exits: -9223372036854775806 LoopDispositions: { %loop: Computable }
71 ; CHECK-NEXT: %indvars.iv.next = add nsw i64 %indvars.iv, -1
72 ; CHECK-NEXT: --> {(-1 + (2147483648 * (zext i32 %start to i64))<nuw><nsw>)<nsw>,+,-1}<nw><%loop> U: full-set S: full-set Exits: -9223372036854775807 LoopDispositions: { %loop: Computable }
73 ; CHECK-NEXT: Determining loop execution counts for: @test_02
74 ; CHECK-NEXT: Loop %loop: backedge-taken count is (9223372036854775806 + (2147483648 * (zext i32 %start to i64))<nuw><nsw>)<nuw>
75 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -2147483650
76 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (9223372036854775806 + (2147483648 * (zext i32 %start to i64))<nuw><nsw>)<nuw>
77 ; CHECK-NEXT: Predicates:
78 ; CHECK: Loop %loop: Trip multiple is 1
81 %zext = zext i32 %start to i64
82 %shl = shl i64 %zext, 31
85 loop: ; preds = %backedge, %entry
86 %indvars.iv = phi i64 [ %indvars.iv.next, %loop ], [ %shl, %entry ]
87 %cond = icmp eq i64 %indvars.iv, -9223372036854775806
88 %indvars.iv.next = add nsw i64 %indvars.iv, -1
89 br i1 %cond, label %exit, label %loop
95 define void @pointer_iv_nowrap(i8* %startptr, i8* %endptr) local_unnamed_addr {
96 ; CHECK-LABEL: 'pointer_iv_nowrap'
97 ; CHECK-NEXT: Classifying expressions for: @pointer_iv_nowrap
98 ; CHECK-NEXT: %init = getelementptr inbounds i8, i8* %startptr, i64 2000
99 ; CHECK-NEXT: --> (2000 + %startptr)<nuw> U: [2000,0) S: [2000,0)
100 ; CHECK-NEXT: %iv = phi i8* [ %init, %entry ], [ %iv.next, %loop ]
101 ; CHECK-NEXT: --> {(2000 + %startptr)<nuw>,+,1}<nuw><%loop> U: [2000,0) S: [2000,0) Exits: ((-1 * (ptrtoint i8* %startptr to i64)) + ((2000 + (ptrtoint i8* %startptr to i64))<nuw> umax (ptrtoint i8* %endptr to i64)) + %startptr) LoopDispositions: { %loop: Computable }
102 ; CHECK-NEXT: %iv.next = getelementptr inbounds i8, i8* %iv, i64 1
103 ; CHECK-NEXT: --> {(2001 + %startptr)<nuw>,+,1}<nuw><%loop> U: [2001,0) S: [2001,0) Exits: (1 + (-1 * (ptrtoint i8* %startptr to i64)) + ((2000 + (ptrtoint i8* %startptr to i64))<nuw> umax (ptrtoint i8* %endptr to i64)) + %startptr) LoopDispositions: { %loop: Computable }
104 ; CHECK-NEXT: Determining loop execution counts for: @pointer_iv_nowrap
105 ; CHECK-NEXT: Loop %loop: backedge-taken count is (-2000 + (-1 * (ptrtoint i8* %startptr to i64)) + ((2000 + (ptrtoint i8* %startptr to i64))<nuw> umax (ptrtoint i8* %endptr to i64)))
106 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -2001
107 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-2000 + (-1 * (ptrtoint i8* %startptr to i64)) + ((2000 + (ptrtoint i8* %startptr to i64))<nuw> umax (ptrtoint i8* %endptr to i64)))
108 ; CHECK-NEXT: Predicates:
109 ; CHECK: Loop %loop: Trip multiple is 1
112 %init = getelementptr inbounds i8, i8* %startptr, i64 2000
116 %iv = phi i8* [ %init, %entry ], [ %iv.next, %loop ]
117 %iv.next = getelementptr inbounds i8, i8* %iv, i64 1
118 %ec = icmp ugt i8* %iv.next, %endptr
119 br i1 %ec, label %end, label %loop
125 define i32 @dummy(i32 %start, i32* %p, i32* %q) {