--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -ffp-contract=off -mavx2 -mfma" } */
+
+void cscal(int n, float da_r, float *x)
+{
+ for (int i = 0; i < n; i += 4)
+ {
+ float temp0 = da_r * x[i] - x[i+1];
+ float temp1 = da_r * x[i+2] - x[i+3];
+ x[i+1] = da_r * x[i+1] + x[i];
+ x[i+3] = da_r * x[i+3] + x[i+2];
+ x[i] = temp0;
+ x[i+2] = temp1;
+ }
+}
+
+/* { dg-final { scan-assembler-not "fma" } } */
auto_vec<slp_tree> left_op, right_op;
slp_tree add0 = NULL;
- /* Check if we may be a multiply add. */
+ /* Check if we may be a multiply add. It's only valid to form FMAs
+ with -ffp-contract=fast. */
if (!mul0
+ && (flag_fp_contract_mode == FP_CONTRACT_FAST
+ || !FLOAT_TYPE_P (SLP_TREE_VECTYPE (l0node[0])))
&& vect_match_expression_p (l0node[0], PLUS_EXPR))
{
auto vals = SLP_TREE_CHILDREN (l0node[0]);
}
/* Now we have either { -, +, -, + ... } (!l0add_p) or { +, -, +, - ... }
- (l0add_p), see whether we have FMA variants. */
- if (!l0add_p
- && vect_match_expression_p (SLP_TREE_CHILDREN (l0node)[0], MULT_EXPR))
+ (l0add_p), see whether we have FMA variants. We can only form FMAs
+ if allowed via -ffp-contract=fast. */
+ if (flag_fp_contract_mode != FP_CONTRACT_FAST
+ && FLOAT_TYPE_P (SLP_TREE_VECTYPE (l0node)))
+ ;
+ else if (!l0add_p
+ && vect_match_expression_p (SLP_TREE_CHILDREN (l0node)[0], MULT_EXPR))
{
/* (c * d) -+ a */
if (vect_pattern_validate_optab (IFN_VEC_FMADDSUB, node))