| Issue |
234717
|
| Summary |
[InstCombine] Missed XOR fold for (x != C) & ((x & 1) == 0) with even C
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
mariiakrasniuk
|
InstCombine misses a simplification of `(x != C) && ((x & 1) == 0)` for even constants `C`.
**Original IR:**
```llvm
define i1 @src(i32 %x) {
%ne = icmp ne i32 %x, 4
%a = and i32 %x, 1
%c = icmp eq i32 %a, 0
%r = and i1 %ne, %c
ret i1 %r
}
```
**Expected optimization:**
```llvm
define i1 @tgt(i32 %x) {
%ne = icmp ne i32 %x, 4
%t = trunc i32 %x to i1
%r = xor i1 %ne, %t
ret i1 %r
}
```
For even `C`, `x == C` implies that the low bit of `x` is zero, making the XOR equivalent to the original _expression_.
**Interestingly, the fold already exists.** When the parity check is written as:
```llvm
%t = trunc i32 %x to i1
%c = icmp eq i1 %t, 0
%r = and i1 %ne, %c
```
InstCombine successfully produces the expected XOR.
**Verification:**
- [[Alive2 transformation correct](https://alive2.llvm.org/ce/z/ohsswr)](https://alive2.llvm.org/ce/z/ohsswr)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs