[llvm] Fujun.han/instcombine or to xor (PR #75129)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 11 18:52:57 PST 2023


================
@@ -3343,6 +3343,27 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
   if (Instruction *X = foldComplexAndOrPatterns(I, Builder))
     return X;
 
+  // Change (or (and (add x, half_c1), c3), (and x, c2)) to (xor x, half_c1),
+  // iff c1, c2, c3 is constant, and half_c1 = (lshr c1, 1),  and c1 is pow2,
+  // and c2 < c1, and c3 == (c1 - 1) ^ c2, and (c1 >> 1) & c3 == (c1 >> 1) and x
+  // is known to be less than c1.
+  Type *Ty = I.getType();
+  if (Ty->isIntegerTy()) {
----------------
dtcxzyw wrote:

It also holds for vectors.
```suggestion
  
```

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


More information about the llvm-commits mailing list