Issue 131457
Summary [AArch64] Opportunity to materialise constants using `sub 0, imm, lsl 12`
Labels backend:AArch64, llvm:optimizations, missed-optimization
Assignees
Reporter Kmeakin
    Instead of materialising `-(4095 << 12)` with a MOVZ+MOVK pair, it can be done in a single instruction by subtracting from the zero register:

```c
uint32_t src32(uint32_t x) { return 0 - (4095 << 12); }
uint32_t tgt32(uint32_t x) { return x - (4095 << 12); }

uint64_t src64(uint64_t x) { return 0 - (4095 << 12); }
uint64_t tgt64(uint64_t x) { return x - (4095 << 12); }
```

```asm
src32:
        mov     w0, #4096
        movk    w0, #65280, lsl #16
        ret

tgt32:
        sub     w0, w0, #4095, lsl #12
        ret

src64:
        mov     x0, #-61440
        movk    x0, #65280, lsl #16
        ret

tgt64:
        sub     x0, x0, #4095, lsl #12
        ret
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to