]> git.ipfire.org Git - thirdparty/gcc.git/commit
tree-optimization/120687 - reduction chain with UB on signed overflow
authorRichard Biener <rguenther@suse.de>
Mon, 20 Oct 2025 12:44:27 +0000 (14:44 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 21 Oct 2025 11:19:04 +0000 (13:19 +0200)
commit40d6dbf0f8dd91db5e4c13187fc341cdef40b054
tree58b04536c6b5f02d5a0283cb1115f24de081989d
parent6588bfab5c13fb4c3e47dd7e1a1aab86c9b70308
tree-optimization/120687 - reduction chain with UB on signed overflow

The following adds the ability to discover a reduction chain on a
series of statements that invoke undefined behavior on integer overflow.
This inhibits the reassoc pass from associating stmts in the way
naturally leading to a reduction chain.  The common mistake on the
source side is to rely on the += operator to sum multiple inputs.

After the refactoring of how we handle reduction chains we can
easily use vect_slp_linearize_chain to do this our selves and
rely on the vectorizer punning operations to unsigned given reduction
vectorization always associates.

PR tree-optimization/120687
* tree-vect-slp.cc (vect_analyze_slp_reduc_chain): When
there's no natural reduction chain see if vect_slp_linearize_chain
can recover one and built the SLP instance manually in that
case.
(vect_schedule_slp): Deal with NULL lanes when looking for
stores to remove.
* tree-vect-loop.cc (vect_transform_cycle_phi): Dump when we
are successfully transforming a reduction chain.

* gcc.dg/vect/vect-reduc-chain-4.c: New testcase.
gcc/testsuite/gcc.dg/vect/vect-reduc-chain-4.c [new file with mode: 0644]
gcc/tree-vect-loop.cc
gcc/tree-vect-slp.cc