Skip to content

Commit a2a9d3e

Browse files
committed
[DAG] foldAddToAvg - split nested m_Reassociatable matchers
The use of nested m_Reassociatable matchers by llvm#169644 can result in high compile times as the inner m_Reassociatable call is being repeated a lot while the outer call is trying to match
1 parent 4427e34 commit a2a9d3e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,26 +3164,28 @@ SDValue DAGCombiner::visitADDLike(SDNode *N) {
31643164
SDValue DAGCombiner::foldAddToAvg(SDNode *N, const SDLoc &DL) {
31653165
SDValue N0 = N->getOperand(0);
31663166
EVT VT = N0.getValueType();
3167-
SDValue A, B;
3167+
SDValue A, B, C;
31683168

31693169
if ((!LegalOperations || hasOperation(ISD::AVGFLOORU, VT)) &&
31703170
(sd_match(N,
31713171
m_Add(m_And(m_Value(A), m_Value(B)),
31723172
m_Srl(m_Xor(m_Deferred(A), m_Deferred(B)), m_One()))) ||
3173-
sd_match(N, m_ReassociatableAdd(
3174-
m_Srl(m_Value(A), m_One()), m_Srl(m_Value(B), m_One()),
3175-
m_ReassociatableAnd(m_Deferred(A), m_Deferred(B),
3176-
m_One()))))) {
3173+
(sd_match(N,
3174+
m_ReassociatableAdd(m_Srl(m_Value(A), m_One()),
3175+
m_Srl(m_Value(B), m_One()), m_Value(C))) &&
3176+
sd_match(
3177+
C, m_ReassociatableAnd(m_Deferred(A), m_Deferred(B), m_One()))))) {
31773178
return DAG.getNode(ISD::AVGFLOORU, DL, VT, A, B);
31783179
}
31793180
if ((!LegalOperations || hasOperation(ISD::AVGFLOORS, VT)) &&
31803181
(sd_match(N,
31813182
m_Add(m_And(m_Value(A), m_Value(B)),
31823183
m_Sra(m_Xor(m_Deferred(A), m_Deferred(B)), m_One()))) ||
3183-
sd_match(N, m_ReassociatableAdd(
3184-
m_Sra(m_Value(A), m_One()), m_Sra(m_Value(B), m_One()),
3185-
m_ReassociatableAnd(m_Deferred(A), m_Deferred(B),
3186-
m_One()))))) {
3184+
(sd_match(N,
3185+
m_ReassociatableAdd(m_Sra(m_Value(A), m_One()),
3186+
m_Sra(m_Value(B), m_One()), m_Value(C))) &&
3187+
sd_match(
3188+
C, m_ReassociatableAnd(m_Deferred(A), m_Deferred(B), m_One()))))) {
31873189
return DAG.getNode(ISD::AVGFLOORS, DL, VT, A, B);
31883190
}
31893191

0 commit comments

Comments
 (0)