[Bug tree-optimization/86136] New: Modular multiplication optimization
mcccs at gmx dot com
gcc-bugzilla@gcc.gnu.org
Wed Jun 13 14:58:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86136
Bug ID: 86136
Summary: Modular multiplication optimization
Product: gcc
Version: 9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: mcccs at gmx dot com
Target Milestone: ---
Optimization: Ofast
GCC can't see that
(a * n) % k = (a * (n % k)) % k
(even) when n is known at compile time.
As a result,
int k (int a) {
return (a * t) % 5;
}
always gives a different assembly for t = 1, 2, ...
you can also replace 5 with any number
Play with it here: https://godbolt.org/g/HkyHqg
Clang has this bug too.
More information about the Gcc-bugs
mailing list