[x86][AArch64] add tests for fmul-fma combine; NFC
authorSanjay Patel <spatel@rotateright.com>
Wed, 24 Jun 2020 19:54:22 +0000 (15:54 -0400)
committerSanjay Patel <spatel@rotateright.com>
Wed, 24 Jun 2020 19:56:32 +0000 (15:56 -0400)
As discussed in D80801, there's a possible overstep in
what is allowed by the 'contract' fast-math-flag.

llvm/test/CodeGen/AArch64/fadd-combines.ll
llvm/test/CodeGen/X86/fma_patterns.ll

index 61d0ecc..0e4f2c0 100644 (file)
@@ -207,6 +207,19 @@ define double @fadd_fma_fmul_1(double %a, double %b, double %c, double %d, doubl
   ret double %a2
 }
 
+define float @fadd_fma_fmul_fmf(float %a, float %b, float %c, float %d, float %n0) nounwind {
+; CHECK-LABEL: fadd_fma_fmul_fmf:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    fmadd s2, s2, s3, s4
+; CHECK-NEXT:    fmadd s0, s0, s1, s2
+; CHECK-NEXT:    ret
+  %m1 = fmul float %a, %b
+  %m2 = fmul float %c, %d
+  %a1 = fadd contract float %m1, %m2
+  %a2 = fadd reassoc float %n0, %a1
+  ret float %a2
+}
+
 ; Minimum FMF, commute final add operands, change type.
 
 define float @fadd_fma_fmul_2(float %a, float %b, float %c, float %d, float %n0) nounwind {
index a11ddf1..3049365 100644 (file)
@@ -1821,6 +1821,31 @@ define double @fadd_fma_fmul_1(double %a, double %b, double %c, double %d, doubl
   ret double %a2
 }
 
+define float @fadd_fma_fmul_fmf(float %a, float %b, float %c, float %d, float %n0) nounwind {
+; FMA-LABEL: fadd_fma_fmul_fmf:
+; FMA:       # %bb.0:
+; FMA-NEXT:    vfmadd213ss {{.*#+}} xmm2 = (xmm3 * xmm2) + xmm4
+; FMA-NEXT:    vfmadd213ss {{.*#+}} xmm0 = (xmm1 * xmm0) + xmm2
+; FMA-NEXT:    retq
+;
+; FMA4-LABEL: fadd_fma_fmul_fmf:
+; FMA4:       # %bb.0:
+; FMA4-NEXT:    vfmaddss {{.*#+}} xmm2 = (xmm2 * xmm3) + xmm4
+; FMA4-NEXT:    vfmaddss {{.*#+}} xmm0 = (xmm0 * xmm1) + xmm2
+; FMA4-NEXT:    retq
+;
+; AVX512-LABEL: fadd_fma_fmul_fmf:
+; AVX512:       # %bb.0:
+; AVX512-NEXT:    vfmadd213ss {{.*#+}} xmm2 = (xmm3 * xmm2) + xmm4
+; AVX512-NEXT:    vfmadd213ss {{.*#+}} xmm0 = (xmm1 * xmm0) + xmm2
+; AVX512-NEXT:    retq
+  %m1 = fmul float %a, %b
+  %m2 = fmul float %c, %d
+  %a1 = fadd contract float %m1, %m2
+  %a2 = fadd reassoc float %n0, %a1
+  ret float %a2
+}
+
 ; Minimum FMF, commute final add operands, change type.
 
 define float @fadd_fma_fmul_2(float %a, float %b, float %c, float %d, float %n0) nounwind {