llvm / llvm/llvm-project

[missed-opt] [isel] Unnecessary shift count masking in 128-bit arithmetic

Open
#171,920 16 comments 0 reactions 0 assignees View on GitHub
backend:X86 missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

[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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.