https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126311
Bug ID: 126311
Summary: (t * u) / v can be reduced if gcd (u, v) > 1
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: kaelfandrew at gmail dot com
Target Milestone: ---
https://godbolt.org/z/hzxdP9EEP
```
int
src (short tt)
{
int t = tt;
return (t * (2 * 3)) / (2 * 5);
}
int
tgt (short tt)
{
int t = tt;
return (t * 3) / 5;
}
```
With -O2, src () should optimize to tgt ()
gcc/match.pd has this pattern to implement this PR:
/* Simplify (t * u) / v -> t * (u / v) if u is multiple of v. */
(simplify
(div (mult@3 @0 INTEGER_CST@1) INTEGER_CST@2)
(if (INTEGRAL_TYPE_P (type)