Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CondCodeSDNode>(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);
}

Expand Down
Loading