-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[GlobalIsel] Combine zext of trunc (episode II) #108305
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 4 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 |
|---|---|---|
|
|
@@ -333,8 +333,10 @@ MachineInstrBuilder CSEMIRBuilder::buildConstant(const DstOp &Res, | |
|
|
||
| // For vectors, CSE the element only for now. | ||
| LLT Ty = Res.getLLTTy(*getMRI()); | ||
| if (Ty.isVector()) | ||
| if (Ty.isFixedVector()) | ||
| return buildSplatBuildVector(Res, buildConstant(Ty.getElementType(), Val)); | ||
| if (Ty.isScalableVector()) | ||
| return buildSplatVector(Res, buildConstant(Ty.getElementType(), Val)); | ||
|
||
|
|
||
| FoldingSetNodeID ID; | ||
| GISelInstProfileBuilder ProfBuilder(ID, *getMRI()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2526,20 +2526,6 @@ bool CombinerHelper::matchCombineAnyExtTrunc(MachineInstr &MI, Register &Reg) { | |
| m_GTrunc(m_all_of(m_Reg(Reg), m_SpecificType(DstTy)))); | ||
| } | ||
|
|
||
| bool CombinerHelper::matchCombineZextTrunc(MachineInstr &MI, Register &Reg) { | ||
| assert(MI.getOpcode() == TargetOpcode::G_ZEXT && "Expected a G_ZEXT"); | ||
| Register DstReg = MI.getOperand(0).getReg(); | ||
| Register SrcReg = MI.getOperand(1).getReg(); | ||
| LLT DstTy = MRI.getType(DstReg); | ||
| if (mi_match(SrcReg, MRI, | ||
| m_GTrunc(m_all_of(m_Reg(Reg), m_SpecificType(DstTy))))) { | ||
|
||
| unsigned DstSize = DstTy.getScalarSizeInBits(); | ||
| unsigned SrcSize = MRI.getType(SrcReg).getScalarSizeInBits(); | ||
| return KB->getKnownBits(Reg).countMinLeadingZeros() >= DstSize - SrcSize; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| static LLT getMidVTForTruncRightShiftCombine(LLT ShiftTy, LLT TruncTy) { | ||
| const unsigned ShiftSize = ShiftTy.getScalarSizeInBits(); | ||
| const unsigned TruncSize = TruncTy.getScalarSizeInBits(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -359,3 +359,94 @@ bool CombinerHelper::matchCastOfInteger(const MachineInstr &CastMI, | |||
| return false; | ||||
| } | ||||
| } | ||||
|
|
||||
| bool CombinerHelper::matchCombineZextTrunc(const MachineInstr &ZextMI, | ||||
| const MachineInstr &TruncMI, | ||||
| BuildFnTy &MatchInfo) { | ||||
| const GZext *Zext = cast<GZext>(&ZextMI); | ||||
| const GTrunc *Trunc = cast<GTrunc>(&TruncMI); | ||||
|
|
||||
| Register Dst = Zext->getReg(0); | ||||
| Register Mid = Zext->getSrcReg(); | ||||
| Register Src = Trunc->getSrcReg(); | ||||
|
|
||||
| LLT DstTy = MRI.getType(Dst); | ||||
| LLT SrcTy = MRI.getType(Src); | ||||
|
|
||||
| if (!MRI.hasOneNonDBGUse(Mid)) | ||||
| return false; | ||||
|
|
||||
| unsigned DstSize = DstTy.getScalarSizeInBits(); | ||||
| unsigned MidSize = MRI.getType(Mid).getScalarSizeInBits(); | ||||
| unsigned SrcSize = SrcTy.getScalarSizeInBits(); | ||||
|
|
||||
| // Are the truncated bits known to be zero? | ||||
| if (DstTy == SrcTy && | ||||
| (KB->getKnownBits(Src).countMinLeadingZeros() >= DstSize - MidSize)) { | ||||
| MatchInfo = [=](MachineIRBuilder &B) { B.buildCopy(Dst, Src); }; | ||||
| return true; | ||||
| } | ||||
|
||||
| // If we're actually extending zero bits, then if |
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.
Crash in combine-with-flags.mir. Blame me.