-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[DAGCombine] Fold ctlz_zero_undef(X << C) -> ctlz_zero_undef(X) - C
#100932
base: main
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -11133,6 +11133,18 @@ SDValue DAGCombiner::visitCTLZ_ZERO_UNDEF(SDNode *N) { | |
if (SDValue C = | ||
DAG.FoldConstantArithmetic(ISD::CTLZ_ZERO_UNDEF, DL, VT, {N0})) | ||
return C; | ||
|
||
// Fold ctlz_zero_undef(X << C) --> ctlz_zero_undef(X) - C | ||
SDValue A; | ||
APInt C; | ||
if (sd_match(N0, m_Shl(m_Value(A), m_ConstInt(C))) && | ||
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. alive link has nuw flag but this doesn't check that 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 checked by 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. That check on the operand of the shift cannot see the flag on the shift 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. The proof has been updated: https://alive2.llvm.org/ce/z/Gd37Tv. 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 can't you use the NUW in place of this check? 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. IIRC DAGCombine doesn't infer poison-generating flags for new SDNodes.
|
||
DAG.computeKnownBits(A).countMinLeadingZeros() >= C.getLimitedValue()) { | ||
SDValue NegC = | ||
DAG.getConstant(-C.zextOrTrunc(VT.getScalarSizeInBits()), DL, VT); | ||
return DAG.getNode(ISD::ADD, DL, VT, | ||
DAG.getNode(ISD::CTLZ_ZERO_UNDEF, DL, VT, A), NegC); | ||
} | ||
|
||
return SDValue(); | ||
} | ||
|
||
|
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.
It's not obvious to me that it's better. it's just trading a shift for an add or sub?
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.
Is it better to fold
C1 - ctlz_zero_undef(X << C2) --> C1 + C2 - ctlz_zero_undef(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.
You can do both. The win is probably that the parameter of the
ctlz_zero_undef
got simpler.