https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104766
Bug ID: 104766
Summary: (a * even_cst) & CST does not remove the lower bit
from the CST
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
auto g(unsigned long x) {
return (x * 6) % 4096;
}
auto g1(unsigned long x) {
auto x1 = x * 6;
return x1 % 4096;
}
----- CUT ----
These two would expect to produce the same results at -O2 but currently does
not.
What we get is:
g(unsigned long):
lea rax, [rdi+rdi*2]
add rax, rax
and eax, 4094
ret
g1(unsigned long):
lea rax, [rdi+rdi*2]
add rax, rax
and eax, 4095
ret
Notice 4095 vs 4094.