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

            Bug ID: 126151
           Summary: [x86-64] Conditional increment on non-carry
                    non-overflow => speculative increment+cmov
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kaelfandrew at gmail dot com
  Target Milestone: ---

Created attachment 64955
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64955&action=edit
C code

https://godbolt.org/z/jYzjK1r3c

With -O3:

x86 current assembly:
"foo":
        and     esi, 63
        mov     rax, rdi
        cmp     rsi, 1
        sbb     rax, -1
        ret

x86 better assembly:
foo:
        lea     rax, [rdi + 1]   ; speculative a + 1
        test    esi, 63          ; ZF = 1 iff (idx & 63) == 0  
(non-destructive)
        cmovz   rax, rdi         ; if zero, take the un-incremented a
        ret

Reply via email to