]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Avoid mult pattern if that will break reduction constraints
authorRichard Biener <rguenther@suse.de>
Wed, 27 Aug 2025 12:40:37 +0000 (14:40 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 28 Aug 2025 08:30:18 +0000 (10:30 +0200)
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 <jakub@redhat.com>
gcc/tree-vect-patterns.cc

index 3fffcac4b3aa35d5da6924c8789dd79b5848e74a..65704e5f338c8fd072d724661db51b267b546cbb 100644 (file)
@@ -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;