From e0892614b162f5f53aa44c88080d986649a50982 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 3 May 2022 12:20:04 +0200 Subject: [PATCH] [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. --- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index d667988..83c752b2 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)); } -- 2.7.4