-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[DAG] Fold (and X, (bswap/bitreverse (not Y))) -> (and X, (not (bswap/bitreverse Y))) #112547
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
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 |
---|---|---|
|
@@ -7353,6 +7353,17 @@ SDValue DAGCombiner::visitAND(SDNode *N) { | |
if (SDValue R = foldLogicOfShifts(N, N1, N0, DAG)) | ||
return R; | ||
|
||
// Fold (and X, (bswap (not Y))) -> (and X, (not (bswap Y))) | ||
// Fold (and X, (bitreverse (not Y))) -> (and X, (not (bitreverse Y))) | ||
SDValue X, Y, NotY; | ||
for (unsigned Opc : {ISD::BSWAP, ISD::BITREVERSE}) | ||
if (sd_match(N, | ||
m_And(m_Value(X), m_OneUse(m_UnaryOp(Opc, m_Value(NotY))))) && | ||
sd_match(NotY, m_Not(m_Value(Y))) && | ||
(TLI.hasAndNot(SDValue(N, 0)) || NotY->hasOneUse())) | ||
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. Is this necessary? Seems like it expose ~X & ~Y -> ~(X | Y) 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. It is 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. Yes - its to prevent the fold when we already have a ANDNOT pattern. 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 mean isn't 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 guess assuming 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. Yes, for the NOT(Y) we can allow multiple uses as with a ANDNOT we'll be getting it for free - I'd be willing to allow this fold to occur on targets without ANDNOT, if for those targets we require the NOT(Y) to have one use? 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. Yeah, something like
should work. |
||
return DAG.getNode(ISD::AND, DL, VT, X, | ||
DAG.getNOT(DL, DAG.getNode(Opc, DL, VT, Y), VT)); | ||
|
||
// Masking the negated extension of a boolean is just the zero-extended | ||
// boolean: | ||
// and (sub 0, zext(bool X)), 1 --> zext(bool X) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe should be
|| (NotY->hasOneUse() && sd_match(X, m_Not(m_Value()))
There is a lot of diff from just re-assosiating the not which seems netural.
No strong opinion, however.