1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define i1 @test1(i8 %A) {
6 ; CHECK-NEXT: ret i1 true
8 %B = sitofp i8 %A to double
9 %C = fcmp ult double %B, 128.0
13 define i1 @test2(i8 %A) {
14 ; CHECK-LABEL: @test2(
15 ; CHECK-NEXT: ret i1 true
17 %B = sitofp i8 %A to double
18 %C = fcmp ugt double %B, -128.1
22 define i1 @test3(i8 %A) {
23 ; CHECK-LABEL: @test3(
24 ; CHECK-NEXT: ret i1 true
26 %B = sitofp i8 %A to double
27 %C = fcmp ule double %B, 127.0
31 define i1 @test4(i8 %A) {
32 ; CHECK-LABEL: @test4(
33 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[A:%.*]], 127
34 ; CHECK-NEXT: ret i1 [[C]]
36 %B = sitofp i8 %A to double
37 %C = fcmp ult double %B, 127.0
41 define i32 @test5(i32 %A) {
42 ; CHECK-LABEL: @test5(
43 ; CHECK-NEXT: ret i32 [[A:%.*]]
45 %B = sitofp i32 %A to double
46 %C = fptosi double %B to i32
47 %D = uitofp i32 %C to double
48 %E = fptoui double %D to i32
52 define i32 @test6(i32 %A) {
53 ; CHECK-LABEL: @test6(
54 ; CHECK-NEXT: [[ADDCONV:%.*]] = and i32 [[A:%.*]], 39
55 ; CHECK-NEXT: ret i32 [[ADDCONV]]
59 %D = sitofp i32 %B to double
60 %E = sitofp i32 %C to double
61 %F = fadd double %D, %E
62 %G = fptosi double %F to i32
66 define i32 @test7(i32 %A) {
67 ; CHECK-LABEL: @test7(
68 ; CHECK-NEXT: ret i32 [[A:%.*]]
70 %B = sitofp i32 %A to double
71 %C = fptoui double %B to i32
75 define i32 @test8(i32 %A) {
76 ; CHECK-LABEL: @test8(
77 ; CHECK-NEXT: ret i32 [[A:%.*]]
79 %B = uitofp i32 %A to double
80 %C = fptosi double %B to i32
84 define i32 @test9(i8 %A) {
85 ; CHECK-LABEL: @test9(
86 ; CHECK-NEXT: [[C:%.*]] = zext i8 [[A:%.*]] to i32
87 ; CHECK-NEXT: ret i32 [[C]]
89 %B = sitofp i8 %A to float
90 %C = fptoui float %B to i32
94 define i32 @test10(i8 %A) {
95 ; CHECK-LABEL: @test10(
96 ; CHECK-NEXT: [[C:%.*]] = sext i8 [[A:%.*]] to i32
97 ; CHECK-NEXT: ret i32 [[C]]
99 %B = sitofp i8 %A to float
100 %C = fptosi float %B to i32
104 ; If the input value is outside of the range of the output cast, it's
105 ; undefined behavior, so we can assume it fits.
107 define i8 @test11(i32 %A) {
108 ; CHECK-LABEL: @test11(
109 ; CHECK-NEXT: [[C:%.*]] = trunc i32 [[A:%.*]] to i8
110 ; CHECK-NEXT: ret i8 [[C]]
112 %B = sitofp i32 %A to float
113 %C = fptosi float %B to i8
117 ; If the input value is negative, it'll be outside the range of the
118 ; output cast, and thus undefined behavior.
120 define i32 @test12(i8 %A) {
121 ; CHECK-LABEL: @test12(
122 ; CHECK-NEXT: [[C:%.*]] = zext i8 [[A:%.*]] to i32
123 ; CHECK-NEXT: ret i32 [[C]]
125 %B = sitofp i8 %A to float
126 %C = fptoui float %B to i32
130 ; This can't fold because the 25-bit input doesn't fit in the mantissa.
132 define i32 @test13(i25 %A) {
133 ; CHECK-LABEL: @test13(
134 ; CHECK-NEXT: [[B:%.*]] = uitofp i25 [[A:%.*]] to float
135 ; CHECK-NEXT: [[C:%.*]] = fptoui float [[B]] to i32
136 ; CHECK-NEXT: ret i32 [[C]]
138 %B = uitofp i25 %A to float
139 %C = fptoui float %B to i32
145 define i32 @test14(i24 %A) {
146 ; CHECK-LABEL: @test14(
147 ; CHECK-NEXT: [[C:%.*]] = zext i24 [[A:%.*]] to i32
148 ; CHECK-NEXT: ret i32 [[C]]
150 %B = uitofp i24 %A to float
151 %C = fptoui float %B to i32
155 ; And this one can too.
157 define i24 @test15(i32 %A) {
158 ; CHECK-LABEL: @test15(
159 ; CHECK-NEXT: [[C:%.*]] = trunc i32 [[A:%.*]] to i24
160 ; CHECK-NEXT: ret i24 [[C]]
162 %B = uitofp i32 %A to float
163 %C = fptoui float %B to i24
167 ; This can fold because the 25-bit input is signed and we discard the sign bit.
169 define i32 @test16(i25 %A) {
170 ; CHECK-LABEL: @test16(
171 ; CHECK-NEXT: [[C:%.*]] = zext i25 [[A:%.*]] to i32
172 ; CHECK-NEXT: ret i32 [[C]]
174 %B = sitofp i25 %A to float
175 %C = fptoui float %B to i32
179 ; This can't fold because the 26-bit input won't fit the mantissa
180 ; even after discarding the signed bit.
182 define i32 @test17(i26 %A) {
183 ; CHECK-LABEL: @test17(
184 ; CHECK-NEXT: [[B:%.*]] = sitofp i26 [[A:%.*]] to float
185 ; CHECK-NEXT: [[C:%.*]] = fptoui float [[B]] to i32
186 ; CHECK-NEXT: ret i32 [[C]]
188 %B = sitofp i26 %A to float
189 %C = fptoui float %B to i32
193 ; This can fold because the 54-bit output is signed and we discard the sign bit.
195 define i54 @test18(i64 %A) {
196 ; CHECK-LABEL: @test18(
197 ; CHECK-NEXT: [[C:%.*]] = trunc i64 [[A:%.*]] to i54
198 ; CHECK-NEXT: ret i54 [[C]]
200 %B = sitofp i64 %A to double
201 %C = fptosi double %B to i54
205 ; This can't fold because the 55-bit output won't fit the mantissa
206 ; even after discarding the sign bit.
208 define i55 @test19(i64 %A) {
209 ; CHECK-LABEL: @test19(
210 ; CHECK-NEXT: [[B:%.*]] = sitofp i64 [[A:%.*]] to double
211 ; CHECK-NEXT: [[C:%.*]] = fptosi double [[B]] to i55
212 ; CHECK-NEXT: ret i55 [[C]]
214 %B = sitofp i64 %A to double
215 %C = fptosi double %B to i55