Skip to content

Commit a3ac511

Browse files
committed
reword with sd_match
1 parent fc5c9c6 commit a3ac511

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10975,30 +10975,18 @@ SDValue DAGCombiner::visitSRL(SDNode *N) {
1097510975
// fold (srl (logic_op x, (shl (zext y), c1)), c1)
1097610976
// -> (logic_op (srl x, c1), (zext y))
1097710977
// c1 <= leadingzeros(zext(y))
10978-
if (N1C && ISD::isBitwiseLogicOp(N0.getOpcode()) && N0.hasOneUse()) {
10979-
SDValue LHS = N0.getOperand(0);
10980-
SDValue RHS = N0.getOperand(1);
10981-
SDValue SHL;
10982-
SDValue Other;
10983-
if (LHS.getOpcode() == ISD::SHL) {
10984-
SHL = LHS;
10985-
Other = RHS;
10986-
} else if (RHS.getOpcode() == ISD::SHL) {
10987-
SHL = RHS;
10988-
Other = LHS;
10989-
}
10990-
if (SHL && SHL.getOperand(1) == N1 && SHL.hasOneUse()) {
10991-
SDValue ZExt = SHL.getOperand(0);
10992-
if (ZExt.getOpcode() == ISD::ZERO_EXTEND) {
10993-
unsigned NumLeadingZeros =
10994-
ZExt.getValueType().getScalarSizeInBits() -
10995-
ZExt.getOperand(0).getValueType().getScalarSizeInBits();
10996-
if (N1C->getZExtValue() <= NumLeadingZeros) {
10997-
return DAG.getNode(N0.getOpcode(), SDLoc(N0), VT,
10998-
DAG.getNode(ISD::SRL, SDLoc(N0), VT, Other, N1),
10999-
ZExt);
11000-
}
11001-
}
10978+
SDValue X, ZExtY;
10979+
if (N1C && sd_match(N0, m_OneUse(m_BitwiseLogic(
10980+
m_Value(X),
10981+
m_OneUse(m_Shl(m_AllOf(m_Value(ZExtY),
10982+
m_Opc(ISD::ZERO_EXTEND)),
10983+
m_Specific(N1))))))) {
10984+
unsigned NumLeadingZeros =
10985+
ZExtY.getValueType().getScalarSizeInBits() -
10986+
ZExtY.getOperand(0).getValueType().getScalarSizeInBits();
10987+
if (N1C->getZExtValue() <= NumLeadingZeros) {
10988+
return DAG.getNode(N0.getOpcode(), SDLoc(N0), VT,
10989+
DAG.getNode(ISD::SRL, SDLoc(N0), VT, X, N1), ZExtY);
1100210990
}
1100310991
}
1100410992

0 commit comments

Comments
 (0)