+
+; (fma x, c1, (fmul x, c2)) -> (fmul x, c1+c2)
+
+define <4 x float> @test_v4f32_fma_x_c1_fmul_x_c2(<4 x float> %x) #0 {
+; ALL-LABEL: test_v4f32_fma_x_c1_fmul_x_c2:
+; ALL: # BB#0:
+; ALL-NEXT: vmulps {{.*}}(%rip), %xmm0, %xmm0
+; ALL-NEXT: retq
+ %m0 = fmul <4 x float> %x, <float 1.0, float 2.0, float 3.0, float 4.0>
+ %m1 = fmul <4 x float> %x, <float 4.0, float 3.0, float 2.0, float 1.0>
+ %a = fadd <4 x float> %m0, %m1
+ ret <4 x float> %a
+}
+
+; (fma (fmul x, c1), c2, y) -> (fma x, c1*c2, y)
+
+define <4 x float> @test_v4f32_fma_fmul_x_c1_c2_y(<4 x float> %x, <4 x float> %y) #0 {
+; CHECK_FMA-LABEL: test_v4f32_fma_fmul_x_c1_c2_y:
+; CHECK_FMA: # BB#0:
+; CHECK_FMA-NEXT: vmovaps {{.*#+}} xmm2 = [4.000000e+00,6.000000e+00,6.000000e+00,4.000000e+00]
+; CHECK_FMA-NEXT: vfmadd213ps %xmm1, %xmm2, %xmm0
+; CHECK_FMA-NEXT: retq
+;
+; CHECK_FMA4-LABEL: test_v4f32_fma_fmul_x_c1_c2_y:
+; CHECK_FMA4: # BB#0:
+; CHECK_FMA4-NEXT: vfmaddps %xmm1, {{.*}}(%rip), %xmm0, %xmm0
+; CHECK_FMA4-NEXT: retq
+ %m0 = fmul <4 x float> %x, <float 1.0, float 2.0, float 3.0, float 4.0>
+ %m1 = fmul <4 x float> %m0, <float 4.0, float 3.0, float 2.0, float 1.0>
+ %a = fadd <4 x float> %m1, %y
+ ret <4 x float> %a
+}
+
+attributes #0 = { "unsafe-fp-math"="true" }