1 ; RUN: opt < %s -float2int -S | FileCheck %s
7 ; CHECK-LABEL: @simple1
8 ; CHECK: %1 = zext i8 %a to i32
9 ; CHECK: %2 = add i32 %1, 1
10 ; CHECK: %3 = trunc i32 %2 to i16
12 define i16 @simple1(i8 %a) {
13 %1 = uitofp i8 %a to float
14 %2 = fadd float %1, 1.0
15 %3 = fptoui float %2 to i16
19 ; CHECK-LABEL: @simple2
20 ; CHECK: %1 = zext i8 %a to i32
21 ; CHECK: %2 = sub i32 %1, 1
22 ; CHECK: %3 = trunc i32 %2 to i8
24 define i8 @simple2(i8 %a) {
25 %1 = uitofp i8 %a to float
26 %2 = fsub float %1, 1.0
27 %3 = fptoui float %2 to i8
31 ; CHECK-LABEL: @simple3
32 ; CHECK: %1 = zext i8 %a to i32
33 ; CHECK: %2 = sub i32 %1, 1
35 define i32 @simple3(i8 %a) {
36 %1 = uitofp i8 %a to float
37 %2 = fsub float %1, 1.0
38 %3 = fptoui float %2 to i32
43 ; CHECK: %1 = zext i8 %a to i32
44 ; CHECK: %2 = zext i8 %b to i32
45 ; CHECK: %3 = icmp slt i32 %1, %2
47 define i1 @cmp(i8 %a, i8 %b) {
48 %1 = uitofp i8 %a to float
49 %2 = uitofp i8 %b to float
50 %3 = fcmp ult float %1, %2
54 ; CHECK-LABEL: @simple4
55 ; CHECK: %1 = zext i32 %a to i64
56 ; CHECK: %2 = add i64 %1, 1
57 ; CHECK: %3 = trunc i64 %2 to i32
59 define i32 @simple4(i32 %a) {
60 %1 = uitofp i32 %a to double
61 %2 = fadd double %1, 1.0
62 %3 = fptoui double %2 to i32
66 ; CHECK-LABEL: @simple5
67 ; CHECK: %1 = zext i8 %a to i32
68 ; CHECK: %2 = zext i8 %b to i32
69 ; CHECK: %3 = add i32 %1, 1
70 ; CHECK: %4 = mul i32 %3, %2
72 define i32 @simple5(i8 %a, i8 %b) {
73 %1 = uitofp i8 %a to float
74 %2 = uitofp i8 %b to float
75 %3 = fadd float %1, 1.0
76 %4 = fmul float %3, %2
77 %5 = fptoui float %4 to i32
81 ; The two chains don't interact - failure of one shouldn't
82 ; cause failure of the other.
84 ; CHECK-LABEL: @multi1
85 ; CHECK: %1 = zext i8 %a to i32
86 ; CHECK: %2 = zext i8 %b to i32
87 ; CHECK: %fc = uitofp i8 %c to float
88 ; CHECK: %x1 = add i32 %1, %2
89 ; CHECK: %z = fadd float %fc, %d
90 ; CHECK: %w = fptoui float %z to i32
91 ; CHECK: %r = add i32 %x1, %w
93 define i32 @multi1(i8 %a, i8 %b, i8 %c, float %d) {
94 %fa = uitofp i8 %a to float
95 %fb = uitofp i8 %b to float
96 %fc = uitofp i8 %c to float
97 %x = fadd float %fa, %fb
98 %y = fptoui float %x to i32
99 %z = fadd float %fc, %d
100 %w = fptoui float %z to i32
105 ; CHECK-LABEL: @simple_negzero
106 ; CHECK: %1 = zext i8 %a to i32
107 ; CHECK: %2 = add i32 %1, 0
108 ; CHECK: %3 = trunc i32 %2 to i16
110 define i16 @simple_negzero(i8 %a) {
111 %1 = uitofp i8 %a to float
112 %2 = fadd fast float %1, -0.0
113 %3 = fptoui float %2 to i16
121 ; CHECK-LABEL: @neg_multi1
122 ; CHECK: %fa = uitofp i8 %a to float
123 ; CHECK: %fc = uitofp i8 %c to float
124 ; CHECK: %x = fadd float %fa, %fc
125 ; CHECK: %y = fptoui float %x to i32
126 ; CHECK: %z = fadd float %fc, %d
127 ; CHECK: %w = fptoui float %z to i32
128 ; CHECK: %r = add i32 %y, %w
130 ; The two chains intersect, which means because one fails, no
131 ; transform can occur.
132 define i32 @neg_multi1(i8 %a, i8 %b, i8 %c, float %d) {
133 %fa = uitofp i8 %a to float
134 %fc = uitofp i8 %c to float
135 %x = fadd float %fa, %fc
136 %y = fptoui float %x to i32
137 %z = fadd float %fc, %d
138 %w = fptoui float %z to i32
143 ; CHECK-LABEL: @neg_muld
144 ; CHECK: %fa = uitofp i32 %a to double
145 ; CHECK: %fb = uitofp i32 %b to double
146 ; CHECK: %mul = fmul double %fa, %fb
147 ; CHECK: %r = fptoui double %mul to i64
149 ; The i32 * i32 = i64, which has 64 bits, which is greater than the 52 bits
150 ; that can be exactly represented in a double.
151 define i64 @neg_muld(i32 %a, i32 %b) {
152 %fa = uitofp i32 %a to double
153 %fb = uitofp i32 %b to double
154 %mul = fmul double %fa, %fb
155 %r = fptoui double %mul to i64
159 ; CHECK-LABEL: @neg_mulf
160 ; CHECK: %fa = uitofp i16 %a to float
161 ; CHECK: %fb = uitofp i16 %b to float
162 ; CHECK: %mul = fmul float %fa, %fb
163 ; CHECK: %r = fptoui float %mul to i32
165 ; The i16 * i16 = i32, which can't be represented in a float, but can in a
166 ; double. This should fail, as the written code uses floats, not doubles so
167 ; the original result may be inaccurate.
168 define i32 @neg_mulf(i16 %a, i16 %b) {
169 %fa = uitofp i16 %a to float
170 %fb = uitofp i16 %b to float
171 %mul = fmul float %fa, %fb
172 %r = fptoui float %mul to i32
176 ; CHECK-LABEL: @neg_cmp
177 ; CHECK: %1 = uitofp i8 %a to float
178 ; CHECK: %2 = uitofp i8 %b to float
179 ; CHECK: %3 = fcmp false float %1, %2
181 ; "false" doesn't have an icmp equivalent.
182 define i1 @neg_cmp(i8 %a, i8 %b) {
183 %1 = uitofp i8 %a to float
184 %2 = uitofp i8 %b to float
185 %3 = fcmp false float %1, %2
189 ; CHECK-LABEL: @neg_div
190 ; CHECK: %1 = uitofp i8 %a to float
191 ; CHECK: %2 = fdiv float %1, 1.0
192 ; CHECK: %3 = fptoui float %2 to i16
194 ; Division isn't a supported operator.
195 define i16 @neg_div(i8 %a) {
196 %1 = uitofp i8 %a to float
197 %2 = fdiv float %1, 1.0
198 %3 = fptoui float %2 to i16
202 ; CHECK-LABEL: @neg_remainder
203 ; CHECK: %1 = uitofp i8 %a to float
204 ; CHECK: %2 = fadd float %1, 1.2
205 ; CHECK: %3 = fptoui float %2 to i16
207 ; 1.2 is not an integer.
208 define i16 @neg_remainder(i8 %a) {
209 %1 = uitofp i8 %a to float
210 %2 = fadd float %1, 1.25
211 %3 = fptoui float %2 to i16
215 ; CHECK-LABEL: @neg_toolarge
216 ; CHECK: %1 = uitofp i80 %a to fp128
217 ; CHECK: %2 = fadd fp128 %1, %1
218 ; CHECK: %3 = fptoui fp128 %2 to i80
220 ; i80 > i64, which is the largest bitwidth handleable by default.
221 define i80 @neg_toolarge(i80 %a) {
222 %1 = uitofp i80 %a to fp128
223 %2 = fadd fp128 %1, %1
224 %3 = fptoui fp128 %2 to i80