Skip to content

Commit 7ffcd4d

Browse files
committed
[DAG]: Refactored foldSelectWithIdentityConstant
1 parent 1897775 commit 7ffcd4d

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

llvm/include/llvm/CodeGen/SDPatternMatch.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,8 @@ m_VSelect(const T0_P &Cond, const T1_P &T, const T2_P &F) {
559559
}
560560

561561
template <typename T0_P, typename T1_P, typename T2_P>
562-
inline TernaryOpc_match<T0_P, T1_P, T2_P>
563-
m_SelectLike(const T0_P &Cond, const T1_P &T, const T2_P &F) {
564-
return m_Select(Cond, T, F) || m_VSelect(Cond, T, F);
562+
inline auto m_SelectLike(const T0_P &Cond, const T1_P &T, const T2_P &F) {
563+
return m_AnyOf(m_Select(Cond, T, F), m_VSelect(Cond, T, F));
565564
}
566565

567566
template <typename T0_P, typename T1_P, typename T2_P>

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,28 +2476,29 @@ static bool canFoldInAddressingMode(SDNode *N, SDNode *Use, SelectionDAG &DAG,
24762476
/// masked vector operation if the target supports it.
24772477
static 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

Comments
 (0)