On Tue, 2 Sep 2025, Jakub Jelinek wrote:

> On Tue, Sep 02, 2025 at 11:34:59AM +0200, Richard Biener wrote:
> > 
> > Oops, now also to the list.
> 
> If so, it needs to punt on anything that uses something more than once.
> So, alg_add_factor and alg_sub_factor are always bad (so return NULL),
> because they do use accumulator both in the PLUS/MINUS and LSHIFT.
> alg_add_t2_m/alg_sub_t2_m/alg_shift if synth_shift_p
> and alg.log[i], all in addition to what it has been doing before.

Like the following?

Thanks,
Richard.

>From 651c377e4f63ff234f034bfaa2633686203ed713 Mon Sep 17 00:00:00 2001
From: Richard Biener <rguent...@suse.de>
Date: Tue, 2 Sep 2025 10:16:28 +0200
Subject: [PATCH] tree-optimization/121753 - ICE with pattern breaking
 reduction constraints
To: gcc-patches@gcc.gnu.org

The recent change to vect_synth_mult_by_constant missed to handle
the synth_shift_p case for alg_shift, so we still changed c * 4
to c + c + c + c.  The following also amends alg_add_t2_m, alg_sub_t2_m,
alg_add_factor and alg_sub_factor appropriately.

        PR tree-optimization/121753
        * tree-vect-patterns.cc (vect_synth_mult_by_constant): Properly
        bail when synth_shift_p and an alg_shift use.  Handle other
        problematic cases.
---
 gcc/tree-vect-patterns.cc | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index 64a49cccc24..d0bf2f9e799 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -4329,7 +4329,14 @@ vect_synth_mult_by_constant (vec_info *vinfo, tree op, 
tree val,
          case alg_add_t2_m:
          case alg_sub_t2_m:
            op_uses++;
+           /* Fallthru.  */
+         case alg_shift:
+           if (synth_shift_p && alg.log[i])
+             return NULL;
            break;
+         case alg_add_factor:
+         case alg_sub_factor:
+           return NULL;
          default:
            break;
          }
-- 
2.43.0

Reply via email to