From 9c8188bd137855350640147889a7b2fabcfb042f Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Thu, 3 Jul 2025 13:14:46 +0100 Subject: [PATCH] [X86] commuteSelect - update to use SDPatternMatch. NFC. --- llvm/lib/Target/X86/X86ISelLowering.cpp | 27 ++++++++++--------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index feafdc909332c..f5d8d65070a3b 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -47568,31 +47568,26 @@ static SDValue combineLogicBlendIntoConditionalNegate( static SDValue commuteSelect(SDNode *N, SelectionDAG &DAG, const SDLoc &DL, const X86Subtarget &Subtarget) { + using namespace SDPatternMatch; if (!Subtarget.hasAVX512()) return SDValue(); - if (N->getOpcode() != ISD::VSELECT) - return SDValue(); - - SDValue Cond = N->getOperand(0); - SDValue LHS = N->getOperand(1); - SDValue RHS = N->getOperand(2); - - if (canCombineAsMaskOperation(LHS, Subtarget)) - return SDValue(); - if (!canCombineAsMaskOperation(RHS, Subtarget)) + ISD::CondCode CC; + SDValue Cond, X, Y, LHS, RHS; + if (!sd_match(N, m_VSelect(m_AllOf(m_Value(Cond), + m_OneUse(m_SetCC(m_Value(X), m_Value(Y), + m_CondCode(CC)))), + m_Value(LHS), m_Value(RHS)))) return SDValue(); - if (Cond.getOpcode() != ISD::SETCC || !Cond.hasOneUse()) + if (canCombineAsMaskOperation(LHS, Subtarget) || + !canCombineAsMaskOperation(RHS, Subtarget)) return SDValue(); // Commute LHS and RHS to create opportunity to select mask instruction. // (vselect M, L, R) -> (vselect ~M, R, L) - ISD::CondCode NewCC = - ISD::getSetCCInverse(cast(Cond.getOperand(2))->get(), - Cond.getOperand(0).getValueType()); - Cond = DAG.getSetCC(SDLoc(Cond), Cond.getValueType(), Cond.getOperand(0), - Cond.getOperand(1), NewCC); + ISD::CondCode NewCC = ISD::getSetCCInverse(CC, X.getValueType()); + Cond = DAG.getSetCC(SDLoc(Cond), Cond.getValueType(), X, Y, NewCC); return DAG.getSelect(DL, LHS.getValueType(), Cond, RHS, LHS); }