Issue 142513
Summary [X86] 64-bit constant compiled to `movabs`+`add` after branch
Labels new issue
Assignees
Reporter dzaima
    https://c.godbolt.org/z/GEb9G3bMq

This C code, compiled with `-O3`:

```c
#include <inttypes.h>
#include <stdlib.h>
uint64_t foo(uint64_t x) {
    if (x >> 47 == 0xffe5) { // equivalent to (x & 0xffff800000000000) == 0x7ff2800000000000
 abort();
    }
    return 0x7ff2800000000003;
}
```

produces:
```asm
foo:
        shr     rdi, 47
        cmp     edi, 65509
        je      .LBB0_2
        movabs  rax, 9219572124669181952 ; 0x7ff2800000000000
        add     rax, 3
 ret
.LBB0_2:
        push    rax
        call    abort@PLT
```
where the `movabs` + `add` could trivially be just `movabs  rax, 9219572124669181955`, as the `movabs` ends up being used only here.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to