[SimplifyLibCalls] Remove useless bits of this tests.
[oota-llvm.git] / test / Transforms / InstCombine / sitofp.ll
1 ; RUN: opt < %s -instcombine -S | FileCheck %s
2
3 ; CHECK-LABEL: test1
4 ; CHECK: ret i1 true
5 define i1 @test1(i8 %A) {
6   %B = sitofp i8 %A to double
7   %C = fcmp ult double %B, 128.0
8   ret i1 %C
9 }
10
11 ; CHECK-LABEL: test2
12 ; CHECK: ret i1 true
13 define i1 @test2(i8 %A) {
14   %B = sitofp i8 %A to double
15   %C = fcmp ugt double %B, -128.1
16   ret i1 %C
17 }
18
19 ; CHECK-LABEL: test3
20 ; CHECK: ret i1 true
21 define i1 @test3(i8 %A) {
22   %B = sitofp i8 %A to double
23   %C = fcmp ule double %B, 127.0
24   ret i1 %C
25 }
26
27 ; CHECK-LABEL: test4
28 ; CHECK: icmp ne i8 %A, 127
29 ; CHECK-NEXT: ret i1
30 define i1 @test4(i8 %A) {
31   %B = sitofp i8 %A to double
32   %C = fcmp ult double %B, 127.0
33   ret i1 %C
34 }
35
36 ; CHECK-LABEL: test5
37 ; CHECK: ret i32
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
43   ret i32 %E
44 }
45
46 ; CHECK-LABEL: test6
47 ; CHECK: and i32 %A, 39
48 ; CHECK-NEXT: ret i32
49 define i32 @test6(i32 %A) {
50   %B = and i32 %A, 7
51   %C = and i32 %A, 32
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
56   ret i32 %G
57 }
58
59 ; CHECK-LABEL: test7
60 ; CHECK: ret i32
61 define i32 @test7(i32 %A) nounwind {
62   %B = sitofp i32 %A to double
63   %C = fptoui double %B to i32
64   ret i32 %C
65 }
66
67 ; CHECK-LABEL: test8
68 ; CHECK: ret i32
69 define i32 @test8(i32 %A) nounwind {
70   %B = uitofp i32 %A to double
71   %C = fptosi double %B to i32
72   ret i32 %C
73 }
74
75 ; CHECK-LABEL: test9
76 ; CHECK: zext i8
77 ; CHECK-NEXT: ret i32
78 define i32 @test9(i8 %A) nounwind {
79   %B = sitofp i8 %A to float
80   %C = fptoui float %B to i32
81   ret i32 %C
82 }
83
84 ; CHECK-LABEL: test10
85 ; CHECK: sext i8
86 ; CHECK-NEXT: ret i32
87 define i32 @test10(i8 %A) nounwind {
88   %B = sitofp i8 %A to float
89   %C = fptosi float %B to i32
90   ret i32 %C
91 }
92
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.
95 ; CHECK-LABEL: test11
96 ; CHECK: trunc
97 ; CHECK-NEXT: ret i8
98 define i8 @test11(i32 %A) nounwind {
99   %B = sitofp i32 %A to float
100   %C = fptosi float %B to i8
101   ret i8 %C
102 }
103
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
107 ; CHECK: zext i8
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
112   ret i32 %C
113 }
114
115 ; This can't fold because the 25-bit input doesn't fit in the mantissa.
116 ; CHECK-LABEL: test13
117 ; CHECK: uitofp
118 ; CHECK-NEXT: fptoui
119 define i32 @test13(i25 %A) nounwind {
120   %B = uitofp i25 %A to float
121   %C = fptoui float %B to i32
122   ret i32 %C
123 }
124
125 ; But this one can.
126 ; CHECK-LABEL: test14
127 ; CHECK: zext i24
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
132   ret i32 %C
133 }
134
135 ; And this one can too.
136 ; CHECK-LABEL: test15
137 ; CHECK: trunc i32
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
142   ret i24 %C
143 }
144
145 ; This can fold because the 25-bit input is signed and we disard the sign bit.
146 ; CHECK-LABEL: test16
147 ; CHECK: zext
148 define i32 @test16(i25 %A) nounwind {
149  %B = sitofp i25 %A to float
150  %C = fptoui float %B to i32
151  ret i32 %C
152 }
153
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
157 ; CHECK: sitofp
158 ; CHECK-NEXT: fptoui
159 define i32 @test17(i26 %A) nounwind {
160  %B = sitofp i26 %A to float
161  %C = fptoui float %B to i32
162  ret i32 %C
163 }
164
165 ; This can fold because the 54-bit output is signed and we disard the sign bit.
166 ; CHECK-LABEL: test18
167 ; CHECK: trunc
168 define i54 @test18(i64 %A) nounwind {
169  %B = sitofp i64 %A to double
170  %C = fptosi double %B to i54
171  ret i54 %C
172 }
173
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
177 ; CHECK: sitofp
178 ; CHECK-NEXT: fptosi
179 define i55 @test19(i64 %A) nounwind {
180  %B = sitofp i64 %A to double
181  %C = fptosi double %B to i55
182  ret i55 %C
183 }
184