Skip to content

Commit 59138a6

Browse files
authored
[DAGCombiner] Cleanup MatchFunnelPosNeg by using SDPatternMatch matchers (#129482)
Fixes issue: #129034
1 parent 71f4c7d commit 59138a6

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8512,39 +8512,33 @@ SDValue DAGCombiner::MatchFunnelPosNeg(SDValue N0, SDValue N1, SDValue Pos,
85128512
// so for now just use the PosOpcode case if its legal.
85138513
// TODO: When can we use the NegOpcode case?
85148514
if (PosOpcode == ISD::FSHL && isPowerOf2_32(EltBits)) {
8515-
auto IsBinOpImm = [](SDValue Op, unsigned BinOpc, unsigned Imm) {
8516-
if (Op.getOpcode() != BinOpc)
8517-
return false;
8518-
ConstantSDNode *Cst = isConstOrConstSplat(Op.getOperand(1));
8519-
return Cst && (Cst->getAPIntValue() == Imm);
8520-
};
8521-
8515+
SDValue X;
85228516
// fold (or (shl x0, y), (srl (srl x1, 1), (xor y, 31)))
85238517
// -> (fshl x0, x1, y)
8524-
if (IsBinOpImm(N1, ISD::SRL, 1) &&
8525-
IsBinOpImm(InnerNeg, ISD::XOR, EltBits - 1) &&
8526-
InnerPos == InnerNeg.getOperand(0) &&
8518+
if (sd_match(N1, m_Srl(m_Value(X), m_One())) &&
8519+
sd_match(InnerNeg,
8520+
m_Xor(m_Specific(InnerPos), m_SpecificInt(EltBits - 1))) &&
85278521
TLI.isOperationLegalOrCustom(ISD::FSHL, VT)) {
8528-
return DAG.getNode(ISD::FSHL, DL, VT, N0, N1.getOperand(0), Pos);
8522+
return DAG.getNode(ISD::FSHL, DL, VT, N0, X, Pos);
85298523
}
85308524

85318525
// fold (or (shl (shl x0, 1), (xor y, 31)), (srl x1, y))
85328526
// -> (fshr x0, x1, y)
8533-
if (IsBinOpImm(N0, ISD::SHL, 1) &&
8534-
IsBinOpImm(InnerPos, ISD::XOR, EltBits - 1) &&
8535-
InnerNeg == InnerPos.getOperand(0) &&
8527+
if (sd_match(N0, m_Shl(m_Value(X), m_One())) &&
8528+
sd_match(InnerPos,
8529+
m_Xor(m_Specific(InnerNeg), m_SpecificInt(EltBits - 1))) &&
85368530
TLI.isOperationLegalOrCustom(ISD::FSHR, VT)) {
8537-
return DAG.getNode(ISD::FSHR, DL, VT, N0.getOperand(0), N1, Neg);
8531+
return DAG.getNode(ISD::FSHR, DL, VT, X, N1, Neg);
85388532
}
85398533

85408534
// fold (or (shl (add x0, x0), (xor y, 31)), (srl x1, y))
85418535
// -> (fshr x0, x1, y)
85428536
// TODO: Should add(x,x) -> shl(x,1) be a general DAG canonicalization?
8543-
if (N0.getOpcode() == ISD::ADD && N0.getOperand(0) == N0.getOperand(1) &&
8544-
IsBinOpImm(InnerPos, ISD::XOR, EltBits - 1) &&
8545-
InnerNeg == InnerPos.getOperand(0) &&
8537+
if (sd_match(N0, m_Add(m_Value(X), m_Deferred(X))) &&
8538+
sd_match(InnerPos,
8539+
m_Xor(m_Specific(InnerNeg), m_SpecificInt(EltBits - 1))) &&
85468540
TLI.isOperationLegalOrCustom(ISD::FSHR, VT)) {
8547-
return DAG.getNode(ISD::FSHR, DL, VT, N0.getOperand(0), N1, Neg);
8541+
return DAG.getNode(ISD::FSHR, DL, VT, X, N1, Neg);
85488542
}
85498543
}
85508544

0 commit comments

Comments
 (0)