1 ; RUN: opt < %s -loop-reduce -S -mtriple=x86_64-unknown-unknown 2>&1 | FileCheck %s
3 ; Provide legal integer types.
4 target datalayout = "n8:16:32:64"
7 define void @foobar(i32 %n) nounwind {
13 %cond = icmp eq i32 %n, 0 ; <i1>:0 [#uses=2]
14 br i1 %cond, label %return, label %bb.nph
16 bb.nph: ; preds = %entry
17 %umax = select i1 %cond, i32 1, i32 %n ; <i32> [#uses=1]
20 bb: ; 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
23 %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]
26 %exitcond = icmp eq i32 %indvar.next, %umax ; <i1> [#uses=1]
27 br i1 %exitcond, label %return, label %bb
29 return: ; preds = %bb, %entry
33 ; Unable to eliminate cast because the mantissa bits for double are not enough
34 ; to hold all of i64 IV bits.
35 define void @foobar2(i64 %n) nounwind {
37 ; CHECK-LABEL: foobar2(
38 ; CHECK-NOT: phi double
39 ; CHECK-NOT: phi float
42 %cond = icmp eq i64 %n, 0 ; <i1>:0 [#uses=2]
43 br i1 %cond, label %return, label %bb.nph
45 bb.nph: ; preds = %entry
46 %umax = select i1 %cond, i64 1, i64 %n ; <i64> [#uses=1]
49 bb: ; preds = %bb, %bb.nph
50 %i.03 = phi i64 [ 0, %bb.nph ], [ %indvar.next, %bb ] ; <i64> [#uses=3]
51 %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]
56 %exitcond = icmp eq i64 %indvar.next, %umax ; <i1> [#uses=1]
57 br i1 %exitcond, label %return, label %bb
59 return: ; preds = %bb, %entry
63 ; Unable to eliminate cast due to potentional overflow.
64 define void @foobar3() nounwind {
66 ; CHECK-LABEL: foobar3(
67 ; CHECK-NOT: phi double
68 ; CHECK-NOT: phi float
71 %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
75 bb: ; preds = %bb, %entry
76 %i.03 = phi i32 [ 0, %entry ], [ %indvar.next, %bb ] ; <i32> [#uses=3]
77 tail call void @bar( i32 %i.03 ) nounwind
78 %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
85 return: ; preds = %bb, %entry
89 ; Unable to eliminate cast due to overflow.
90 define void @foobar4() nounwind {
92 ; CHECK-LABEL: foobar4(
93 ; CHECK-NOT: phi double
94 ; CHECK-NOT: phi float
99 bb.nph: ; preds = %entry
102 bb: ; 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
108 %indvar.next = add nsw nuw i8 %i.03, 1 ; <i32> [#uses=2]
109 %tmp = sext i8 %indvar.next to i32
110 %exitcond = icmp eq i32 %tmp, 32767 ; <i1> [#uses=1]
111 br i1 %exitcond, label %return, label %bb
113 return: ; preds = %bb, %entry
117 ; Unable to eliminate cast because the integer IV overflows (accum exceeds
120 define i32 @foobar5() {
121 ; CHECK-LABEL: foobar5(
122 ; CHECK-NOT: phi double
123 ; CHECK-NOT: phi float
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
137 exit: ; preds = %loop
141 ; Can eliminate if we set nsw and, thus, think that we don't overflow SINT_MAX.
143 define i32 @foobar6() {
144 ; CHECK-LABEL: foobar6(
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
160 exit: ; preds = %loop
164 ; Unable to eliminate cast because the integer IV overflows (accum exceeds
167 define i32 @foobar7() {
168 ; CHECK-LABEL: foobar7(
169 ; CHECK-NOT: phi double
170 ; CHECK-NOT: phi float
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
184 exit: ; preds = %loop
188 ; Can eliminate if we set nuw and, thus, think that we don't overflow UINT_MAX.
190 define i32 @foobar8() {
191 ; CHECK-LABEL: foobar8(
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
207 exit: ; preds = %loop
211 declare void @bar(i32)
213 declare void @foo(double)