]> git.ipfire.org Git - thirdparty/gcc.git/commit
tree-optimization/114074 - CHREC multiplication and undefined overflow
authorRichard Biener <rguenther@suse.de>
Mon, 26 Feb 2024 12:33:21 +0000 (13:33 +0100)
committerRichard Biener <rguenther@suse.de>
Tue, 27 Feb 2024 09:54:56 +0000 (10:54 +0100)
commita0b1798042d033fd2cc2c806afbb77875dd2909b
treed0ab495e1bc7966c45c330384ea800d5c8c3983a
parentc3c44c01d20b00ab5228f32596153b7f4cbc6036
tree-optimization/114074 - CHREC multiplication and undefined overflow

When folding a multiply CHRECs are handled like {a, +, b} * c
is {a*c, +, b*c} but that isn't generally correct when overflow
invokes undefined behavior.  The following uses unsigned arithmetic
unless either a is zero or a and b have the same sign.

I've used simple early outs for INTEGER_CSTs and otherwise use
a range-query since we lack a tree_expr_nonpositive_p and
get_range_pos_neg isn't a good fit.

PR tree-optimization/114074
* tree-chrec.h (chrec_convert_rhs): Default at_stmt arg to NULL.
* tree-chrec.cc (chrec_fold_multiply): Canonicalize inputs.
Handle poly vs. non-poly multiplication correctly with respect
to undefined behavior on overflow.

* gcc.dg/torture/pr114074.c: New testcase.
* gcc.dg/pr68317.c: Adjust expected location of diagnostic.
* gcc.dg/vect/vect-early-break_119-pr114068.c: Do not expect
loop to be vectorized.
gcc/testsuite/gcc.dg/pr68317.c
gcc/testsuite/gcc.dg/torture/pr114074.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-early-break_119-pr114068.c
gcc/tree-chrec.cc
gcc/tree-chrec.h