-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SDAG] Use shifts if ISD::MUL is illegal when lowering ISD::CTPOP #86505
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
888726d
02baa6c
d041aea
e882368
66e4b9f
1bd62e4
5087f7a
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 |
---|---|---|
|
@@ -6362,12 +6362,26 @@ LegalizerHelper::lowerBitCount(MachineInstr &MI) { | |
// 8 bits can hold CTPOP result of 128 bit int or smaller. Mul with this | ||
// bitmask will set 8 msb in ResTmp to sum of all B8Counts in 8 bit blocks. | ||
auto MulMask = B.buildConstant(Ty, APInt::getSplat(Size, APInt(8, 0x01))); | ||
auto ResTmp = B.buildMul(Ty, B8Count, MulMask); | ||
|
||
// Shift count result from 8 high bits to low bits. | ||
auto C_SizeM8 = B.buildConstant(Ty, Size - 8); | ||
B.buildLShr(MI.getOperand(0).getReg(), ResTmp, C_SizeM8); | ||
|
||
auto IsMulSupported = [this](const LLT Ty) { | ||
auto Action = LI.getAction({TargetOpcode::G_MUL, {Ty}}).Action; | ||
return Action == Legal || Action == WidenScalar || Action == Custom; | ||
}; | ||
if (IsMulSupported(Ty)) { | ||
auto ResTmp = B.buildMul(Ty, B8Count, MulMask); | ||
B.buildLShr(MI.getOperand(0).getReg(), ResTmp, C_SizeM8); | ||
} else { | ||
auto ResTmp = B8Count; | ||
for (unsigned Shift = 8; Shift < Size; Shift *= 2) { | ||
auto ShiftC = B.buildConstant(Ty, Shift); | ||
auto Shl = B.buildShl(Ty, ResTmp, ShiftC); | ||
ResTmp = B.buildAdd(Ty, ResTmp, Shl); | ||
} | ||
B.buildLShr(MI.getOperand(0).getReg(), ResTmp, C_SizeM8); | ||
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 assuming the result type is the same as the source type, which is not the case. CTPOP has 2 type indices, the result type may differ from the source 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 see this is an existing bug, so I suppose it's best to leave as-is and fix separately 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'm not familiar with GlobalISel, so I will leave it to you guys to fix it. :-) |
||
} | ||
MI.eraseFromParent(); | ||
return Legalized; | ||
} | ||
|
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.
Same here