blob: da14e631f5142e7e0fc1212442d9f76b824b84d0 [file] [log] [blame]
Max Kazantsev03407da2017-08-29 05:20:56 +00001; RUN: opt < %s -loop-reduce -S -mtriple=x86_64-unknown-unknown 2>&1 | FileCheck %s
Evan Cheng8ec334f2008-08-17 19:25:28 +00002
Mehdi Amini46a43552015-03-04 18:43:29 +00003; Provide legal integer types.
4target datalayout = "n8:16:32:64"
5
6
Evan Cheng8ec334f2008-08-17 19:25:28 +00007define void @foobar(i32 %n) nounwind {
Max Kazantsev03407da2017-08-29 05:20:56 +00008
9; CHECK-LABEL: foobar(
10; CHECK: phi double
11
Evan Cheng8ec334f2008-08-17 19:25:28 +000012entry:
Max Kazantsev03407da2017-08-29 05:20:56 +000013 %cond = icmp eq i32 %n, 0 ; <i1>:0 [#uses=2]
14 br i1 %cond, label %return, label %bb.nph
Evan Cheng8ec334f2008-08-17 19:25:28 +000015
16bb.nph: ; preds = %entry
Max Kazantsev03407da2017-08-29 05:20:56 +000017 %umax = select i1 %cond, i32 1, i32 %n ; <i32> [#uses=1]
Evan Cheng8ec334f2008-08-17 19:25:28 +000018 br label %bb
19
20bb: ; preds = %bb, %bb.nph
21 %i.03 = phi i32 [ 0, %bb.nph ], [ %indvar.next, %bb ] ; <i32> [#uses=3]
22 tail call void @bar( i32 %i.03 ) nounwind
Max Kazantsev03407da2017-08-29 05:20:56 +000023 %tmp1 = uitofp i32 %i.03 to double ; <double>:1 [#uses=1]
24 tail call void @foo( double %tmp1 ) nounwind
25 %indvar.next = add nsw nuw i32 %i.03, 1 ; <i32> [#uses=2]
Evan Cheng8ec334f2008-08-17 19:25:28 +000026 %exitcond = icmp eq i32 %indvar.next, %umax ; <i1> [#uses=1]
27 br i1 %exitcond, label %return, label %bb
28
29return: ; preds = %bb, %entry
30 ret void
31}
32
33; Unable to eliminate cast because the mantissa bits for double are not enough
34; to hold all of i64 IV bits.
35define void @foobar2(i64 %n) nounwind {
Max Kazantsev03407da2017-08-29 05:20:56 +000036
37; CHECK-LABEL: foobar2(
38; CHECK-NOT: phi double
39; CHECK-NOT: phi float
40
Evan Cheng8ec334f2008-08-17 19:25:28 +000041entry:
Max Kazantsev03407da2017-08-29 05:20:56 +000042 %cond = icmp eq i64 %n, 0 ; <i1>:0 [#uses=2]
43 br i1 %cond, label %return, label %bb.nph
Evan Cheng8ec334f2008-08-17 19:25:28 +000044
45bb.nph: ; preds = %entry
Max Kazantsev03407da2017-08-29 05:20:56 +000046 %umax = select i1 %cond, i64 1, i64 %n ; <i64> [#uses=1]
Evan Cheng8ec334f2008-08-17 19:25:28 +000047 br label %bb
48
49bb: ; preds = %bb, %bb.nph
50 %i.03 = phi i64 [ 0, %bb.nph ], [ %indvar.next, %bb ] ; <i64> [#uses=3]
Max Kazantsev03407da2017-08-29 05:20:56 +000051 %tmp1 = trunc i64 %i.03 to i32 ; <i32>:1 [#uses=1]
52 tail call void @bar( i32 %tmp1 ) nounwind
53 %tmp2 = uitofp i64 %i.03 to double ; <double>:2 [#uses=1]
54 tail call void @foo( double %tmp2 ) nounwind
55 %indvar.next = add nsw nuw i64 %i.03, 1 ; <i64> [#uses=2]
Evan Cheng8ec334f2008-08-17 19:25:28 +000056 %exitcond = icmp eq i64 %indvar.next, %umax ; <i1> [#uses=1]
57 br i1 %exitcond, label %return, label %bb
58
59return: ; preds = %bb, %entry
60 ret void
61}
62
63; Unable to eliminate cast due to potentional overflow.
64define void @foobar3() nounwind {
Max Kazantsev03407da2017-08-29 05:20:56 +000065
66; CHECK-LABEL: foobar3(
67; CHECK-NOT: phi double
68; CHECK-NOT: phi float
69
Evan Cheng8ec334f2008-08-17 19:25:28 +000070entry:
Max Kazantsev03407da2017-08-29 05:20:56 +000071 %tmp0 = tail call i32 (...) @nn( ) nounwind ; <i32>:0 [#uses=1]
72 %cond = icmp eq i32 %tmp0, 0 ; <i1>:1 [#uses=1]
73 br i1 %cond, label %return, label %bb
Evan Cheng8ec334f2008-08-17 19:25:28 +000074
75bb: ; preds = %bb, %entry
Max Kazantsev03407da2017-08-29 05:20:56 +000076 %i.03 = phi i32 [ 0, %entry ], [ %indvar.next, %bb ] ; <i32> [#uses=3]
Evan Cheng8ec334f2008-08-17 19:25:28 +000077 tail call void @bar( i32 %i.03 ) nounwind
Max Kazantsev03407da2017-08-29 05:20:56 +000078 %tmp2 = uitofp i32 %i.03 to double ; <double>:2 [#uses=1]
79 tail call void @foo( double %tmp2 ) nounwind
80 %indvar.next = add nuw nsw i32 %i.03, 1 ; <i32>:3 [#uses=2]
81 %tmp4 = tail call i32 (...) @nn( ) nounwind ; <i32>:4 [#uses=1]
82 %exitcond = icmp ugt i32 %tmp4, %indvar.next ; <i1>:5 [#uses=1]
83 br i1 %exitcond, label %bb, label %return
Evan Cheng8ec334f2008-08-17 19:25:28 +000084
85return: ; preds = %bb, %entry
86 ret void
87}
88
89; Unable to eliminate cast due to overflow.
90define void @foobar4() nounwind {
Max Kazantsev03407da2017-08-29 05:20:56 +000091
92; CHECK-LABEL: foobar4(
93; CHECK-NOT: phi double
94; CHECK-NOT: phi float
95
Evan Cheng8ec334f2008-08-17 19:25:28 +000096entry:
97 br label %bb.nph
98
99bb.nph: ; preds = %entry
100 br label %bb
101
102bb: ; preds = %bb, %bb.nph
103 %i.03 = phi i8 [ 0, %bb.nph ], [ %indvar.next, %bb ] ; <i32> [#uses=3]
104 %tmp2 = sext i8 %i.03 to i32 ; <i32>:0 [#uses=1]
105 tail call void @bar( i32 %tmp2 ) nounwind
106 %tmp3 = uitofp i8 %i.03 to double ; <double>:1 [#uses=1]
107 tail call void @foo( double %tmp3 ) nounwind
Max Kazantsev03407da2017-08-29 05:20:56 +0000108 %indvar.next = add nsw nuw i8 %i.03, 1 ; <i32> [#uses=2]
Max Kazantsevf2e017b2017-08-29 05:30:58 +0000109 %tmp = sext i8 %indvar.next to i32
Evan Cheng8ec334f2008-08-17 19:25:28 +0000110 %exitcond = icmp eq i32 %tmp, 32767 ; <i1> [#uses=1]
111 br i1 %exitcond, label %return, label %bb
112
113return: ; preds = %bb, %entry
114 ret void
115}
116
Max Kazantsevbb1d0102017-08-29 07:32:20 +0000117; Unable to eliminate cast because the integer IV overflows (accum exceeds
118; SINT_MAX).
119
120define i32 @foobar5() {
121; CHECK-LABEL: foobar5(
122; CHECK-NOT: phi double
123; CHECK-NOT: phi float
124entry:
125 br label %loop
126
127loop:
128 %accum = phi i32 [ -3220, %entry ], [ %accum.next, %loop ]
129 %iv = phi i32 [ 12, %entry ], [ %iv.next, %loop ]
130 %tmp1 = sitofp i32 %accum to double
131 tail call void @foo( double %tmp1 ) nounwind
132 %accum.next = add i32 %accum, 9597741
133 %iv.next = add nuw nsw i32 %iv, 1
134 %exitcond = icmp ugt i32 %iv, 235
135 br i1 %exitcond, label %exit, label %loop
136
137exit: ; preds = %loop
138 ret i32 %accum.next
139}
140
141; Can eliminate if we set nsw and, thus, think that we don't overflow SINT_MAX.
142
143define i32 @foobar6() {
144; CHECK-LABEL: foobar6(
145; CHECK: phi double
146
147entry:
148 br label %loop
149
150loop:
151 %accum = phi i32 [ -3220, %entry ], [ %accum.next, %loop ]
152 %iv = phi i32 [ 12, %entry ], [ %iv.next, %loop ]
153 %tmp1 = sitofp i32 %accum to double
154 tail call void @foo( double %tmp1 ) nounwind
155 %accum.next = add nsw i32 %accum, 9597741
156 %iv.next = add nuw nsw i32 %iv, 1
157 %exitcond = icmp ugt i32 %iv, 235
158 br i1 %exitcond, label %exit, label %loop
159
160exit: ; preds = %loop
161 ret i32 %accum.next
162}
163
164; Unable to eliminate cast because the integer IV overflows (accum exceeds
165; UINT_MAX).
166
167define i32 @foobar7() {
168; CHECK-LABEL: foobar7(
169; CHECK-NOT: phi double
170; CHECK-NOT: phi float
171entry:
172 br label %loop
173
174loop:
175 %accum = phi i32 [ -3220, %entry ], [ %accum.next, %loop ]
176 %iv = phi i32 [ 12, %entry ], [ %iv.next, %loop ]
177 %tmp1 = uitofp i32 %accum to double
178 tail call void @foo( double %tmp1 ) nounwind
179 %accum.next = add i32 %accum, 9597741
180 %iv.next = add nuw nsw i32 %iv, 1
181 %exitcond = icmp ugt i32 %iv, 235
182 br i1 %exitcond, label %exit, label %loop
183
184exit: ; preds = %loop
185 ret i32 %accum.next
186}
187
188; Can eliminate if we set nuw and, thus, think that we don't overflow UINT_MAX.
189
190define i32 @foobar8() {
191; CHECK-LABEL: foobar8(
192; CHECK: phi double
193
194entry:
195 br label %loop
196
197loop:
198 %accum = phi i32 [ -3220, %entry ], [ %accum.next, %loop ]
199 %iv = phi i32 [ 12, %entry ], [ %iv.next, %loop ]
200 %tmp1 = uitofp i32 %accum to double
201 tail call void @foo( double %tmp1 ) nounwind
202 %accum.next = add nuw i32 %accum, 9597741
203 %iv.next = add nuw nsw i32 %iv, 1
204 %exitcond = icmp ugt i32 %iv, 235
205 br i1 %exitcond, label %exit, label %loop
206
207exit: ; preds = %loop
208 ret i32 %accum.next
209}
210
Evan Cheng8ec334f2008-08-17 19:25:28 +0000211declare void @bar(i32)
212
213declare void @foo(double)
214
215declare i32 @nn(...)