]> git.ipfire.org Git - thirdparty/gcc.git/commit
tree-optimization/112344 - wrong final value replacement
authorRichard Biener <rguenther@suse.de>
Wed, 22 Nov 2023 10:10:41 +0000 (11:10 +0100)
committerRichard Biener <rguenther@suse.de>
Wed, 22 Nov 2023 14:37:14 +0000 (15:37 +0100)
commit6bf66276e3e41d5d92f7b7260e98b6a111653805
treee65612606d8a42214f5f2f78cf8385f0848d9b08
parentecb22ddbe2b676484d04e7979f7991f7eec93470
tree-optimization/112344 - wrong final value replacement

When performing final value replacement chrec_apply that's used to
compute the overall effect of niters to a CHREC doesn't consider that
the overall increment of { -2147483648, +, 2 } doesn't fit in
a signed integer when the loop iterates until the value of the IV
of 20.  The following fixes this mistake, carrying out the multiply
and add in an unsigned type instead, avoiding undefined overflow
and thus later miscompilation by path range analysis.

PR tree-optimization/112344
* tree-chrec.cc (chrec_apply): Perform the overall increment
calculation and increment in an unsigned type.

* gcc.dg/torture/pr112344.c: New testcase.
gcc/testsuite/gcc.dg/torture/pr112344.c [new file with mode: 0644]
gcc/tree-chrec.cc