1 ; Test that floating-point compares are omitted if CC already has the
4 ; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 -no-integrated-as | FileCheck %s
6 declare float @llvm.fabs.f32(float %f)
8 ; Test addition followed by EQ, which can use the CC result of the addition.
9 define float @f1(float %a, float %b, ptr %dest) {
11 ; CHECK: aebr %f0, %f2
12 ; CHECK-NEXT: ber %r14
15 %res = fadd float %a, %b
16 %cmp = fcmp oeq float %res, 0.0
17 br i1 %cmp, label %exit, label %store
20 store float %b, ptr %dest
27 ; ...and again with LT.
28 define float @f2(float %a, float %b, ptr %dest) {
30 ; CHECK: aebr %f0, %f2
31 ; CHECK-NEXT: blr %r14
34 %res = fadd float %a, %b
35 %cmp = fcmp olt float %res, 0.0
36 br i1 %cmp, label %exit, label %store
39 store float %b, ptr %dest
46 ; ...and again with GT.
47 define float @f3(float %a, float %b, ptr %dest) {
49 ; CHECK: aebr %f0, %f2
50 ; CHECK-NEXT: bhr %r14
53 %res = fadd float %a, %b
54 %cmp = fcmp ogt float %res, 0.0
55 br i1 %cmp, label %exit, label %store
58 store float %b, ptr %dest
65 ; ...and again with UEQ.
66 define float @f4(float %a, float %b, ptr %dest) {
68 ; CHECK: aebr %f0, %f2
69 ; CHECK-NEXT: bnlhr %r14
72 %res = fadd float %a, %b
73 %cmp = fcmp ueq float %res, 0.0
74 br i1 %cmp, label %exit, label %store
77 store float %b, ptr %dest
84 ; Subtraction also provides a zero-based CC value.
85 define float @f5(float %a, float %b, ptr %dest) {
87 ; CHECK: seb %f0, 0(%r2)
88 ; CHECK-NEXT: bnher %r14
91 %cur = load float, ptr %dest
92 %res = fsub float %a, %cur
93 %cmp = fcmp ult float %res, 0.0
94 br i1 %cmp, label %exit, label %store
97 store float %b, ptr %dest
104 ; Test the result of LOAD POSITIVE.
105 define float @f6(float %dummy, float %a, ptr %dest) {
107 ; CHECK: lpebr %f0, %f2
108 ; CHECK-NEXT: bhr %r14
111 %res = call float @llvm.fabs.f32(float %a)
112 %cmp = fcmp ogt float %res, 0.0
113 br i1 %cmp, label %exit, label %store
116 store float %res, ptr %dest
123 ; Test the result of LOAD NEGATIVE.
124 define float @f7(float %dummy, float %a, ptr %dest) {
126 ; CHECK: lnebr %f0, %f2
127 ; CHECK-NEXT: blr %r14
130 %abs = call float @llvm.fabs.f32(float %a)
131 %res = fneg float %abs
132 %cmp = fcmp olt float %res, 0.0
133 br i1 %cmp, label %exit, label %store
136 store float %res, ptr %dest
143 ; Test the result of LOAD COMPLEMENT.
144 define float @f8(float %dummy, float %a, ptr %dest) {
146 ; CHECK: lcebr %f0, %f2
147 ; CHECK-NEXT: bler %r14
151 %cmp = fcmp ole float %res, 0.0
152 br i1 %cmp, label %exit, label %store
155 store float %res, ptr %dest
162 ; Multiplication (for example) does not modify CC.
163 define float @f9(float %a, float %b, ptr %dest) {
165 ; CHECK: meebr %f0, %f2
166 ; CHECK-NEXT: ltebr %f1, %f0
167 ; CHECK-NEXT: blhr %r14
170 %res = fmul float %a, %b
171 %cmp = fcmp one float %res, 0.0
172 br i1 %cmp, label %exit, label %store
175 store float %b, ptr %dest
182 ; Test a combination involving a CC-setting instruction followed by
183 ; a non-CC-setting instruction.
184 define float @f10(float %a, float %b, float %c, ptr %dest) {
186 ; CHECK: aebr %f0, %f2
187 ; CHECK-NEXT: debr %f0, %f4
188 ; CHECK-NEXT: ltebr %f1, %f0
189 ; CHECK-NEXT: bner %r14
192 %add = fadd float %a, %b
193 %res = fdiv float %add, %c
194 %cmp = fcmp une float %res, 0.0
195 br i1 %cmp, label %exit, label %store
198 store float %b, ptr %dest
205 ; Test a case where CC is set based on a different register from the
207 define float @f11(float %a, float %b, float %c, ptr %dest1, ptr %dest2) {
209 ; CHECK: aebr %f0, %f2
210 ; CHECK-NEXT: sebr %f4, %f0
211 ; CHECK-DAG: ste %f4, 0(%r2)
212 ; CHECK-DAG: ltebr %f1, %f0
213 ; CHECK-NEXT: ber %r14
216 %add = fadd float %a, %b
217 %sub = fsub float %c, %add
218 store float %sub, ptr %dest1
219 %cmp = fcmp oeq float %add, 0.0
220 br i1 %cmp, label %exit, label %store
223 store float %sub, ptr %dest2
230 ; %val in %f2 must be preserved during comparison and also copied to %f0.
231 define float @f12(float %dummy, float %val, ptr %dest) {
233 ; CHECK: ler %f0, %f2
234 ; CHECK-NEXT: ltebr %f1, %f2
236 ; CHECK-NEXT: blah %f0
237 ; CHECK-NEXT: #NO_APP
238 ; CHECK-NEXT: blr %r14
241 call void asm sideeffect "blah $0", "{f0}"(float %val)
242 %cmp = fcmp olt float %val, 0.0
243 br i1 %cmp, label %exit, label %store
246 store float %val, ptr %dest
254 define double @f13(double %dummy, double %val, ptr %dest) {
256 ; CHECK: ldr %f0, %f2
257 ; CHECK-NEXT: ltdbr %f1, %f2
259 ; CHECK-NEXT: blah %f0
260 ; CHECK-NEXT: #NO_APP
261 ; CHECK-NEXT: blr %r14
264 call void asm sideeffect "blah $0", "{f0}"(double %val)
265 %cmp = fcmp olt double %val, 0.0
266 br i1 %cmp, label %exit, label %store
269 store double %val, ptr %dest
276 ; LXR cannot be converted to LTXBR as its input is live after it.
277 define void @f14(ptr %ptr1, ptr %ptr2) {
287 ; CHECK-NEXT: blr %r14
290 %val1 = load fp128, ptr %ptr1
291 %val2 = load fp128, ptr %ptr2
292 %div = fdiv fp128 %val1, %val2
293 store fp128 %div, ptr %ptr1
294 %mul = fmul fp128 %val1, %val2
295 store fp128 %mul, ptr %ptr2
296 %cmp = fcmp olt fp128 %val1, 0xL00000000000000000000000000000000
297 br i1 %cmp, label %exit, label %store
300 call void asm sideeffect "blah", ""()
307 define float @f15(float %val, float %dummy, ptr %dest) {
309 ; CHECK: ltebr %f1, %f0
310 ; CHECK-NEXT: ler %f2, %f0
312 ; CHECK-NEXT: blah %f2
313 ; CHECK-NEXT: #NO_APP
314 ; CHECK-NEXT: blr %r14
317 call void asm sideeffect "blah $0", "{f2}"(float %val)
318 %cmp = fcmp olt float %val, 0.0
319 br i1 %cmp, label %exit, label %store
322 store float %val, ptr %dest
329 define double @f16(double %val, double %dummy, ptr %dest) {
331 ; CHECK: ltdbr %f1, %f0
332 ; CHECK: ldr %f2, %f0
334 ; CHECK-NEXT: blah %f2
335 ; CHECK-NEXT: #NO_APP
336 ; CHECK-NEXT: blr %r14
339 call void asm sideeffect "blah $0", "{f2}"(double %val)
340 %cmp = fcmp olt double %val, 0.0
341 br i1 %cmp, label %exit, label %store
344 store double %val, ptr %dest
351 ; Repeat f2 with a comparison against -0.
352 define float @f17(float %a, float %b, ptr %dest) {
354 ; CHECK: aebr %f0, %f2
355 ; CHECK-NEXT: blr %r14
358 %res = fadd float %a, %b
359 %cmp = fcmp olt float %res, -0.0
360 br i1 %cmp, label %exit, label %store
363 store float %b, ptr %dest
370 ; Test another form of f7 in which the condition is based on the unnegated
371 ; result. This is what InstCombine would produce.
372 define float @f18(float %dummy, float %a, ptr %dest) {
374 ; CHECK: # %bb.0: # %entry
375 ; CHECK-NEXT: lnebr %f0, %f2
376 ; CHECK-NEXT: blr %r14
377 ; CHECK-NEXT: .LBB17_1: # %store
378 ; CHECK-NEXT: ste %f0, 0(%r2)
379 ; CHECK-NEXT: br %r14
381 %abs = call float @llvm.fabs.f32(float %a)
382 %res = fneg float %abs
383 %cmp = fcmp ogt float %abs, 0.0
384 br i1 %cmp, label %exit, label %store
387 store float %res, ptr %dest
395 define float @f19(float %dummy, float %a, ptr %dest) {
397 ; CHECK: # %bb.0: # %entry
398 ; CHECK-NEXT: lcebr %f0, %f2
399 ; CHECK-NEXT: bler %r14
400 ; CHECK-NEXT: .LBB18_1: # %store
401 ; CHECK-NEXT: ste %f0, 0(%r2)
402 ; CHECK-NEXT: br %r14
405 %cmp = fcmp oge float %a, 0.0
406 br i1 %cmp, label %exit, label %store
409 store float %res, ptr %dest