[Bug c/96753] New: Missed optimization [x86-64] on modulo when left side value is known to be greater than right side value
goldstein.w.n at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sun Aug 23 22:00:36 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96753
Bug ID: 96753
Summary: Missed optimization [x86-64] on modulo when left side
value is known to be greater than right side value
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: goldstein.w.n at gmail dot com
Target Milestone: ---
uint64_t
do_mod(uint64_t x, uint64_t y) {
if(x >= y) {
__builtin_unreachable();
}
return x % y;
}
With -O3 compiles to
do_mod(unsigned long, unsigned long):
movq %rdi, %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %rax
ret
given that x is known to be less than y this could be return x;
Godbolt link: https://gcc.godbolt.org/z/sfhr96
More information about the Gcc-bugs
mailing list