[llvm] [InstCombine] fold `(a == c && b != c) || (a != c && b == c))` to `(a == c) == (b != c)` (PR #94915)

Zain Jaffal via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 21 16:07:25 PDT 2024


================
@@ -3476,7 +3469,7 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
   if (Instruction *X = foldComplexAndOrPatterns(I, Builder))
     return X;
 
-  // (A == c & B != d) | (A != c & B == d)) -> (A == c) | (B == d)
+  // (A == c & B != d) | (A != c & B == d)) -> (A == c) ^ (B == d)
----------------
zjaffal wrote:

removing it made the following test fail 
```
define i32 @and_to_xor4(i32 %a, i32 %b) {
; CHECK-LABEL: @and_to_xor4(
; CHECK-NEXT:    [[AND2:%.*]] = xor i32 [[B:%.*]], [[A:%.*]]
; CHECK-NEXT:    ret i32 [[AND2]]
;
  %or = or i32 %b, %a
  %and = and i32 %a, %b
  %not = xor i32 %and, -1
  %and2 = and i32 %not, %or
  ret i32 %and2
}

```

probably I need to move where I call my function to be called there as well so I make sure any negations are pushed inside 

https://github.com/llvm/llvm-project/pull/94915


More information about the llvm-commits mailing list