1 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2 ; RUN: opt < %s -disable-output -scalar-evolution-use-expensive-range-sharpening -passes='print<scalar-evolution>' 2>&1 | FileCheck %s
4 define i32 @test_01(i32 %start, ptr %p, ptr %q) {
5 ; CHECK-LABEL: 'test_01'
6 ; CHECK-NEXT: Classifying expressions for: @test_01
7 ; CHECK-NEXT: %0 = zext i32 %start to i64
8 ; CHECK-NEXT: --> (zext i32 %start to i64) U: [0,4294967296) S: [0,4294967296)
9 ; CHECK-NEXT: %indvars.iv = phi i64 [ %indvars.iv.next, %backedge ], [ %0, %entry ]
10 ; CHECK-NEXT: --> {(zext i32 %start to i64),+,-1}<nsw><%loop> U: [0,4294967296) S: [0,4294967296) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
11 ; CHECK-NEXT: %iv = phi i32 [ %start, %entry ], [ %iv.next, %backedge ]
12 ; CHECK-NEXT: --> {%start,+,-1}<%loop> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
13 ; CHECK-NEXT: %iv.next = add i32 %iv, -1
14 ; CHECK-NEXT: --> {(-1 + %start),+,-1}<%loop> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
15 ; CHECK-NEXT: %index = zext i32 %iv.next to i64
16 ; CHECK-NEXT: --> (zext i32 {(-1 + %start),+,-1}<%loop> to i64) U: [0,4294967296) S: [0,4294967296) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
17 ; CHECK-NEXT: %store.addr = getelementptr i32, ptr %p, i64 %index
18 ; 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 }
19 ; CHECK-NEXT: %load.addr = getelementptr i32, ptr %q, i64 %index
20 ; 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 }
21 ; CHECK-NEXT: %stop = load i32, ptr %load.addr, align 4
22 ; CHECK-NEXT: --> %stop U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
23 ; CHECK-NEXT: %indvars.iv.next = add nsw i64 %indvars.iv, -1
24 ; CHECK-NEXT: --> {(-1 + (zext i32 %start to i64))<nsw>,+,-1}<nsw><%loop> U: [-4294967296,4294967295) S: [-1,4294967295) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
25 ; CHECK-NEXT: Determining loop execution counts for: @test_01
26 ; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
27 ; CHECK-NEXT: exit count for loop: (zext i32 %start to i64)
28 ; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE***
29 ; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i64 4294967295
30 ; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (zext i32 %start to i64)
31 ; CHECK-NEXT: symbolic max exit count for loop: (zext i32 %start to i64)
32 ; CHECK-NEXT: symbolic max exit count for backedge: ***COULDNOTCOMPUTE***
35 %0 = zext i32 %start to i64
38 loop: ; preds = %backedge, %entry
39 %indvars.iv = phi i64 [ %indvars.iv.next, %backedge ], [ %0, %entry ]
40 %iv = phi i32 [ %start, %entry ], [ %iv.next, %backedge ]
41 %cond = icmp eq i64 %indvars.iv, 0
42 br i1 %cond, label %exit, label %backedge
44 backedge: ; preds = %loop
45 %iv.next = add i32 %iv, -1
46 %index = zext i32 %iv.next to i64
47 %store.addr = getelementptr i32, ptr %p, i64 %index
48 store i32 1, ptr %store.addr, align 4
49 %load.addr = getelementptr i32, ptr %q, i64 %index
50 %stop = load i32, ptr %load.addr, align 4
51 %loop.cond = icmp eq i32 %stop, 0
52 %indvars.iv.next = add nsw i64 %indvars.iv, -1
53 br i1 %loop.cond, label %loop, label %failure
58 failure: ; preds = %backedge
62 ; Check that we do not mess up with wrapping ranges.
63 define i32 @test_02(i32 %start, ptr %p, ptr %q) {
64 ; CHECK-LABEL: 'test_02'
65 ; CHECK-NEXT: Classifying expressions for: @test_02
66 ; CHECK-NEXT: %zext = zext i32 %start to i64
67 ; CHECK-NEXT: --> (zext i32 %start to i64) U: [0,4294967296) S: [0,4294967296)
68 ; CHECK-NEXT: %shl = shl i64 %zext, 31
69 ; CHECK-NEXT: --> (2147483648 * (zext i32 %start to i64))<nuw><nsw> U: [0,9223372034707292161) S: [0,9223372034707292161)
70 ; CHECK-NEXT: %indvars.iv = phi i64 [ %indvars.iv.next, %loop ], [ %shl, %entry ]
71 ; CHECK-NEXT: --> {(2147483648 * (zext i32 %start to i64))<nuw><nsw>,+,-1}<nsw><%loop> U: [-9223372036854775808,9223372034707292161) S: [-9223372036854775808,9223372034707292161) Exits: -9223372036854775806 LoopDispositions: { %loop: Computable }
72 ; CHECK-NEXT: %indvars.iv.next = add nsw i64 %indvars.iv, -1
73 ; 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 }
74 ; CHECK-NEXT: Determining loop execution counts for: @test_02
75 ; CHECK-NEXT: Loop %loop: backedge-taken count is (9223372036854775806 + (2147483648 * (zext i32 %start to i64))<nuw><nsw>)<nuw>
76 ; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i64 -2147483650
77 ; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (9223372036854775806 + (2147483648 * (zext i32 %start to i64))<nuw><nsw>)<nuw>
78 ; CHECK-NEXT: 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(ptr %startptr, ptr %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, ptr %startptr, i64 2000
99 ; CHECK-NEXT: --> (2000 + %startptr) U: full-set S: full-set
100 ; CHECK-NEXT: %iv = phi ptr [ %init, %entry ], [ %iv.next, %loop ]
101 ; CHECK-NEXT: --> {(2000 + %startptr),+,1}<nuw><%loop> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
102 ; CHECK-NEXT: %iv.next = getelementptr inbounds i8, ptr %iv, i64 1
103 ; CHECK-NEXT: --> {(2001 + %startptr),+,1}<nuw><%loop> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
104 ; CHECK-NEXT: Determining loop execution counts for: @pointer_iv_nowrap
105 ; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count.
106 ; CHECK-NEXT: Loop %loop: Unpredictable constant max backedge-taken count.
107 ; CHECK-NEXT: Loop %loop: Unpredictable symbolic max backedge-taken count.
110 %init = getelementptr inbounds i8, ptr %startptr, i64 2000
114 %iv = phi ptr [ %init, %entry ], [ %iv.next, %loop ]
115 %iv.next = getelementptr inbounds i8, ptr %iv, i64 1
116 %ec = icmp ugt ptr %iv.next, %endptr
117 br i1 %ec, label %end, label %loop
123 define void @pointer_iv_nowrap_guard(ptr %startptr, ptr %endptr) local_unnamed_addr {
124 ; CHECK-LABEL: 'pointer_iv_nowrap_guard'
125 ; CHECK-NEXT: Classifying expressions for: @pointer_iv_nowrap_guard
126 ; CHECK-NEXT: %init = getelementptr inbounds i32, ptr %startptr, i64 2000
127 ; CHECK-NEXT: --> (8000 + %startptr)<nuw> U: [8000,0) S: [8000,0)
128 ; CHECK-NEXT: %iv = phi ptr [ %init, %entry ], [ %iv.next, %loop ]
129 ; CHECK-NEXT: --> {(8000 + %startptr)<nuw>,+,4}<nuw><%loop> U: [8000,0) S: [8000,0) Exits: (8000 + (4 * ((-8001 + (-1 * (ptrtoint ptr %startptr to i64)) + ((8004 + (ptrtoint ptr %startptr to i64)) umax (ptrtoint ptr %endptr to i64))) /u 4))<nuw> + %startptr) LoopDispositions: { %loop: Computable }
130 ; CHECK-NEXT: %iv.next = getelementptr inbounds i32, ptr %iv, i64 1
131 ; CHECK-NEXT: --> {(8004 + %startptr),+,4}<nuw><%loop> U: full-set S: full-set Exits: (8004 + (4 * ((-8001 + (-1 * (ptrtoint ptr %startptr to i64)) + ((8004 + (ptrtoint ptr %startptr to i64)) umax (ptrtoint ptr %endptr to i64))) /u 4))<nuw> + %startptr) LoopDispositions: { %loop: Computable }
132 ; CHECK-NEXT: Determining loop execution counts for: @pointer_iv_nowrap_guard
133 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-8001 + (-1 * (ptrtoint ptr %startptr to i64)) + ((8004 + (ptrtoint ptr %startptr to i64)) umax (ptrtoint ptr %endptr to i64))) /u 4)
134 ; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i64 4611686018427387903
135 ; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is ((-8001 + (-1 * (ptrtoint ptr %startptr to i64)) + ((8004 + (ptrtoint ptr %startptr to i64)) umax (ptrtoint ptr %endptr to i64))) /u 4)
136 ; CHECK-NEXT: Loop %loop: Trip multiple is 1
139 %init = getelementptr inbounds i32, ptr %startptr, i64 2000
140 %cmp2 = icmp ult ptr %init, %endptr
141 br i1 %cmp2, label %loop, label %end
144 %iv = phi ptr [ %init, %entry ], [ %iv.next, %loop ]
145 %iv.next = getelementptr inbounds i32, ptr %iv, i64 1
146 %ec = icmp uge ptr %iv.next, %endptr
147 br i1 %ec, label %end, label %loop