-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[SDag][ARM][RISCV] Allow lowering CTPOP into a libcall #99752
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 5 commits
bb8a735
437a0e5
f90a6b4
66ae5db
724bc32
c418f1c
fb985db
ae297d6
6b48d10
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 |
---|---|---|
|
@@ -3847,15 +3847,36 @@ void DAGTypeLegalizer::ExpandIntRes_CTLZ(SDNode *N, | |
Hi = DAG.getConstant(0, dl, NVT); | ||
} | ||
|
||
void DAGTypeLegalizer::ExpandIntRes_CTPOP(SDNode *N, | ||
SDValue &Lo, SDValue &Hi) { | ||
SDLoc dl(N); | ||
void DAGTypeLegalizer::ExpandIntRes_CTPOP(SDNode *N, SDValue &Lo, SDValue &Hi) { | ||
SDValue Op = N->getOperand(0); | ||
EVT VT = N->getValueType(0); | ||
SDLoc DL(N); | ||
|
||
// If the narrow CTPOP is not supported by the target, try to convert it | ||
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. Do we really have to handle the libcall logic during type legalization? Can this just adjust the type, and leave the libcall for the libcall action 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. If we expand it later, we will end up with two libcalls for an illegal type instead of one (best case), or those two libcalls will be expanded into scalar code. You can see the difference in this commit. |
||
// to a libcall. | ||
EVT ExpandedVT = TLI.getTypeToExpandTo(*DAG.getContext(), VT); | ||
if (!TLI.isOperationLegalOrCustom(ISD::CTPOP, ExpandedVT)) { | ||
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. Should at least check if this is the libcall action 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 was thinking about this too, but I found only one place where LibCall action is checked. That made me wonder if this is the right thing to do. Hopefully someone can tell for sure. 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. This is a stalled migration. Ideally the Expand action would never produce a libcall. 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. Changed to check for LibCall action. |
||
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; | ||
if (VT == MVT::i32) | ||
LC = RTLIB::CTPOP_I32; | ||
else if (VT == MVT::i64) | ||
LC = RTLIB::CTPOP_I64; | ||
else if (VT == MVT::i128) | ||
LC = RTLIB::CTPOP_I128; | ||
if (LC != RTLIB::UNKNOWN_LIBCALL && TLI.getLibcallName(LC)) { | ||
TargetLowering::MakeLibCallOptions CallOptions; | ||
SDValue Res = TLI.makeLibCall(DAG, LC, VT, Op, CallOptions, DL).first; | ||
SplitInteger(Res, Lo, Hi); | ||
return; | ||
} | ||
} | ||
|
||
// ctpop(HiLo) -> ctpop(Hi)+ctpop(Lo) | ||
GetExpandedInteger(N->getOperand(0), Lo, Hi); | ||
GetExpandedInteger(Op, Lo, Hi); | ||
EVT NVT = Lo.getValueType(); | ||
Lo = DAG.getNode(ISD::ADD, dl, NVT, DAG.getNode(ISD::CTPOP, dl, NVT, Lo), | ||
DAG.getNode(ISD::CTPOP, dl, NVT, Hi)); | ||
Hi = DAG.getConstant(0, dl, NVT); | ||
Lo = DAG.getNode(ISD::ADD, DL, NVT, DAG.getNode(ISD::CTPOP, DL, NVT, Lo), | ||
DAG.getNode(ISD::CTPOP, DL, NVT, Hi)); | ||
Hi = DAG.getConstant(0, DL, NVT); | ||
} | ||
|
||
void DAGTypeLegalizer::ExpandIntRes_CTTZ(SDNode *N, | ||
|
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.
Looks like a lot of unrelated format changes?
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 renamed isSigned -> IsSigned while I was here, clang-format insisted that I reformat this code fragment.
Do I need to revert these changes?
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.
Ah, didn't notice the capital letter change. I don't think it's necessary to change then.
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.
Can precommit this unrelated change