From: Richard Biener Date: Wed, 27 Aug 2025 12:40:37 +0000 (+0200) Subject: Avoid mult pattern if that will break reduction constraints X-Git-Tag: basepoints/gcc-17~5376 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fa03e49399a8b202b7d6700604c8fbe5ee33474f;p=thirdparty%2Fgcc.git Avoid mult pattern if that will break reduction constraints synth-mult introduces multiple uses of a reduction variable in some cases which will ultimatively fail vectorization (or ICE with a pending change). So avoid applying the pattern in such case. * tree-vect-patterns.cc (vect_synth_mult_by_constant): Avoid in cases that introduce multiple uses of reduction operands. Co-authored-by: Jakub Jelinek --- diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc index 3fffcac4b3a..65704e5f338 100644 --- a/gcc/tree-vect-patterns.cc +++ b/gcc/tree-vect-patterns.cc @@ -4314,6 +4314,35 @@ vect_synth_mult_by_constant (vec_info *vinfo, tree op, tree val, if (!possible) return NULL; + if (vect_is_reduction (stmt_vinfo)) + { + int op_uses = alg.op[0] != alg_zero; + for (int i = 1; i < alg.ops; i++) + switch (alg.op[i]) + { + case alg_add_t_m2: + case alg_sub_t_m2: + if (synth_shift_p && alg.log[i]) + return NULL; + else + op_uses++; + break; + case alg_add_t2_m: + case alg_sub_t2_m: + op_uses++; + break; + default: + break; + } + if (variant == add_variant) + op_uses++; + /* When we'll synthesize more than a single use of the reduction + operand the reduction constraints are violated. Avoid this + situation. */ + if (op_uses > 1) + return NULL; + } + if (!target_supports_mult_synth_alg (&alg, variant, vectype, synth_shift_p)) return NULL;