missed optimization: ((x ^ mask) >> n) ^ mask to arithmetic shift
Open
@GabrielKimm is already working on this.
Since Jul 25, 2026.
llvm:instcombine
missed-optimization
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
https://godbolt.org/z/P3dhcarEd
https://alive2.llvm.org/ce/z/_sSp6K
uint32_t asr(uint32_t x, int n) {
return ((x ^ -(x >> 31)) >> n) ^ -(x >> 31);
}
define i32 @src(i32 %1, i32 %2) {
%4 = ashr i32 %1, 31
%5 = xor i32 %1, %4
%6 = lshr i32 %5, %2
%7 = xor i32 %6, %4
ret i32 %7
}
Expected:
define i32 @tgt(i32 %1, i32 %2) {
%4 = ashr i32 %1, %2
ret i32 %4
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.