Skip to content

Commit ca2e8fc

Browse files
authored
Update callers of isTriviallyReMaterializable to check trivialness (#160319)
This is a preparatory change for an upcoming reorganization of our rematerialization APIs. Despite the interface being documented as "trivial" (meaning no virtual register uses on the instruction being considered for remat), our actual implementation inconsistently supports non-trivial remat, and certain backends (AMDGPU and RISC-V mostly) lie about instructions being trivial to abuse that. We want to allow non-triial remat more broadly, but first we need to do some cleanup to make it understandable what's going on. These three call sites are ones which appear to actually want the trivial definition, and appear fairly low risk to change. p.s. I'm deliberately *not* updating any APIs in this change, I'm going to do that as a followup once it's clear which category each callsite fits in.
1 parent 721d1a0 commit ca2e8fc

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2212,7 +2212,11 @@ findPrologueEndLoc(const MachineFunction *MF) {
22122212
-> std::optional<std::pair<const MachineInstr *, bool>> {
22132213
// Is this instruction trivial data shuffling or frame-setup?
22142214
bool isCopy = (TII.isCopyInstr(MI) ? true : false);
2215-
bool isTrivRemat = TII.isTriviallyReMaterializable(MI);
2215+
bool isTrivRemat =
2216+
TII.isTriviallyReMaterializable(MI) &&
2217+
llvm::all_of(MI.all_uses(), [](const MachineOperand &MO) {
2218+
return MO.getReg().isVirtual();
2219+
});
22162220
bool isFrameSetup = MI.getFlag(MachineInstr::FrameSetup);
22172221

22182222
if (!isFrameSetup && MI.getDebugLoc()) {

llvm/lib/CodeGen/RegAllocScore.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ llvm::calculateRegAllocScore(const MachineFunction &MF,
7979
return MBFI.getBlockFreqRelativeToEntryBlock(&MBB);
8080
},
8181
[&](const MachineInstr &MI) {
82-
return MF.getSubtarget().getInstrInfo()->isTriviallyReMaterializable(
83-
MI);
82+
auto *TTI = MF.getSubtarget().getInstrInfo();
83+
return TTI->isTriviallyReMaterializable(MI) &&
84+
llvm::all_of(MI.all_uses(), [](const MachineOperand &MO) {
85+
return MO.getReg().isVirtual();
86+
});
8487
});
8588
}
8689

llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,10 @@ static void query(const MachineInstr &MI, bool &Read, bool &Write,
260260
// Test whether Def is safe and profitable to rematerialize.
261261
static bool shouldRematerialize(const MachineInstr &Def,
262262
const WebAssemblyInstrInfo *TII) {
263-
return Def.isAsCheapAsAMove() && TII->isTriviallyReMaterializable(Def);
263+
return Def.isAsCheapAsAMove() && TII->isTriviallyReMaterializable(Def) &&
264+
llvm::all_of(Def.all_uses(), [](const MachineOperand &MO) {
265+
return MO.getReg().isVirtual();
266+
});
264267
}
265268

266269
// Identify the definition for this register at this point. This is a

0 commit comments

Comments
 (0)