Issue |
83225
|
Summary |
[InstCombine] Missed optimization: fold select if the user of its select user indicates the condition
|
Labels |
|
Assignees |
|
Reporter |
XChy
|
Alive2 proof: https://alive2.llvm.org/ce/z/EDjfon
### Motivating example
```llvm
define i32 @src(i32 %a, i1 %c1, i1 %c2){
entry:
%s1 = select i1 %c1, i32 23, i32 45
%s2 = select i1 %c2, i32 666, i32 %s1
%s3 = select i1 %c1, i32 789, i32 %s2
ret i32 %s3
}
```
can be folded to:
```llvm
define i32 @tgt(i32 %a, i1 %c1, i1 %c2){
entry:
%s2 = select i1 %c2, i32 666, i32 45
%s3 = select i1 %c1, i32 789, i32 %s2
ret i32 %s3
}
```
### Real-world motivation
This snippet of IR is derived from [libdeflate/lib/crc32.c@dispatch_crc32](https://github.com/ebiggers/libdeflate/blob/e93127b7e85d8dc65a80ed0ad4883c4b3efbe813/lib/crc32.c#L241) (after O3 pipeline, original IR comes from [llvm-opt-benchmark](https://github.com/dtcxzyw/llvm-opt-benchmark)).
The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, see also:https://godbolt.org/z/rjf9zWM81
**Let me know if you can confirm that it's an optimization opportunity, thanks.**
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs