1 ; RUN: opt < %s -instcombine -S | FileCheck %s
5 define i1 @test1(i8 %A) {
6 %B = sitofp i8 %A to double
7 %C = fcmp ult double %B, 128.0
13 define i1 @test2(i8 %A) {
14 %B = sitofp i8 %A to double
15 %C = fcmp ugt double %B, -128.1
21 define i1 @test3(i8 %A) {
22 %B = sitofp i8 %A to double
23 %C = fcmp ule double %B, 127.0
28 ; CHECK: icmp ne i8 %A, 127
30 define i1 @test4(i8 %A) {
31 %B = sitofp i8 %A to double
32 %C = fcmp ult double %B, 127.0
38 define i32 @test5(i32 %A) {
39 %B = sitofp i32 %A to double
40 %C = fptosi double %B to i32
41 %D = uitofp i32 %C to double
42 %E = fptoui double %D to i32
47 ; CHECK: and i32 %A, 39
49 define i32 @test6(i32 %A) {
52 %D = sitofp i32 %B to double
53 %E = sitofp i32 %C to double
54 %F = fadd double %D, %E
55 %G = fptosi double %F to i32
61 define i32 @test7(i32 %A) nounwind {
62 %B = sitofp i32 %A to double
63 %C = fptoui double %B to i32
69 define i32 @test8(i32 %A) nounwind {
70 %B = uitofp i32 %A to double
71 %C = fptosi double %B to i32
78 define i32 @test9(i8 %A) nounwind {
79 %B = sitofp i8 %A to float
80 %C = fptoui float %B to i32
87 define i32 @test10(i8 %A) nounwind {
88 %B = sitofp i8 %A to float
89 %C = fptosi float %B to i32
93 ; If the input value is outside of the range of the output cast, it's
94 ; undefined behavior, so we can assume it fits.
98 define i8 @test11(i32 %A) nounwind {
99 %B = sitofp i32 %A to float
100 %C = fptosi float %B to i8
104 ; If the input value is negative, it'll be outside the range of the
105 ; output cast, and thus undefined behavior.
106 ; CHECK-LABEL: test12
108 ; CHECK-NEXT: ret i32
109 define i32 @test12(i8 %A) nounwind {
110 %B = sitofp i8 %A to float
111 %C = fptoui float %B to i32
115 ; This can't fold because the 25-bit input doesn't fit in the mantissa.
116 ; CHECK-LABEL: test13
119 define i32 @test13(i25 %A) nounwind {
120 %B = uitofp i25 %A to float
121 %C = fptoui float %B to i32
126 ; CHECK-LABEL: test14
128 ; CHECK-NEXT: ret i32
129 define i32 @test14(i24 %A) nounwind {
130 %B = uitofp i24 %A to float
131 %C = fptoui float %B to i32
135 ; And this one can too.
136 ; CHECK-LABEL: test15
138 ; CHECK-NEXT: ret i24
139 define i24 @test15(i32 %A) nounwind {
140 %B = uitofp i32 %A to float
141 %C = fptoui float %B to i24
145 ; This can fold because the 25-bit input is signed and we disard the sign bit.
146 ; CHECK-LABEL: test16
148 define i32 @test16(i25 %A) nounwind {
149 %B = sitofp i25 %A to float
150 %C = fptoui float %B to i32
154 ; This can't fold because the 26-bit input won't fit the mantissa
155 ; even after disarding the signed bit.
156 ; CHECK-LABEL: test17
159 define i32 @test17(i26 %A) nounwind {
160 %B = sitofp i26 %A to float
161 %C = fptoui float %B to i32
165 ; This can fold because the 54-bit output is signed and we disard the sign bit.
166 ; CHECK-LABEL: test18
168 define i54 @test18(i64 %A) nounwind {
169 %B = sitofp i64 %A to double
170 %C = fptosi double %B to i54
174 ; This can't fold because the 55-bit output won't fit the mantissa
175 ; even after disarding the sign bit.
176 ; CHECK-LABEL: test19
179 define i55 @test19(i64 %A) nounwind {
180 %B = sitofp i64 %A to double
181 %C = fptosi double %B to i55