1; ; RUN: opt -analyze -enable-new-pm=0 -scalar-evolution < %s | FileCheck %s
2; ; RUN: opt -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s
3
4define void @infer.sext.0(i1* %c, i32 %start, i32* %buf) {
5; CHECK-LABEL: Classifying expressions for: @infer.sext.0
6 entry:
7  br label %loop
8
9 loop:
10  %counter = phi i32 [ 0, %entry ], [ %counter.inc, %loop ]
11  %idx = phi i32 [ %start, %entry ], [ %idx.inc, %loop ]
12  %idx.inc = add nsw i32 %idx, 1
13  %idx.inc.sext = sext i32 %idx.inc to i64
14; CHECK: %idx.inc.sext = sext i32 %idx.inc to i64
15; CHECK-NEXT: -->  {(1 + (sext i32 %start to i64))<nsw>,+,1}<nsw><%loop>
16
17  %buf.gep = getelementptr inbounds i32, i32* %buf, i32 %idx.inc
18  %val = load i32, i32* %buf.gep
19
20  %condition = icmp eq i32 %counter, 1
21  %counter.inc = add i32 %counter, 1
22  br i1 %condition, label %exit, label %loop
23
24 exit:
25  ret void
26}
27
28define void @infer.zext.0(i1* %c, i32 %start, i32* %buf) {
29; CHECK-LABEL: Classifying expressions for: @infer.zext.0
30 entry:
31  br label %loop
32
33 loop:
34  %counter = phi i32 [ 0, %entry ], [ %counter.inc, %loop ]
35  %idx = phi i32 [ %start, %entry ], [ %idx.inc, %loop ]
36  %idx.inc = add nuw i32 %idx, 1
37  %idx.inc.sext = zext i32 %idx.inc to i64
38; CHECK: %idx.inc.sext = zext i32 %idx.inc to i64
39; CHECK-NEXT: -->  {(1 + (zext i32 %start to i64))<nuw><nsw>,+,1}<nuw><%loop>
40
41  %buf.gep = getelementptr inbounds i32, i32* %buf, i32 %idx.inc
42  %val = load i32, i32* %buf.gep
43
44  %condition = icmp eq i32 %counter, 1
45  %counter.inc = add i32 %counter, 1
46  br i1 %condition, label %exit, label %loop
47
48 exit:
49  ret void
50}
51
52define void @infer.sext.1(i32 %start, i1* %c) {
53; CHECK-LABEL: Classifying expressions for: @infer.sext.1
54 entry:
55  %start.mul = mul i32 %start, 4
56  %start.real = add i32 %start.mul, 2
57  br label %loop
58
59 loop:
60  %idx = phi i32 [ %start.real, %entry ], [ %idx.inc, %loop ]
61  %idx.sext = sext i32 %idx to i64
62; CHECK: %idx.sext = sext i32 %idx to i64
63; CHECK-NEXT:  -->  {(2 + (sext i32 (4 * %start) to i64))<nuw><nsw>,+,2}<nsw><%loop>
64  %idx.inc = add nsw i32 %idx, 2
65  %condition = load i1, i1* %c
66  br i1 %condition, label %exit, label %loop
67
68 exit:
69  ret void
70}
71
72define void @infer.sext.2(i1* %c, i8 %start) {
73; CHECK-LABEL: Classifying expressions for: @infer.sext.2
74 entry:
75  %start.inc = add i8 %start, 1
76  %entry.condition = icmp slt i8 %start, 127
77  br i1 %entry.condition, label %loop, label %exit
78
79 loop:
80  %idx = phi i8 [ %start.inc, %entry ], [ %idx.inc, %loop ]
81  %idx.sext = sext i8 %idx to i16
82; CHECK: %idx.sext = sext i8 %idx to i16
83; CHECK-NEXT: -->  {(1 + (sext i8 %start to i16))<nsw>,+,1}<nsw><%loop>
84  %idx.inc = add nsw i8 %idx, 1
85  %condition = load volatile i1, i1* %c
86  br i1 %condition, label %exit, label %loop
87
88 exit:
89  ret void
90}
91
92define void @infer.zext.1(i1* %c, i8 %start) {
93; CHECK-LABEL: Classifying expressions for: @infer.zext.1
94 entry:
95  %start.inc = add i8 %start, 1
96  %entry.condition = icmp ult i8 %start, 255
97  br i1 %entry.condition, label %loop, label %exit
98
99 loop:
100  %idx = phi i8 [ %start.inc, %entry ], [ %idx.inc, %loop ]
101  %idx.zext = zext i8 %idx to i16
102; CHECK: %idx.zext = zext i8 %idx to i16
103; CHECK-NEXT: -->  {(1 + (zext i8 %start to i16))<nuw><nsw>,+,1}<nuw><%loop>
104  %idx.inc = add nuw i8 %idx, 1
105  %condition = load volatile i1, i1* %c
106  br i1 %condition, label %exit, label %loop
107
108 exit:
109  ret void
110}
111