[llvm] [AMDGPU][CodeGen] Allow remat with multiple users in multiple regions (PR #215598)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 03:12:12 PDT 2026
================
@@ -1593,40 +1590,57 @@ bool PreRARematStage::initGCNSchedStage() {
[](const MachineInstr *DefMI) { return DefMI->isConvergent(); }))
continue;
- // We further filter the registers that we can rematerialize based on our
- // current tracking capabilities in the stage. Users cannot themselves be
- // marked rematerializable, and no register operand of the defining MI can
- // be marked rematerializable. We also do not rematerialize an instruction
- // if it uses registers that aren't available at its use. This ensures that
- // we are not extending any live range while rematerializing.
- if (llvm::any_of(Users, [&MarkedRegs](const MachineInstr *UserMI) {
- assert(UserMI->getNumOperands() > 0 &&
- "user must have at least one operand");
- const MachineOperand &UseMO = UserMI->getOperand(0);
- return UseMO.isReg() && MarkedRegs.contains(UseMO.getReg());
- }))
- continue;
- MachineInstr *FirstUseMI =
- CandReg.getRegionUseBounds(UseRegion, *DAG.LIS).first;
- assert(FirstUseMI && "there must be a user in the region");
- SlotIndex FirstUseIdx =
- DAG.LIS->getInstructionIndex(*FirstUseMI).getRegSlot(true);
SlotIndex RefIdx =
DAG.LIS->getInstructionIndex(*CandReg.getLastDef()).getRegSlot(true);
+
+ // We further filter the registers that we can rematerialize based on our
+ // current tracking capabilities in the stage. This ensures that we are not
+ // extending any live range while rematerializing, and that rematerializing
+ // any register candidate will not affect other candidates.
+
+ // All register dependencies should not already be considered
+ // rematerializable.
if (llvm::any_of(CandReg.Dependencies, [&](RegisterIdx DepRegIdx) {
- const Rematerializer::Reg &DepReg = Remater.getReg(DepRegIdx);
- Register DepDefReg = DepReg.getDefReg();
- return MarkedRegs.contains(DepDefReg) ||
- !Remater.isRegIdenticalAtUses(DepDefReg, DepReg.Mask, RefIdx,
- {FirstUseIdx});
+ return MarkedRegs.contains(Remater.getReg(DepRegIdx).getDefReg());
}))
continue;
- if (llvm::any_of(Remater.getUnrematableDeps(RegIdx),
- [&](const std::pair<Register, LaneBitmask> &RegAndMask) {
- const auto &[Reg, Mask] = RegAndMask;
- return !Remater.isRegIdenticalAtUses(Reg, Mask, RefIdx,
- {FirstUseIdx});
- }))
+
+ auto IsInvalidUsingRegion =
----------------
arsenm wrote:
This is too big for a lamba
https://github.com/llvm/llvm-project/pull/215598
More information about the llvm-commits
mailing list