[llvm] [InstCombine] Simplify and/or by replacing operands with constants (PR #77231)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 22 06:22:46 PST 2024


================
@@ -2179,6 +2179,57 @@ foldBitwiseLogicWithIntrinsics(BinaryOperator &I,
   }
 }
 
+// Try to simplify X | Y by replacing occurrences of Y in X with 0.
+// Similarly, simplify X & Y by replacing occurrences of Y in X with -1.
+// Return the simplified result of X if successful, and nullptr otherwise.
+static Value *simplifyAndOrWithOpReplaced(Value *X, Value *Y, bool IsAnd,
+                                          InstCombinerImpl &IC,
+                                          unsigned Depth = 0) {
+  if (isa<Constant>(X) || X == Y)
+    return nullptr;
+
+  auto RecursivelyReplaceUses = [&](Instruction::BinaryOps Opcode, Value *Op0,
+                                    Value *Op1) -> Value * {
----------------
nikic wrote:

Used only in one place, so you could inline it.

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


More information about the llvm-commits mailing list