1 ; Test that floating-point strict compares are omitted if CC already has the
4 ; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 \
5 ; RUN: -enable-misched=0 -no-integrated-as | FileCheck %s
7 ; We need -enable-misched=0 to make sure f12 and following routines really
8 ; test the compare elimination pass.
11 declare float @llvm.fabs.f32(float %f)
13 ; Test addition followed by EQ, which can use the CC result of the addition.
14 define float @f1(float %a, float %b, ptr %dest) #0 {
16 ; CHECK: aebr %f0, %f2
17 ; CHECK-NEXT: ber %r14
20 %res = call float @llvm.experimental.constrained.fadd.f32(
22 metadata !"round.dynamic",
23 metadata !"fpexcept.strict") #0
24 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
25 float %res, float 0.0,
27 metadata !"fpexcept.strict") #0
28 br i1 %cmp, label %exit, label %store
31 store float %b, ptr %dest
38 ; ...and again with LT.
39 define float @f2(float %a, float %b, ptr %dest) #0 {
41 ; CHECK: aebr %f0, %f2
42 ; CHECK-NEXT: blr %r14
45 %res = call float @llvm.experimental.constrained.fadd.f32(
47 metadata !"round.dynamic",
48 metadata !"fpexcept.strict") #0
49 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
50 float %res, float 0.0,
52 metadata !"fpexcept.strict") #0
53 br i1 %cmp, label %exit, label %store
56 store float %b, ptr %dest
63 ; ...and again with GT.
64 define float @f3(float %a, float %b, ptr %dest) #0 {
66 ; CHECK: aebr %f0, %f2
67 ; CHECK-NEXT: bhr %r14
70 %res = call float @llvm.experimental.constrained.fadd.f32(
72 metadata !"round.dynamic",
73 metadata !"fpexcept.strict") #0
74 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
75 float %res, float 0.0,
77 metadata !"fpexcept.strict") #0
78 br i1 %cmp, label %exit, label %store
81 store float %b, ptr %dest
88 ; ...and again with UEQ.
89 define float @f4(float %a, float %b, ptr %dest) #0 {
91 ; CHECK: aebr %f0, %f2
92 ; CHECK-NEXT: bnlhr %r14
95 %res = call float @llvm.experimental.constrained.fadd.f32(
97 metadata !"round.dynamic",
98 metadata !"fpexcept.strict") #0
99 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
100 float %res, float 0.0,
102 metadata !"fpexcept.strict") #0
103 br i1 %cmp, label %exit, label %store
106 store float %b, ptr %dest
113 ; Subtraction also provides a zero-based CC value.
114 define float @f5(float %a, float %b, ptr %dest) #0 {
116 ; CHECK: seb %f0, 0(%r2)
117 ; CHECK-NEXT: bnher %r14
120 %cur = load float, ptr %dest
121 %res = call float @llvm.experimental.constrained.fsub.f32(
122 float %a, float %cur,
123 metadata !"round.dynamic",
124 metadata !"fpexcept.strict") #0
125 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
126 float %res, float 0.0,
128 metadata !"fpexcept.strict") #0
129 br i1 %cmp, label %exit, label %store
132 store float %b, ptr %dest
139 ; Test the result of LOAD POSITIVE. We cannot omit the LTEBR.
140 define float @f6(float %dummy, float %a, ptr %dest) #0 {
142 ; CHECK: lpdfr %f0, %f2
143 ; CHECK-NEXT: ltebr %f1, %f0
144 ; CHECK-NEXT: bhr %r14
147 %res = call float @llvm.fabs.f32(float %a) #0
148 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
149 float %res, float 0.0,
151 metadata !"fpexcept.strict") #0
152 br i1 %cmp, label %exit, label %store
155 store float %res, ptr %dest
162 ; Test the result of LOAD NEGATIVE. We cannot omit the LTEBR.
163 define float @f7(float %dummy, float %a, ptr %dest) #0 {
165 ; CHECK: lndfr %f0, %f2
166 ; CHECK-NEXT: ltebr %f1, %f0
167 ; CHECK-NEXT: blr %r14
170 %abs = call float @llvm.fabs.f32(float %a) #0
171 %res = fneg float %abs
172 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
173 float %res, float 0.0,
175 metadata !"fpexcept.strict") #0
176 br i1 %cmp, label %exit, label %store
179 store float %res, ptr %dest
186 ; Test the result of LOAD COMPLEMENT. We cannot omit the LTEBR.
187 define float @f8(float %dummy, float %a, ptr %dest) #0 {
189 ; CHECK: lcdfr %f0, %f2
190 ; CHECK-NEXT: ltebr %f1, %f0
191 ; CHECK-NEXT: bler %r14
195 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
196 float %res, float 0.0,
198 metadata !"fpexcept.strict") #0
199 br i1 %cmp, label %exit, label %store
202 store float %res, ptr %dest
209 ; Multiplication (for example) does not modify CC.
210 define float @f9(float %a, float %b, ptr %dest) #0 {
212 ; CHECK: meebr %f0, %f2
213 ; CHECK-NEXT: ltebr %f1, %f0
214 ; CHECK-NEXT: blhr %r14
217 %res = call float @llvm.experimental.constrained.fmul.f32(
219 metadata !"round.dynamic",
220 metadata !"fpexcept.strict") #0
221 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
222 float %res, float 0.0,
224 metadata !"fpexcept.strict") #0
225 br i1 %cmp, label %exit, label %store
228 store float %b, ptr %dest
235 ; Test a combination involving a CC-setting instruction followed by
236 ; a non-CC-setting instruction.
237 define float @f10(float %a, float %b, float %c, ptr %dest) #0 {
239 ; CHECK: aebr %f0, %f2
240 ; CHECK-NEXT: debr %f0, %f4
241 ; CHECK-NEXT: ltebr %f1, %f0
242 ; CHECK-NEXT: bner %r14
245 %add = call float @llvm.experimental.constrained.fadd.f32(
247 metadata !"round.dynamic",
248 metadata !"fpexcept.strict") #0
249 %res = call float @llvm.experimental.constrained.fdiv.f32(
250 float %add, float %c,
251 metadata !"round.dynamic",
252 metadata !"fpexcept.strict") #0
253 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
254 float %res, float 0.0,
256 metadata !"fpexcept.strict") #0
257 br i1 %cmp, label %exit, label %store
260 store float %b, ptr %dest
267 ; Test a case where CC is set based on a different register from the
269 define float @f11(float %a, float %b, float %c, ptr %dest1, ptr %dest2) #0 {
271 ; CHECK: aebr %f0, %f2
272 ; CHECK-NEXT: sebr %f4, %f0
273 ; CHECK-DAG: ste %f4, 0(%r2)
274 ; CHECK-DAG: ltebr %f1, %f0
275 ; CHECK-NEXT: ber %r14
278 %add = call float @llvm.experimental.constrained.fadd.f32(
280 metadata !"round.dynamic",
281 metadata !"fpexcept.strict") #0
282 %sub = call float @llvm.experimental.constrained.fsub.f32(
283 float %c, float %add,
284 metadata !"round.dynamic",
285 metadata !"fpexcept.strict") #0
286 store float %sub, ptr %dest1
287 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
288 float %add, float 0.0,
290 metadata !"fpexcept.strict") #0
291 br i1 %cmp, label %exit, label %store
294 store float %sub, ptr %dest2
301 ; Test that LER does not get converted to LTEBR as %f0 is live after it.
302 define float @f12(float %dummy, float %val) #0 {
304 ; CHECK: ler %f0, %f2
306 ; CHECK-NEXT: blah %f0
307 ; CHECK-NEXT: #NO_APP
308 ; CHECK-NEXT: ltebr %f1, %f2
309 ; CHECK-NEXT: blr %r14
312 %ret = call float asm "blah $1", "=f,{f0}"(float %val) #0
313 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
314 float %val, float 0.0,
316 metadata !"fpexcept.strict") #0
317 br i1 %cmp, label %exit, label %store
320 call void asm sideeffect "blah", ""() #0
327 ; Test that LDR does not get converted to LTDBR as %f0 is live after it.
328 define double @f13(double %dummy, double %val) #0 {
330 ; CHECK: ldr %f0, %f2
332 ; CHECK-NEXT: blah %f0
333 ; CHECK-NEXT: #NO_APP
334 ; CHECK-NEXT: ltdbr %f1, %f2
335 ; CHECK-NEXT: blr %r14
338 %ret = call double asm "blah $1", "=f,{f0}"(double %val) #0
339 %cmp = call i1 @llvm.experimental.constrained.fcmp.f64(
340 double %val, double 0.0,
342 metadata !"fpexcept.strict") #0
343 br i1 %cmp, label %exit, label %store
346 call void asm sideeffect "blah", ""() #0
353 ; Test that LXR does not get converted to LTXBR as %f4 is live after it.
354 define void @f14(ptr %ptr1, ptr %ptr2) #0 {
364 ; CHECK-NEXT: blr %r14
367 %val1 = load fp128, ptr %ptr1
368 %val2 = load fp128, ptr %ptr2
369 %div = fdiv fp128 %val1, %val2
370 store fp128 %div, ptr %ptr1
371 %mul = fmul fp128 %val1, %val2
372 store fp128 %mul, ptr %ptr2
373 %cmp = call i1 @llvm.experimental.constrained.fcmp.f128(
374 fp128 %val1, fp128 0xL00000000000000000000000000000000,
376 metadata !"fpexcept.strict") #0
377 br i1 %cmp, label %exit, label %store
380 call void asm sideeffect "blah", ""() #0
387 ; Test a case where it is the source rather than destination of LER that
388 ; we need, but cannot convert the LER.
389 define float @f15(float %val, float %dummy) #0 {
391 ; CHECK: ler %f2, %f0
393 ; CHECK-NEXT: blah %f2
394 ; CHECK-NEXT: #NO_APP
395 ; CHECK-NEXT: ltebr %f1, %f2
396 ; CHECK-NEXT: blr %r14
399 %ret = call float asm "blah $1", "=f,{f2}"(float %val) #0
400 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
401 float %val, float 0.0,
403 metadata !"fpexcept.strict") #0
404 br i1 %cmp, label %exit, label %store
407 call void asm sideeffect "blah", ""() #0
414 ; Test a case where it is the source rather than destination of LDR that
415 ; we need, but cannot convert the LDR.
416 define double @f16(double %val, double %dummy) #0 {
418 ; CHECK: ldr %f2, %f0
420 ; CHECK-NEXT: blah %f2
421 ; CHECK-NEXT: #NO_APP
422 ; CHECK-NEXT: ltdbr %f1, %f2
423 ; CHECK-NEXT: blr %r14
426 %ret = call double asm "blah $1", "=f,{f2}"(double %val) #0
427 %cmp = call i1 @llvm.experimental.constrained.fcmp.f64(
428 double %val, double 0.0,
430 metadata !"fpexcept.strict") #0
431 br i1 %cmp, label %exit, label %store
434 call void asm sideeffect "blah", ""() #0
441 ; Repeat f2 with a comparison against -0.
442 define float @f17(float %a, float %b, ptr %dest) #0 {
444 ; CHECK: aebr %f0, %f2
445 ; CHECK-NEXT: blr %r14
448 %res = call float @llvm.experimental.constrained.fadd.f32(
450 metadata !"round.dynamic",
451 metadata !"fpexcept.strict") #0
452 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
453 float %res, float -0.0,
455 metadata !"fpexcept.strict") #0
456 br i1 %cmp, label %exit, label %store
459 store float %b, ptr %dest
466 ; Verify that we cannot omit the compare if there may be an intervening
467 ; change to the exception flags.
468 define float @f18(float %a, float %b, ptr %dest) #0 {
470 ; CHECK: aebr %f0, %f2
471 ; CHECK: ltebr %f1, %f0
472 ; CHECK-NEXT: ber %r14
475 %res = call float @llvm.experimental.constrained.fadd.f32(
477 metadata !"round.dynamic",
478 metadata !"fpexcept.strict") #0
479 call void asm sideeffect "blah", ""() #0
480 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
481 float %res, float 0.0,
483 metadata !"fpexcept.strict") #0
484 br i1 %cmp, label %exit, label %store
487 store float %b, ptr %dest
494 ; Verify that we cannot convert LER to LTEBR and omit the compare if
495 ; there may be an intervening change to the exception flags.
496 define float @f19(float %dummy, float %val) #0 {
498 ; CHECK: ler %f0, %f2
500 ; CHECK-NEXT: blah %f0
501 ; CHECK-NEXT: #NO_APP
502 ; CHECK-NEXT: ltebr %f1, %f2
503 ; CHECK-NEXT: blr %r14
506 %ret = call float asm sideeffect "blah $1", "=f,{f0}"(float %val) #0
507 %cmp = call i1 @llvm.experimental.constrained.fcmp.f32(
508 float %val, float 0.0,
510 metadata !"fpexcept.strict") #0
511 br i1 %cmp, label %exit, label %store
514 call void asm sideeffect "blah", ""() #0
521 attributes #0 = { strictfp }
523 declare float @llvm.experimental.constrained.fadd.f32(float, float, metadata, metadata)
524 declare float @llvm.experimental.constrained.fsub.f32(float, float, metadata, metadata)
525 declare float @llvm.experimental.constrained.fmul.f32(float, float, metadata, metadata)
526 declare float @llvm.experimental.constrained.fdiv.f32(float, float, metadata, metadata)
527 declare i1 @llvm.experimental.constrained.fcmp.f32(float, float, metadata, metadata)
528 declare i1 @llvm.experimental.constrained.fcmp.f64(double, double, metadata, metadata)
529 declare i1 @llvm.experimental.constrained.fcmp.f128(fp128, fp128, metadata, metadata)