Skip to content

Commit e77d428

Browse files
authored
[AMDGPU] Do not remat instructions with PhysReg uses (#124366)
This blocks rematerialization during scheduling if the instruction has a non accepted PhysReg use. Currently, there aren't any checks like this in place, and we may create invalid code: https://godbolt.org/z/xjPjdcorf
1 parent d1139b3 commit e77d428

File tree

2 files changed

+418
-50
lines changed

2 files changed

+418
-50
lines changed

llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,15 +1842,23 @@ bool PreRARematStage::sinkTriviallyRematInsts(const GCNSubtarget &ST,
18421842
return true;
18431843
}
18441844

1845-
// Copied from MachineLICM
18461845
bool PreRARematStage::isTriviallyReMaterializable(const MachineInstr &MI) {
18471846
if (!DAG.TII->isTriviallyReMaterializable(MI))
18481847
return false;
18491848

1850-
for (const MachineOperand &MO : MI.all_uses())
1849+
for (const MachineOperand &MO : MI.all_uses()) {
18511850
if (MO.getReg().isVirtual())
18521851
return false;
18531852

1853+
// We can't remat physreg uses, unless it is a constant or an ignorable
1854+
// use (e.g. implicit exec use on VALU instructions)
1855+
if (MO.getReg().isPhysical()) {
1856+
if (DAG.MRI.isConstantPhysReg(MO.getReg()) || DAG.TII->isIgnorableUse(MO))
1857+
continue;
1858+
return false;
1859+
}
1860+
}
1861+
18541862
return true;
18551863
}
18561864

0 commit comments

Comments
 (0)