| #
5fe14667 |
| 15-Apr-2024 |
Yingwei Zheng <dtcxzyw2333@gmail.com> |
[InstCombine] Simplify switch with selects (#84143)
An example from https://github.com/image-rs/image:
```
define void @test_ult_rhsc(i8 %x) {
%val = add nsw i8 %x, -2
%cmp = icmp ult i8 %va
[InstCombine] Simplify switch with selects (#84143)
An example from https://github.com/image-rs/image:
```
define void @test_ult_rhsc(i8 %x) {
%val = add nsw i8 %x, -2
%cmp = icmp ult i8 %val, 11
%cond = select i1 %cmp, i8 %val, i8 6
switch i8 %cond, label %bb1 [
i8 0, label %bb2
i8 10, label %bb3
]
bb1:
call void @func1()
unreachable
bb2:
call void @func2()
unreachable
bb3:
call void @func3()
unreachable
}
```
When `%cmp` evaluates to false, we can prove that the range of `%val` is
[11, umax]. Thus we can safely replace `%cond` with `%val` since both
`switch 6` and `switch %val` go to the default dest `%bb1`.
Alive2: https://alive2.llvm.org/ce/z/uSTj6w
Godbolt: https://godbolt.org/z/MGrG84bzr
This patch will benefit many rust applications and some C/C++
applications (e.g., cvc5).
show more ...
|