https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101253
Bug ID: 101253
Summary: Optimize i % C1 == C0 || i % C1*C2 == C0 to i % C1 ==
C0
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: antoshkka at gmail dot com
Target Milestone: ---
Consider the following code
bool test_naive(short i) {
return i % 100 == 0 || i % 400 == 0;
}
It could be optimized into
bool test_optim(short i) {
return i % 100 == 0;
}
Godbolt playground: https://godbolt.org/z/zW49qcs7G
P.S.: Inspired by the manual optimizations in libstdc++
https://github.com/gcc-mirror/gcc/commit/b92d12d3fe3f1aa56d190d960e40c62869a6cfbb