sitofp.ll
4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
define i1 @test1(i8 %A) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: ret i1 true
;
%B = sitofp i8 %A to double
%C = fcmp ult double %B, 128.0
ret i1 %C
}
define i1 @test2(i8 %A) {
; CHECK-LABEL: @test2(
; CHECK-NEXT: ret i1 true
;
%B = sitofp i8 %A to double
%C = fcmp ugt double %B, -128.1
ret i1 %C
}
define i1 @test3(i8 %A) {
; CHECK-LABEL: @test3(
; CHECK-NEXT: ret i1 true
;
%B = sitofp i8 %A to double
%C = fcmp ule double %B, 127.0
ret i1 %C
}
define i1 @test4(i8 %A) {
; CHECK-LABEL: @test4(
; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[A:%.*]], 127
; CHECK-NEXT: ret i1 [[C]]
;
%B = sitofp i8 %A to double
%C = fcmp ult double %B, 127.0
ret i1 %C
}
define i32 @test5(i32 %A) {
; CHECK-LABEL: @test5(
; CHECK-NEXT: ret i32 [[A:%.*]]
;
%B = sitofp i32 %A to double
%C = fptosi double %B to i32
%D = uitofp i32 %C to double
%E = fptoui double %D to i32
ret i32 %E
}
define i32 @test6(i32 %A) {
; CHECK-LABEL: @test6(
; CHECK-NEXT: [[ADDCONV:%.*]] = and i32 [[A:%.*]], 39
; CHECK-NEXT: ret i32 [[ADDCONV]]
;
%B = and i32 %A, 7
%C = and i32 %A, 32
%D = sitofp i32 %B to double
%E = sitofp i32 %C to double
%F = fadd double %D, %E
%G = fptosi double %F to i32
ret i32 %G
}
define i32 @test7(i32 %A) {
; CHECK-LABEL: @test7(
; CHECK-NEXT: ret i32 [[A:%.*]]
;
%B = sitofp i32 %A to double
%C = fptoui double %B to i32
ret i32 %C
}
define i32 @test8(i32 %A) {
; CHECK-LABEL: @test8(
; CHECK-NEXT: ret i32 [[A:%.*]]
;
%B = uitofp i32 %A to double
%C = fptosi double %B to i32
ret i32 %C
}
define i32 @test9(i8 %A) {
; CHECK-LABEL: @test9(
; CHECK-NEXT: [[C:%.*]] = zext i8 [[A:%.*]] to i32
; CHECK-NEXT: ret i32 [[C]]
;
%B = sitofp i8 %A to float
%C = fptoui float %B to i32
ret i32 %C
}
define i32 @test10(i8 %A) {
; CHECK-LABEL: @test10(
; CHECK-NEXT: [[C:%.*]] = sext i8 [[A:%.*]] to i32
; CHECK-NEXT: ret i32 [[C]]
;
%B = sitofp i8 %A to float
%C = fptosi float %B to i32
ret i32 %C
}
; If the input value is outside of the range of the output cast, it's
; undefined behavior, so we can assume it fits.
define i8 @test11(i32 %A) {
; CHECK-LABEL: @test11(
; CHECK-NEXT: [[C:%.*]] = trunc i32 [[A:%.*]] to i8
; CHECK-NEXT: ret i8 [[C]]
;
%B = sitofp i32 %A to float
%C = fptosi float %B to i8
ret i8 %C
}
; If the input value is negative, it'll be outside the range of the
; output cast, and thus undefined behavior.
define i32 @test12(i8 %A) {
; CHECK-LABEL: @test12(
; CHECK-NEXT: [[C:%.*]] = zext i8 [[A:%.*]] to i32
; CHECK-NEXT: ret i32 [[C]]
;
%B = sitofp i8 %A to float
%C = fptoui float %B to i32
ret i32 %C
}
; This can't fold because the 25-bit input doesn't fit in the mantissa.
define i32 @test13(i25 %A) {
; CHECK-LABEL: @test13(
; CHECK-NEXT: [[B:%.*]] = uitofp i25 [[A:%.*]] to float
; CHECK-NEXT: [[C:%.*]] = fptoui float [[B]] to i32
; CHECK-NEXT: ret i32 [[C]]
;
%B = uitofp i25 %A to float
%C = fptoui float %B to i32
ret i32 %C
}
; But this one can.
define i32 @test14(i24 %A) {
; CHECK-LABEL: @test14(
; CHECK-NEXT: [[C:%.*]] = zext i24 [[A:%.*]] to i32
; CHECK-NEXT: ret i32 [[C]]
;
%B = uitofp i24 %A to float
%C = fptoui float %B to i32
ret i32 %C
}
; And this one can too.
define i24 @test15(i32 %A) {
; CHECK-LABEL: @test15(
; CHECK-NEXT: [[C:%.*]] = trunc i32 [[A:%.*]] to i24
; CHECK-NEXT: ret i24 [[C]]
;
%B = uitofp i32 %A to float
%C = fptoui float %B to i24
ret i24 %C
}
; This can fold because the 25-bit input is signed and we discard the sign bit.
define i32 @test16(i25 %A) {
; CHECK-LABEL: @test16(
; CHECK-NEXT: [[C:%.*]] = zext i25 [[A:%.*]] to i32
; CHECK-NEXT: ret i32 [[C]]
;
%B = sitofp i25 %A to float
%C = fptoui float %B to i32
ret i32 %C
}
; This can't fold because the 26-bit input won't fit the mantissa
; even after discarding the signed bit.
define i32 @test17(i26 %A) {
; CHECK-LABEL: @test17(
; CHECK-NEXT: [[B:%.*]] = sitofp i26 [[A:%.*]] to float
; CHECK-NEXT: [[C:%.*]] = fptoui float [[B]] to i32
; CHECK-NEXT: ret i32 [[C]]
;
%B = sitofp i26 %A to float
%C = fptoui float %B to i32
ret i32 %C
}
; This can fold because the 54-bit output is signed and we discard the sign bit.
define i54 @test18(i64 %A) {
; CHECK-LABEL: @test18(
; CHECK-NEXT: [[C:%.*]] = trunc i64 [[A:%.*]] to i54
; CHECK-NEXT: ret i54 [[C]]
;
%B = sitofp i64 %A to double
%C = fptosi double %B to i54
ret i54 %C
}
; This can't fold because the 55-bit output won't fit the mantissa
; even after discarding the sign bit.
define i55 @test19(i64 %A) {
; CHECK-LABEL: @test19(
; CHECK-NEXT: [[B:%.*]] = sitofp i64 [[A:%.*]] to double
; CHECK-NEXT: [[C:%.*]] = fptosi double [[B]] to i55
; CHECK-NEXT: ret i55 [[C]]
;
%B = sitofp i64 %A to double
%C = fptosi double %B to i55
ret i55 %C
}