[llvm] [InstCombine] Simplify and/or of icmp eq with op replacement (PR #70335)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 2 03:35:49 PDT 2023
nikic wrote:
@mikaelholmen Thank you! Here is a reduced version:
```llvm
declare void @barrier()
define i1 @test1(i32 %x) {
%cmp1 = icmp ne i32 %x, 0
call void @barrier()
%div = udiv i32 2147483647, %x
%cmp2 = icmp ugt i32 %x, %div
%or = or i1 %cmp1, %cmp2
ret i1 %or
}
```
What happens is that we try to evaluate `%cmp2` with `%x==0`, in which case the division is UB and folds to poison. We then fold `or` with a poison operand, resulting in an overall `poison` result.
Another slight variant of this would be:
```
define i1 @test2(i32 %x) {
%cmp1 = icmp ne i32 %x, 32
%shl = shl i32 1, %x
%cmp2 = icmp ugt i32 %x, %shl
%or = or i1 %cmp1, %cmp2
ret i1 %or
}
```
Same basic issue, but without UB involvement, just plain poison.
https://github.com/llvm/llvm-project/pull/70335
More information about the llvm-commits
mailing list