-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[RegisterCoalescer] Mark implicit-defs of super-registers as dead in remat #159110
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 3 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 |
|---|---|---|
|
|
@@ -1474,28 +1474,22 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP, | |
| // | ||
| // The implicit-def of the super register may have been reduced to | ||
| // subregisters depending on the uses. | ||
|
|
||
| bool NewMIDefinesFullReg = false; | ||
|
|
||
| SmallVector<MCRegister, 4> NewMIImplDefs; | ||
| SmallVector<std::pair<unsigned, MCRegister>, 4> NewMIImplDefs; | ||
| for (unsigned i = NewMI.getDesc().getNumOperands(), | ||
| e = NewMI.getNumOperands(); | ||
| i != e; ++i) { | ||
| MachineOperand &MO = NewMI.getOperand(i); | ||
| if (MO.isReg() && MO.isDef()) { | ||
| assert(MO.isImplicit()); | ||
| if (MO.getReg().isPhysical()) { | ||
| if (MO.getReg() == DstReg) | ||
| NewMIDefinesFullReg = true; | ||
|
|
||
| assert(MO.isImplicit() && MO.getReg().isPhysical() && | ||
| (MO.isDead() || | ||
| (DefSubIdx && | ||
| ((TRI->getSubReg(MO.getReg(), DefSubIdx) == | ||
| MCRegister((unsigned)NewMI.getOperand(0).getReg())) || | ||
| TRI->isSubRegisterEq(NewMI.getOperand(0).getReg(), | ||
| MO.getReg()))))); | ||
| NewMIImplDefs.push_back(MO.getReg().asMCReg()); | ||
| NewMIImplDefs.push_back({i, MO.getReg().asMCReg()}); | ||
| } else { | ||
| assert(MO.getReg() == NewMI.getOperand(0).getReg()); | ||
|
|
||
|
|
@@ -1640,12 +1634,30 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP, | |
| // been asked for. If so it must implicitly define the whole thing. | ||
| assert(DstReg.isPhysical() && | ||
| "Only expect virtual or physical registers in remat"); | ||
|
|
||
| // When we're rematerializing into a not-quite-right register we already add | ||
| // the real definition as an implicit-def, but we should also be marking the | ||
| // "official" register as dead, since nothing else is going to use it as a | ||
| // result of this remat. Not doing this can affect pressure tracking. | ||
| NewMI.getOperand(0).setIsDead(true); | ||
|
Contributor
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. Is this whole function reinventing MachineInstr::addRegisterDead?
Member
Author
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. Not really.
|
||
|
|
||
| if (!NewMIDefinesFullReg) { | ||
| bool HasDefMatchingCopy = false; | ||
| for (auto [OpIndex, Reg] : NewMIImplDefs) { | ||
| if (Reg != DstReg.asMCReg()) | ||
| continue; | ||
| // Also, if CopyDstReg is a sub-register of DstReg (and it is defined), we | ||
| // must mark DstReg as dead since it is not going to used as a result of | ||
| // this remat. | ||
| if (DstReg != CopyDstReg) | ||
| NewMI.getOperand(OpIndex).setIsDead(true); | ||
| else | ||
| HasDefMatchingCopy = true; | ||
| } | ||
|
|
||
| // If NewMI does not already have an implicit-def CopyDstReg add one now. | ||
| if (!HasDefMatchingCopy) | ||
| NewMI.addOperand(MachineOperand::CreateReg( | ||
| CopyDstReg, true /*IsDef*/, true /*IsImp*/, false /*IsKill*/)); | ||
| } | ||
|
|
||
| // Record small dead def live-ranges for all the subregisters | ||
| // of the destination register. | ||
|
|
@@ -1676,7 +1688,7 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP, | |
| NewMI.addOperand(MO); | ||
|
|
||
| SlotIndex NewMIIdx = LIS->getInstructionIndex(NewMI); | ||
| for (MCRegister Reg : NewMIImplDefs) { | ||
| for (MCRegister Reg : make_second_range(NewMIImplDefs)) { | ||
| for (MCRegUnit Unit : TRI->regunits(Reg)) | ||
| if (LiveRange *LR = LIS->getCachedRegUnit(Unit)) | ||
| LR->createDeadDef(NewMIIdx.getRegSlot(), LIS->getVNInfoAllocator()); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.