@@ -2476,28 +2476,29 @@ static bool canFoldInAddressingMode(SDNode *N, SDNode *Use, SelectionDAG &DAG,
24762476/// masked vector operation if the target supports it.
24772477static SDValue foldSelectWithIdentityConstant(SDNode *N, SelectionDAG &DAG,
24782478 bool ShouldCommuteOperands) {
2479- // Match a select as operand 1. The identity constant that we are looking for
2480- // is only valid as operand 1 of a non-commutative binop.
24812479 SDValue N0 = N->getOperand(0);
24822480 SDValue N1 = N->getOperand(1);
2481+
2482+ // Match a select as operand 1. The identity constant that we are looking for
2483+ // is only valid as operand 1 of a non-commutative binop.
24832484 if (ShouldCommuteOperands)
24842485 std::swap(N0, N1);
24852486
2486- unsigned SelOpcode = N1.getOpcode();
2487- if ((SelOpcode != ISD::VSELECT && SelOpcode != ISD::SELECT) ||
2488- !N1.hasOneUse())
2487+ SDValue Cond, TVal, FVal;
2488+ if (!sd_match(N1,
2489+ m_SelectLike(m_Value(Cond), m_Value(TVal), m_Value(FVal))) ||
2490+ !N1->hasOneUse()) {
24892491 return SDValue();
2492+ }
24902493
24912494 // We can't hoist all instructions because of immediate UB (not speculatable).
24922495 // For example div/rem by zero.
24932496 if (!DAG.isSafeToSpeculativelyExecuteNode(N))
24942497 return SDValue();
24952498
2499+ unsigned SelOpcode = N1.getOpcode();
24962500 unsigned Opcode = N->getOpcode();
24972501 EVT VT = N->getValueType(0);
2498- SDValue Cond = N1.getOperand(0);
2499- SDValue TVal = N1.getOperand(1);
2500- SDValue FVal = N1.getOperand(2);
25012502 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
25022503
25032504 // This transform increases uses of N0, so freeze it to be safe.
0 commit comments