https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109044

            Bug ID: 109044
           Summary: Missed fold for (n - 1) / 2 when n is odd
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: llvm at rifkin dot dev
  Target Milestone: ---

int foo(unsigned n) {
    if(n % 2 == 0) __builtin_unreachable();
    return (n - 1) / 2;
}

int bar(unsigned n) {
    return n >> 1;
}



foo(unsigned int):
        lea     eax, [rdi-1]
        shr     eax
        ret
bar(unsigned int):
        mov     eax, edi
        shr     eax
        ret


https://godbolt.org/z/3G7enYdnM

https://alive2.llvm.org/ce/z/m3qbdN

Reply via email to