llvm.org GIT mirror llvm / 6d62c71
DAG: Check no signed zeros instead of unsafe math attribute git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297354 91177308-0d34-0410-b5e6-96231b3b80d8 Matt Arsenault 2 years ago
7 changed file(s) with 52 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
91419141 GetNegatedExpression(N0, DAG, LegalOperations), Flags);
91429142
91439143 // FIXME: Auto-upgrade the target/function-level option.
9144 if (Options.UnsafeFPMath || N->getFlags()->hasNoSignedZeros()) {
9144 if (Options.NoSignedZerosFPMath || N->getFlags()->hasNoSignedZeros()) {
91459145 // fold (fadd A, 0) -> A
91469146 if (ConstantFPSDNode *N1C = isConstOrConstSplatFP(N1))
91479147 if (N1C->isZero())
92849284 GetNegatedExpression(N1, DAG, LegalOperations), Flags);
92859285
92869286 // FIXME: Auto-upgrade the target/function-level option.
9287 if (Options.UnsafeFPMath || N->getFlags()->hasNoSignedZeros()) {
9287 if (Options.NoSignedZerosFPMath || N->getFlags()->hasNoSignedZeros()) {
92889288 // (fsub 0, B) -> -B
92899289 if (N0CFP && N0CFP->isZero()) {
92909290 if (isNegatibleForFree(N1, LegalOperations, TLI, &Options))
44 ; FUNC-LABEL: {{^}}fadd_f32:
55 ; R600: ADD {{\** *}}T{{[0-9]+\.[XYZW]}}, KC0[2].Z, KC0[2].W
66 ; SI: v_add_f32
7 define void @fadd_f32(float addrspace(1)* %out, float %a, float %b) {
7 define void @fadd_f32(float addrspace(1)* %out, float %a, float %b) #0 {
88 %add = fadd float %a, %b
99 store float %add, float addrspace(1)* %out, align 4
1010 ret void
1515 ; R600-DAG: ADD {{\** *}}T{{[0-9]\.[XYZW]}}, KC0[2].W, KC0[3].Y
1616 ; SI: v_add_f32
1717 ; SI: v_add_f32
18 define void @fadd_v2f32(<2 x float> addrspace(1)* %out, <2 x float> %a, <2 x float> %b) {
18 define void @fadd_v2f32(<2 x float> addrspace(1)* %out, <2 x float> %a, <2 x float> %b) #0 {
1919 %add = fadd <2 x float> %a, %b
2020 store <2 x float> %add, <2 x float> addrspace(1)* %out, align 8
2121 ret void
3030 ; SI: v_add_f32
3131 ; SI: v_add_f32
3232 ; SI: v_add_f32
33 define void @fadd_v4f32(<4 x float> addrspace(1)* %out, <4 x float> addrspace(1)* %in) {
33 define void @fadd_v4f32(<4 x float> addrspace(1)* %out, <4 x float> addrspace(1)* %in) #0 {
3434 %b_ptr = getelementptr <4 x float>, <4 x float> addrspace(1)* %in, i32 1
3535 %a = load <4 x float>, <4 x float> addrspace(1)* %in, align 16
3636 %b = load <4 x float>, <4 x float> addrspace(1)* %b_ptr, align 16
5656 ; SI: v_add_f32
5757 ; SI: v_add_f32
5858 ; SI: v_add_f32
59 define void @fadd_v8f32(<8 x float> addrspace(1)* %out, <8 x float> %a, <8 x float> %b) {
59 define void @fadd_v8f32(<8 x float> addrspace(1)* %out, <8 x float> %a, <8 x float> %b) #0 {
6060 %add = fadd <8 x float> %a, %b
6161 store <8 x float> %add, <8 x float> addrspace(1)* %out, align 32
6262 ret void
6363 }
64
65 ; FUNC-LABEL: {{^}}fadd_0_nsz_attr_f32:
66 ; SI-NOT: v_add_f32
67 define void @fadd_0_nsz_attr_f32(float addrspace(1)* %out, float %a) #1 {
68 %add = fadd float %a, 0.0
69 store float %add, float addrspace(1)* %out, align 4
70 ret void
71 }
72
73 attributes #0 = { nounwind }
74 attributes #1 = { nounwind "no-signed-zeros-fp-math"="true" }
120120 ret void
121121 }
122122
123 ; FUNC-LABEL: {{^}}v_fsub_0_nsz_attribute_f32:
124 ; SI-NOT: v_sub
125 define void @v_fsub_0_nsz_attribute_f32(float addrspace(1)* %out, float addrspace(1)* %in) #0 {
126 %a = load float, float addrspace(1)* %in, align 4
127 %result = fsub float %a, 0.0
128 store float %result, float addrspace(1)* %out, align 4
129 ret void
130 }
131
123132 attributes #0 = { nounwind "no-signed-zeros-fp-math"="true" }
124133 attributes #1 = { nounwind "no-signed-zeros-fp-math"="false" }
112112 ret void
113113 }
114114
115 ; GCN-LABEL: {{^}}unsafe_mad_sub0_src0:
116 ; GCN-NOT: v_mac_f32
117 ; GCN: v_mad_f32 v{{[0-9]+}}, -v{{[0-9]+}}, v{{[0-9]+}}, v{{[-0-9]}}
118 define void @unsafe_mad_sub0_src0(float addrspace(1)* %out, float addrspace(1)* %in) #1 {
115 ; GCN-LABEL: {{^}}nsz_mad_sub0_src0:
116 ; GCN-NOT: v_mac_f32
117 ; GCN: v_mad_f32 v{{[0-9]+}}, -v{{[0-9]+}}, v{{[0-9]+}}, v{{[-0-9]}}
118 define void @nsz_mad_sub0_src0(float addrspace(1)* %out, float addrspace(1)* %in) #1 {
119119 entry:
120120 %b_ptr = getelementptr float, float addrspace(1)* %in, i32 1
121121 %c_ptr = getelementptr float, float addrspace(1)* %in, i32 2
172172 ret void
173173 }
174174
175 ; GCN-LABEL: {{^}}unsafe_mad_sub0_src1:
176 ; GCN-NOT: v_mac_f32
177 ; GCN: v_mad_f32 v{{[0-9]+}}, -v{{[0-9]+}}, v{{[0-9]+}}, v{{[-0-9]}}
178 define void @unsafe_mad_sub0_src1(float addrspace(1)* %out, float addrspace(1)* %in) #1 {
175 ; GCN-LABEL: {{^}}nsz_mad_sub0_src1:
176 ; GCN-NOT: v_mac_f32
177 ; GCN: v_mad_f32 v{{[0-9]+}}, -v{{[0-9]+}}, v{{[0-9]+}}, v{{[-0-9]}}
178 define void @nsz_mad_sub0_src1(float addrspace(1)* %out, float addrspace(1)* %in) #1 {
179179 entry:
180180 %b_ptr = getelementptr float, float addrspace(1)* %in, i32 1
181181 %c_ptr = getelementptr float, float addrspace(1)* %in, i32 2
280280
281281 declare i32 @llvm.amdgcn.workitem.id.x() #2
282282
283 attributes #0 = { nounwind "unsafe-fp-math"="false" }
284 attributes #1 = { nounwind "unsafe-fp-math"="true" }
283 attributes #0 = { nounwind "no-signed-zeros-fp-math"="false" }
284 attributes #1 = { nounwind "no-signed-zeros-fp-math"="true" }
285285 attributes #2 = { nounwind readnone }
286286 attributes #3 = { nounwind }
216216 ret void
217217 }
218218
219 ; GCN-LABEL: {{^}}mac_f16_neg_a_unsafe_fp_math:
219 ; GCN-LABEL: {{^}}mac_f16_neg_a_nsz_fp_math:
220220 ; SI: v_cvt_f32_f16_e32 [[CVT_A:v[0-9]+]], v{{[0-9]+}}
221221 ; SI: v_cvt_f32_f16_e32 [[CVT_B:v[0-9]+]], v{{[0-9]+}}
222222 ; SI: v_cvt_f32_f16_e32 [[CVT_C:v[0-9]+]], v{{[0-9]+}}
225225 ; VI-NOT: v_mac_f16
226226 ; VI: v_mad_f16 v{{[0-9]+}}, -v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]}}
227227 ; GCN: s_endpgm
228 define void @mac_f16_neg_a_unsafe_fp_math(
228 define void @mac_f16_neg_a_nsz_fp_math(
229229 half addrspace(1)* %r,
230230 half addrspace(1)* %a,
231231 half addrspace(1)* %b,
243243 ret void
244244 }
245245
246 ; GCN-LABEL: {{^}}mac_f16_neg_b_unsafe_fp_math:
246 ; GCN-LABEL: {{^}}mac_f16_neg_b_nsz_fp_math:
247247 ; SI: v_cvt_f32_f16_e32 [[CVT_A:v[0-9]+]], v{{[0-9]+}}
248248 ; SI: v_cvt_f32_f16_e32 [[CVT_B:v[0-9]+]], v{{[0-9]+}}
249249 ; SI: v_cvt_f32_f16_e32 [[CVT_C:v[0-9]+]], v{{[0-9]+}}
252252 ; VI-NOT: v_mac_f16
253253 ; VI: v_mad_f16 v{{[0-9]+}}, -v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]}}
254254 ; GCN: s_endpgm
255 define void @mac_f16_neg_b_unsafe_fp_math(
255 define void @mac_f16_neg_b_nsz_fp_math(
256256 half addrspace(1)* %r,
257257 half addrspace(1)* %a,
258258 half addrspace(1)* %b,
270270 ret void
271271 }
272272
273 ; GCN-LABEL: {{^}}mac_f16_neg_c_unsafe_fp_math:
273 ; GCN-LABEL: {{^}}mac_f16_neg_c_nsz_fp_math:
274274 ; SI: v_cvt_f32_f16_e32 [[CVT_A:v[0-9]+]], v{{[0-9]+}}
275275 ; SI: v_cvt_f32_f16_e32 [[CVT_B:v[0-9]+]], v{{[0-9]+}}
276276 ; SI: v_cvt_f32_f16_e32 [[CVT_C:v[0-9]+]], v{{[0-9]+}}
279279 ; VI-NOT: v_mac_f16
280280 ; VI: v_mad_f16 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}, -v{{[0-9]}}
281281 ; GCN: s_endpgm
282 define void @mac_f16_neg_c_unsafe_fp_math(
282 define void @mac_f16_neg_c_nsz_fp_math(
283283 half addrspace(1)* %r,
284284 half addrspace(1)* %a,
285285 half addrspace(1)* %b,
551551 ret void
552552 }
553553
554 ; GCN-LABEL: {{^}}mac_v2f16_neg_a_unsafe_fp_math:
554 ; GCN-LABEL: {{^}}mac_v2f16_neg_a_nsz_fp_math:
555555 ; SI: v_cvt_f32_f16_e32 [[CVT0:v[0-9]+]], {{v[0-9]+}}
556556 ; SI: v_cvt_f32_f16_e32 [[CVT1:v[0-9]+]], {{v[0-9]+}}
557557 ; SI: v_cvt_f32_f16_e32 [[CVT2:v[0-9]+]], {{v[0-9]+}}
566566 ; VI: v_mad_f16 v{{[0-9]+}}, -v{{[0-9]+}}, v{{[0-9]+}}, v{{[-0-9]}}
567567 ; VI: v_mad_f16 v{{[0-9]+}}, -v{{[0-9]+}}, v{{[0-9]+}}, v{{[-0-9]}}
568568 ; GCN: s_endpgm
569 define void @mac_v2f16_neg_a_unsafe_fp_math(
569 define void @mac_v2f16_neg_a_nsz_fp_math(
570570 <2 x half> addrspace(1)* %r,
571571 <2 x half> addrspace(1)* %a,
572572 <2 x half> addrspace(1)* %b,
584584 ret void
585585 }
586586
587 ; GCN-LABEL: {{^}}mac_v2f16_neg_b_unsafe_fp_math:
587 ; GCN-LABEL: {{^}}mac_v2f16_neg_b_nsz_fp_math:
588588 ; SI: v_cvt_f32_f16_e32 [[CVT0:v[0-9]+]], {{v[0-9]+}}
589589 ; SI: v_cvt_f32_f16_e32 [[CVT1:v[0-9]+]], {{v[0-9]+}}
590590 ; SI: v_cvt_f32_f16_e32 [[CVT2:v[0-9]+]], {{v[0-9]+}}
599599 ; VI: v_mad_f16 v{{[0-9]+}}, -v{{[0-9]+}}, v{{[0-9]+}}, v{{[-0-9]}}
600600 ; VI: v_mad_f16 v{{[0-9]+}}, -v{{[0-9]+}}, v{{[0-9]+}}, v{{[-0-9]}}
601601 ; GCN: s_endpgm
602 define void @mac_v2f16_neg_b_unsafe_fp_math(
602 define void @mac_v2f16_neg_b_nsz_fp_math(
603603 <2 x half> addrspace(1)* %r,
604604 <2 x half> addrspace(1)* %a,
605605 <2 x half> addrspace(1)* %b,
617617 ret void
618618 }
619619
620 ; GCN-LABEL: {{^}}mac_v2f16_neg_c_unsafe_fp_math:
620 ; GCN-LABEL: {{^}}mac_v2f16_neg_c_nsz_fp_math:
621621 ; SI: v_cvt_f32_f16_e32 [[CVT0:v[0-9]+]], {{v[0-9]+}}
622622 ; SI: v_cvt_f32_f16_e32 [[CVT1:v[0-9]+]], {{v[0-9]+}}
623623 ; SI: v_cvt_f32_f16_e32 [[CVT2:v[0-9]+]], {{v[0-9]+}}
632632 ; VI: v_mad_f16 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}, -v{{[-0-9]}}
633633 ; VI: v_mad_f16 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}, -v{{[-0-9]}}
634634 ; GCN: s_endpgm
635 define void @mac_v2f16_neg_c_unsafe_fp_math(
635 define void @mac_v2f16_neg_c_nsz_fp_math(
636636 <2 x half> addrspace(1)* %r,
637637 <2 x half> addrspace(1)* %a,
638638 <2 x half> addrspace(1)* %b,
650650 ret void
651651 }
652652
653 attributes #0 = { nounwind "unsafe-fp-math"="false" }
654 attributes #1 = { nounwind "unsafe-fp-math"="true" }
653 attributes #0 = { nounwind "no-signed-zeros-fp-math"="false" }
654 attributes #1 = { nounwind "no-signed-zeros-fp-math"="true" }
220220 ret <4 x float> %z
221221 }
222222
223 attributes #0 = { "less-precise-fpmad"="true" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "unsafe-fp-math"="true" }
223 attributes #0 = { "less-precise-fpmad"="true" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "unsafe-fp-math"="true" "no-signed-zeros-fp-math"="true" }
None ; RUN: llc < %s -enable-unsafe-fp-math -mtriple=x86_64-unknown-unknown -mcpu=corei7 | FileCheck %s
0 ; RUN: llc < %s -enable-unsafe-fp-math -enable-no-signed-zeros-fp-math -mtriple=x86_64-unknown-unknown -mcpu=corei7 | FileCheck %s
11
22 ; Make sure that vectors get the same benefits as scalars when using unsafe-fp-math.
33