[llvm] [InstSimplify] Simplify select if it combinated `and/or/xor` (PR #73362)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 10 01:17:09 PST 2024


================
@@ -4425,6 +4425,61 @@ Value *llvm::simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
                                   RecursionLimit);
 }
 
+/// Try simplifying the selection command when condition, trueValue, and
+/// falseValue are combinations of special bitwise operators.
+static Value *simplifySelectBitTestSpec(Value *CmpLHS, Value *CmpRHS,
+                                        Value *TrueVal, Value *FalseVal) {
+  Value *X, *Y;
+  // (X & Y) == 0 ? X | Y : X ^ Y   --> X ^ Y
+  // (X & Y) == 0 ? X ^ Y : X | Y   --> X | Y
+  // (X & Y) != 0 ? X | Y : X ^ Y   --> X | Y
+  // (X & Y) != 0 ? X ^ Y : X | Y   --> X ^ Y
+  if (match(CmpLHS, m_c_And(m_Value(X), m_Value(Y))) &&
+      match(CmpRHS, m_Zero())) {
+    if (match(TrueVal, m_c_Or(m_Specific(X), m_Specific(Y))) &&
+        match(FalseVal, m_c_Xor(m_Specific(X), m_Specific(Y)))) {
+      return FalseVal;
+    } else if (match(FalseVal, m_c_Or(m_Specific(X), m_Specific(Y))) &&
+               match(TrueVal, m_c_Xor(m_Specific(X), m_Specific(Y)))) {
+      return FalseVal;
+    }
----------------
ParkHanbum wrote:

@goldsteinn would you give a time for me a moment? :smiling_face_with_tear: 

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


More information about the llvm-commits mailing list