-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DAG] Matched FixedWidth pattern for ISD::AVGFLOORU #84903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f24f251
c2f47d6
298712b
93c9305
194fd28
46c23cb
ed3aae8
766caed
9365317
00986c4
eb994e0
c706403
e7dc0c0
830ac3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2820,6 +2820,23 @@ SDValue DAGCombiner::visitADDLike(SDNode *N) { | |
return SDValue(); | ||
} | ||
|
||
// Attempt to form avgflooru(A, B) from (A & B) + ((A ^ B) >> 1) | ||
static SDValue combineFixedwidthToAVGFLOORU(SDNode *N, SelectionDAG &DAG) { | ||
Sh0g0-1758 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const TargetLowering &TLI = DAG.getTargetLoweringInfo(); | ||
SDValue N0 = N->getOperand(0); | ||
Sh0g0-1758 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
EVT VT = N0.getValueType(); | ||
SDLoc DL(N); | ||
if (TLI.isOperationLegal(ISD::AVGFLOORU, VT)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally the operands of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using sd_match would handle commutative matching for us There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the kind of thing I had in mind: if (TLI.isOperationLegal(ISD::AVGFLOORU, VT)) {
SDValue A, B;
if (sd_match(N, m_Add(m_And(m_Value(A), m_Value(B)),
m_Srl(m_Xor(m_Deferred(A), m_Deferred(B)),
m_SpecificInt(1))))) {
return DAG.getNode(ISD::AVGFLOORU, DL, VT, A, B);
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But since const TargetLowering &TLI = DAG.getTargetLoweringInfo();
SDValue N0 = N->getOperand(0);
EVT VT = N0.getValueType();
SDLoc DL(N);
if (TLI.isOperationLegal(ISD::AVGFLOORU, VT)) {
SDValue A, B;
if (sd_match(N, llvm::SDPatternMatch::m_Add(llvm::PatternMatch::m_And(m_Value(A), m_Value(B)),
llvm::SDPatternMatch::m_Srl(llvm::PatternMatch::m_Xor(m_Deferred(A), m_Deferred(B)),
m_SpecificInt(1))))) {
return DAG.getNode(ISD::AVGFLOORU, DL, VT, A, B);
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added the code for commutative matching, but not using the method as suggested by @RKSimon. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll get m_And / mXor / m_Or added shortly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, sure thing. Then we can use the shortened version as part of this PR itself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modified the code accordingly. |
||
SDValue A, B; | ||
if (sd_match(N, m_Add(m_And(m_Value(A), m_Value(B)), | ||
m_Srl(m_Xor(m_Deferred(A), m_Deferred(B)), | ||
m_SpecificInt(1))))) { | ||
return DAG.getNode(ISD::AVGFLOORU, DL, VT, A, B); | ||
} | ||
} | ||
return SDValue(); | ||
Sh0g0-1758 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
SDValue DAGCombiner::visitADD(SDNode *N) { | ||
SDValue N0 = N->getOperand(0); | ||
SDValue N1 = N->getOperand(1); | ||
|
@@ -2835,6 +2852,10 @@ SDValue DAGCombiner::visitADD(SDNode *N) { | |
if (SDValue V = foldAddSubOfSignBit(N, DAG)) | ||
Sh0g0-1758 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return V; | ||
|
||
// Try to match AVGFLOORU fixedwidth pattern | ||
if (SDValue V = combineFixedwidthToAVGFLOORU(N, DAG)) | ||
return V; | ||
|
||
// fold (a+b) -> (a|b) iff a and b share no bits. | ||
if ((!LegalOperations || TLI.isOperationLegal(ISD::OR, VT)) && | ||
DAG.haveNoCommonBitsSet(N0, N1)) | ||
|
Uh oh!
There was an error while loading. Please reload this page.