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