Issue 207987
Summary x86_64 Conditional increment on non-carry non-overflow => speculative increment+cmov
Labels
Assignees
Reporter Validark
    [C Godbolt](https://c.godbo.lt/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,selection:(endColumn:1,endLineNumber:2,positionColumn:1,positionLineNumber:2,selectionStartColumn:1,selectionStartLineNumber:2,startColumn:1,startLineNumber:2),source:'%23include+%3Cstdint.h%3E%0Auint64_t+foo(uint64_t+a,+uint64_t+b)+%7B%0A++++return+a+%2B+((b+%26+63)+!!%3D+0)%3B%0A%7D%0A'),l:'5',n:'0',o:'C+source+%231',t:'0')),k:48.46943717911461,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:cclang_trunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,libs:!(),options:'-O3+-march%3Dznver5',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+x86-64+clang+(trunk)+(Editor+%231)',t:'0')),k:51.53056282088541,l:'4',m:100,n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)

```c
#include <stdint.h>
uint64_t foo(uint64_t a, uint64_t b) {
    return a + ((b & 63) != 0);
}
```

Compiles to:

```asm
foo:
        and     esi, 63
 mov     rax, rdi
        cmp     rsi, 1
        sbb     rax, -1
 ret
```

Could be:

```asm
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
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to