-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[DAGCombiner] Turn (neg (max x, (neg x))) into (min x, (neg x))
#120666
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 2 commits
abf6f85
25c43d8
1abcdc3
55d7531
3e85bc4
b8b253b
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 |
|---|---|---|
|
|
@@ -3949,6 +3949,20 @@ SDValue DAGCombiner::visitSUB(SDNode *N) { | |
| if (SDValue Result = TLI.expandABS(N1.getNode(), DAG, true)) | ||
| return Result; | ||
|
|
||
| // Similar to the previous rule, but this time targeting an expanded abs. | ||
| // (sub 0, (max X, (sub 0, X))) --> (min X, (sub 0, X)) | ||
| // Note that this is applicable to both signed and unsigned min/max. | ||
| SDValue X; | ||
| if (LegalOperations && | ||
| sd_match(N1, | ||
| m_OneUse(m_AnyOf(m_SMax(m_Value(X), m_Neg(m_Deferred(X))), | ||
| m_UMax(m_Value(X), m_Neg(m_Deferred(X))))))) { | ||
| unsigned MinOpc = N1->getOpcode() == ISD::SMAX ? ISD::SMIN : ISD::UMIN; | ||
|
||
| if (hasOperation(MinOpc, VT)) | ||
| return DAG.getNode(MinOpc, DL, VT, X, | ||
| DAG.getNode(ISD::SUB, DL, VT, N0, X)); | ||
|
||
| } | ||
|
|
||
| // Fold neg(splat(neg(x)) -> splat(x) | ||
| if (VT.isVector()) { | ||
| SDValue N1S = DAG.getSplatValue(N1, true); | ||
|
|
||
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.
Could also do the converse:
but I don't know if there's a real need for it.
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.
I think it's fine to add it in this patch. It's done now.