| Issue |
243259
|
| Summary |
[InstCombine] Missed optimization: `((x & 1) + 9) >> 1` is not folded to `(x & 1) + 4`
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
Leo0506
|
InstCombine does not simplify the following function:
```llvm
define i32 @src(i32 %x) {
%a = and i32 %x, 1
%b = add nuw nsw i32 %a, 9
%c = lshr i32 %b, 1
ret i32 %c
}
```
`%a` is 0 or 1, so `%b` is 9 or 10 and `%c` is 4 or 5. That is `%a + 4`:
```llvm
define i32 @tgt(i32 %x) {
%a = and i32 %x, 1
%c = add nuw nsw i32 %a, 4
ret i32 %c
}
```
This saves one instruction. https://godbolt.org/z/5zbvzxefq
Alive2 proof: https://alive2.llvm.org/ce/z/_CB6nx
Trunk (`opt -O3`, LLVM 24.0.0git) leaves `@src` unchanged apart from adding `range(i32 4, 6)` to the return value.
It was found in Wireshark (`msg_dlmap.c`).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs