Issue 171920
Summary [missed-opt] [isel] Unnecessary shift count masking in 128-bit arithmetic
Labels new issue
Assignees
Reporter purplesyringa
    [Godbolt](https://godbolt.org/z/WeWG3x1TM)

```cpp
__uint128_t shift(unsigned long x, unsigned long n) {
    return (__uint128_t)x << (n & 63);
}
```

```asm
; x86-64
shift(unsigned long, unsigned long):
 mov     rcx, rsi
        mov     rax, rdi
        shl     rax, cl
 shr     rdi
        and     cl, 63 ; unnecessary
        not     cl
 shr     rdi, cl
        mov     rdx, rdi
        ret
```

```asm
; aarch64
shift(unsigned long, unsigned long):
        and     x8, x1, #0x3f ; unnecessary
        lsr     x9, x0, #1
        lsl     x0, x0, x1
 eor     x8, x8, #0x3f
        lsr     x1, x9, x8
        ret
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to