[Bug tree-optimization/97997] Missed optimization: Multiply of extended integer cannot overflow
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97997 Andrew Pinski changed: What|Removed |Added Target Milestone|--- |11.0 Keywords||missed-optimization Severity|normal |enhancement
[Bug tree-optimization/97997] Missed optimization: Multiply of extended integer cannot overflow
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97997 --- Comment #5 from Matthijs Kooijman --- Awesome, thanks for the quick response and fix!
[Bug tree-optimization/97997] Missed optimization: Multiply of extended integer cannot overflow
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97997 Jakub Jelinek changed: What|Removed |Added Resolution|--- |FIXED Status|ASSIGNED|RESOLVED --- Comment #4 from Jakub Jelinek --- Fixed for 11.1+.
[Bug tree-optimization/97997] Missed optimization: Multiply of extended integer cannot overflow
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97997 --- Comment #3 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:a3ebc13492ff238873f2c6a7a3e51abefec1d052 commit r11-5444-ga3ebc13492ff238873f2c6a7a3e51abefec1d052 Author: Jakub Jelinek Date: Thu Nov 26 16:24:07 2020 +0100 match.pd: Use ranges to optimize some x * y / y to x [PR97997] For signed integers with undefined overflow we already optimize x * y / y into x, but for signed integers with -fwrapv or unsigned integers we don't. The following patch allows optimizing that into just x if value ranges prove that x * y will never overflow. It uses the global SSA_NAME_RANGE_INFO only, because like mentioned in another PR we don't currently have a way to tell the ranger from match.pd the use stmt (and we'd need in that case to tell ranger to only follow SSA_NAME_DEF_STMTs + SSA_NAME_RANGE_INFO and never go in the other direction, as following immediate uses seems forbidden in match.pd). Another possibility would be to optimize this during vrp, but on the other side the optimization itself is match.pd-ish. 2020-11-26 Jakub Jelinek PR tree-optimization/97997 * match.pd ((t * 2) / 2) -> t): Optimize even for defined overflow if ranges prove there is no overflow. * gcc.dg/tree-ssa/pr97997-1.c: New test. * gcc.dg/tree-ssa/pr97997-2.c: New test.
[Bug tree-optimization/97997] Missed optimization: Multiply of extended integer cannot overflow
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97997 Jakub Jelinek changed: What|Removed |Added Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org Ever confirmed|0 |1 Status|UNCONFIRMED |ASSIGNED Last reconfirmed||2020-11-25 --- Comment #2 from Jakub Jelinek --- Created attachment 49629 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49629=edit gcc11-pr97997.patch Untested fix.
[Bug tree-optimization/97997] Missed optimization: Multiply of extended integer cannot overflow
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97997 Jakub Jelinek changed: What|Removed |Added CC||jakub at gcc dot gnu.org --- Comment #1 from Jakub Jelinek --- unsigned short f1 (unsigned short x) { return x * 10 / 10; } unsigned short f2 (unsigned short x) { int a = x; int b = 10; int c = 10; return a * b / c; } unsigned short f3 (unsigned short x) { return x * 10U / 10; } unsigned short f4 (unsigned short x) { unsigned a = x; unsigned b = 10; unsigned c = 10; return a * b / c; } For f1 we fold it already during generic folding, f2 we fold during ccp using the /* Simplify (t * 2) / 2) -> t. */ (for div (trunc_div ceil_div floor_div round_div exact_div) (simplify (div (mult:c @0 @1) @1) (if (ANY_INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_UNDEFINED (type)) @0))) rule.