File: fcmp.ll

package info (click to toggle)
llvm-toolchain-5.0 1:5.0.1-2~bpo9+1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 553,688 kB
  • sloc: cpp: 2,878,786; ansic: 584,110; asm: 246,252; python: 124,751; objc: 106,925; sh: 21,542; lisp: 8,628; pascal: 5,885; ml: 5,544; perl: 5,312; makefile: 2,208; cs: 2,022; xml: 686; php: 212; csh: 117
file content (336 lines) | stat: -rw-r--r-- 10,132 bytes parent folder | download | duplicates (4)
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
; RUN: opt -S -instcombine < %s | FileCheck %s

declare double @llvm.fabs.f64(double) nounwind readnone

define i1 @test1(float %x, float %y) nounwind {
; CHECK-LABEL: @test1(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp ogt float %x, %y
; CHECK-NEXT:    ret i1 [[CMP]]
;
  %ext1 = fpext float %x to double
  %ext2 = fpext float %y to double
  %cmp = fcmp ogt double %ext1, %ext2
  ret i1 %cmp
}

define i1 @test2(float %a) nounwind {
; CHECK-LABEL: @test2(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp ogt float %a, 1.000000e+00
; CHECK-NEXT:    ret i1 [[CMP]]
;
  %ext = fpext float %a to double
  %cmp = fcmp ogt double %ext, 1.000000e+00
  ret i1 %cmp
}

define i1 @test3(float %a) nounwind {
; CHECK-LABEL: @test3(
; CHECK-NEXT:    [[EXT:%.*]] = fpext float %a to double
; CHECK-NEXT:    [[CMP:%.*]] = fcmp ogt double [[EXT]], 0x3FF0000000000001
; CHECK-NEXT:    ret i1 [[CMP]]
;
  %ext = fpext float %a to double
  %cmp = fcmp ogt double %ext, 0x3FF0000000000001 ; more precision than float.
  ret i1 %cmp
}

define i1 @test4(float %a) nounwind {
; CHECK-LABEL: @test4(
; CHECK-NEXT:    [[EXT:%.*]] = fpext float %a to double
; CHECK-NEXT:    [[CMP:%.*]] = fcmp ogt double [[EXT]], 0x36A0000000000000
; CHECK-NEXT:    ret i1 [[CMP]]
;
  %ext = fpext float %a to double
  %cmp = fcmp ogt double %ext, 0x36A0000000000000 ; denormal in float.
  ret i1 %cmp
}

define i1 @test5(float %a) nounwind {
; CHECK-LABEL: @test5(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp olt float %a, -1.000000e+00
; CHECK-NEXT:    ret i1 [[CMP]]
;
  %neg = fsub float -0.000000e+00, %a
  %cmp = fcmp ogt float %neg, 1.000000e+00
  ret i1 %cmp
}

define i1 @test6(float %x, float %y) nounwind {
; CHECK-LABEL: @test6(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp ogt float %x, %y
; CHECK-NEXT:    ret i1 [[CMP]]
;
  %neg1 = fsub float -0.000000e+00, %x
  %neg2 = fsub float -0.000000e+00, %y
  %cmp = fcmp olt float %neg1, %neg2
  ret i1 %cmp
}

define i1 @test7(float %x) nounwind readnone ssp noredzone {
; CHECK-LABEL: @test7(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp ogt float %x, 0.000000e+00
; CHECK-NEXT:    ret i1 [[CMP]]
;
  %ext = fpext float %x to ppc_fp128
  %cmp = fcmp ogt ppc_fp128 %ext, 0xM00000000000000000000000000000000
  ret i1 %cmp
}

define float @test8(float %x) nounwind readnone optsize ssp {
; CHECK-LABEL: @test8(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp olt float %x, 0.000000e+00
; CHECK-NEXT:    [[CONV2:%.*]] = uitofp i1 [[CMP]] to float
; CHECK-NEXT:    ret float [[CONV2]]
;
  %conv = fpext float %x to double
  %cmp = fcmp olt double %conv, 0.000000e+00
  %conv1 = zext i1 %cmp to i32
  %conv2 = sitofp i32 %conv1 to float
  ret float %conv2
; Float comparison to zero shouldn't cast to double.
}

declare double @fabs(double) nounwind readnone

define i32 @test9(double %a) nounwind {
; CHECK-LABEL: @test9(
; CHECK-NEXT:    ret i32 0
;
  %call = tail call double @fabs(double %a) nounwind
  %cmp = fcmp olt double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test9_intrinsic(double %a) nounwind {
; CHECK-LABEL: @test9_intrinsic(
; CHECK-NEXT:    ret i32 0
;
  %call = tail call double @llvm.fabs.f64(double %a) nounwind
  %cmp = fcmp olt double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test10(double %a) nounwind {
; CHECK-LABEL: @test10(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp oeq double %a, 0.000000e+00
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
  %call = tail call double @fabs(double %a) nounwind
  %cmp = fcmp ole double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test10_intrinsic(double %a) nounwind {
; CHECK-LABEL: @test10_intrinsic(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp oeq double %a, 0.000000e+00
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
  %call = tail call double @llvm.fabs.f64(double %a) nounwind
  %cmp = fcmp ole double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test11(double %a) nounwind {
; CHECK-LABEL: @test11(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp one double %a, 0.000000e+00
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
  %call = tail call double @fabs(double %a) nounwind
  %cmp = fcmp ogt double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test11_intrinsic(double %a) nounwind {
; CHECK-LABEL: @test11_intrinsic(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp one double %a, 0.000000e+00
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
  %call = tail call double @llvm.fabs.f64(double %a) nounwind
  %cmp = fcmp ogt double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test12(double %a) nounwind {
; CHECK-LABEL: @test12(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp ord double %a, 0.000000e+00
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
  %call = tail call double @fabs(double %a) nounwind
  %cmp = fcmp oge double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test12_intrinsic(double %a) nounwind {
; CHECK-LABEL: @test12_intrinsic(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp ord double %a, 0.000000e+00
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
  %call = tail call double @llvm.fabs.f64(double %a) nounwind
  %cmp = fcmp oge double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test13(double %a) nounwind {
; CHECK-LABEL: @test13(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp une double %a, 0.000000e+00
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
  %call = tail call double @fabs(double %a) nounwind
  %cmp = fcmp une double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test13_intrinsic(double %a) nounwind {
; CHECK-LABEL: @test13_intrinsic(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp une double %a, 0.000000e+00
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
  %call = tail call double @llvm.fabs.f64(double %a) nounwind
  %cmp = fcmp une double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test14(double %a) nounwind {
; CHECK-LABEL: @test14(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp oeq double %a, 0.000000e+00
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
  %call = tail call double @fabs(double %a) nounwind
  %cmp = fcmp oeq double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test14_intrinsic(double %a) nounwind {
; CHECK-LABEL: @test14_intrinsic(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp oeq double %a, 0.000000e+00
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
  %call = tail call double @llvm.fabs.f64(double %a) nounwind
  %cmp = fcmp oeq double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test15(double %a) nounwind {
; CHECK-LABEL: @test15(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp one double %a, 0.000000e+00
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
  %call = tail call double @fabs(double %a) nounwind
  %cmp = fcmp one double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test15_intrinsic(double %a) nounwind {
; CHECK-LABEL: @test15_intrinsic(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp one double %a, 0.000000e+00
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
  %call = tail call double @llvm.fabs.f64(double %a) nounwind
  %cmp = fcmp one double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test16(double %a) nounwind {
; CHECK-LABEL: @test16(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp ueq double %a, 0.000000e+00
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
  %call = tail call double @fabs(double %a) nounwind
  %cmp = fcmp ueq double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test16_intrinsic(double %a) nounwind {
; CHECK-LABEL: @test16_intrinsic(
; CHECK-NEXT:    [[CMP:%.*]] = fcmp ueq double %a, 0.000000e+00
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
  %call = tail call double @llvm.fabs.f64(double %a) nounwind
  %cmp = fcmp ueq double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

; Don't crash.
define i32 @test17(double %a, double (double)* %p) nounwind {
; CHECK-LABEL: @test17(
; CHECK-NEXT:    [[CALL:%.*]] = tail call double %p(double %a) #1
; CHECK-NEXT:    [[CMP:%.*]] = fcmp ueq double [[CALL]], 0.000000e+00
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
  %call = tail call double %p(double %a) nounwind
  %cmp = fcmp ueq double %call, 0.000000e+00
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

; Can fold fcmp with undef on one side by choosing NaN for the undef
define i32 @test18_undef_unordered(float %a) nounwind {
; CHECK-LABEL: @test18_undef_unordered(
; CHECK-NEXT:    ret i32 1
;
  %cmp = fcmp ueq float %a, undef
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}
; Can fold fcmp with undef on one side by choosing NaN for the undef
define i32 @test18_undef_ordered(float %a) nounwind {
; CHECK-LABEL: @test18_undef_ordered(
; CHECK-NEXT:    ret i32 0
;
  %cmp = fcmp oeq float %a, undef
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

; Can fold fcmp with undef on both side
;   fcmp u_pred undef, undef -> true
;   fcmp o_pred undef, undef -> false
; because whatever you choose for the first undef
; you can choose NaN for the other undef
define i1 @test19_undef_unordered() nounwind {
; CHECK-LABEL: @test19_undef_unordered(
; CHECK-NEXT:    ret i1 true
;
  %cmp = fcmp ueq float undef, undef
  ret i1 %cmp
}

define i1 @test19_undef_ordered() nounwind {
; CHECK-LABEL: @test19_undef_ordered(
; CHECK-NEXT:    ret i1 false
;
  %cmp = fcmp oeq float undef, undef
  ret i1 %cmp
}