[llvm] e089261 - [SDAG] Extract commutative helper from haveNoCommonBitsSet() (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue May 3 03:28:44 PDT 2022


Author: Nikita Popov
Date: 2022-05-03T12:28:35+02:00
New Revision: e0892614b162f5f53aa44c88080d986649a50982

URL: https://github.com/llvm/llvm-project/commit/e0892614b162f5f53aa44c88080d986649a50982
DIFF: https://github.com/llvm/llvm-project/commit/e0892614b162f5f53aa44c88080d986649a50982.diff

LOG: [SDAG] Extract commutative helper from haveNoCommonBitsSet() (NFC)

To make it easier to add additional patterns, which will generally
want to handle commuted top-level operands.

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index d66798818706f..83c752b23ba00 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4684,10 +4684,7 @@ bool SelectionDAG::isEqualTo(SDValue A, SDValue B) const {
   return false;
 }
 
-// FIXME: unify with llvm::haveNoCommonBitsSet.
-bool SelectionDAG::haveNoCommonBitsSet(SDValue A, SDValue B) const {
-  assert(A.getValueType() == B.getValueType() &&
-         "Values must have the same type");
+static bool haveNoCommonBitsSetCommutative(SDValue A, SDValue B) {
   // Match masked merge pattern (X & ~M) op (Y & M)
   if (A->getOpcode() == ISD::AND && B->getOpcode() == ISD::AND) {
     auto MatchNoCommonBitsPattern = [&](SDValue NotM, SDValue And) {
@@ -4698,12 +4695,19 @@ bool SelectionDAG::haveNoCommonBitsSet(SDValue A, SDValue B) const {
       }
       return false;
     };
-    if (MatchNoCommonBitsPattern(A->getOperand(0), B) ||
-        MatchNoCommonBitsPattern(A->getOperand(1), B) ||
-        MatchNoCommonBitsPattern(B->getOperand(0), A) ||
-        MatchNoCommonBitsPattern(B->getOperand(1), A))
-      return true;
+    return MatchNoCommonBitsPattern(A->getOperand(0), B) ||
+           MatchNoCommonBitsPattern(A->getOperand(1), B);
   }
+  return false;
+}
+
+// FIXME: unify with llvm::haveNoCommonBitsSet.
+bool SelectionDAG::haveNoCommonBitsSet(SDValue A, SDValue B) const {
+  assert(A.getValueType() == B.getValueType() &&
+         "Values must have the same type");
+  if (haveNoCommonBitsSetCommutative(A, B) ||
+      haveNoCommonBitsSetCommutative(B, A))
+    return true;
   return KnownBits::haveNoCommonBitsSet(computeKnownBits(A),
                                         computeKnownBits(B));
 }


        


More information about the llvm-commits mailing list