Skip to content

Commit 8ebbf25

Browse files
committed
AMDGPU: Erase redundant redefs of m0 in SIFoldOperands
Only handle simple inter-block redefs of m0 to the same value. This avoids interference from redefs of m0 in SILoadStoreOptimzer. I was initially teaching that pass to ignore redefs of m0, but having them not exist beforehand is much simpler. This is in preparation for deleting the current special m0 handling in SIFixSGPRCopies to allow the register coalescer to handle the difficult cases. llvm-svn: 375449
1 parent dd6cf15 commit 8ebbf25

File tree

2 files changed

+387
-0
lines changed

2 files changed

+387
-0
lines changed

llvm/lib/Target/AMDGPU/SIFoldOperands.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,8 @@ bool SIFoldOperands::runOnMachineFunction(MachineFunction &MF) {
13491349

13501350
for (MachineBasicBlock *MBB : depth_first(&MF)) {
13511351
MachineBasicBlock::iterator I, Next;
1352+
1353+
MachineOperand *CurrentKnownM0Val = nullptr;
13521354
for (I = MBB->begin(); I != MBB->end(); I = Next) {
13531355
Next = std::next(I);
13541356
MachineInstr &MI = *I;
@@ -1361,6 +1363,25 @@ bool SIFoldOperands::runOnMachineFunction(MachineFunction &MF) {
13611363
if (IsIEEEMode || (!HasNSZ && !MI.getFlag(MachineInstr::FmNsz)) ||
13621364
!tryFoldOMod(MI))
13631365
tryFoldClamp(MI);
1366+
1367+
// Saw an unknown clobber of m0, so we no longer know what it is.
1368+
if (CurrentKnownM0Val && MI.modifiesRegister(AMDGPU::M0, TRI))
1369+
CurrentKnownM0Val = nullptr;
1370+
continue;
1371+
}
1372+
1373+
// Specially track simple redefs of m0 to the same value in a block, so we
1374+
// can erase the later ones.
1375+
if (MI.getOperand(0).getReg() == AMDGPU::M0) {
1376+
MachineOperand &NewM0Val = MI.getOperand(1);
1377+
if (CurrentKnownM0Val && CurrentKnownM0Val->isIdenticalTo(NewM0Val)) {
1378+
MI.eraseFromParent();
1379+
continue;
1380+
}
1381+
1382+
// We aren't tracking other physical registers
1383+
CurrentKnownM0Val = (NewM0Val.isReg() && NewM0Val.getReg().isPhysical()) ?
1384+
nullptr : &NewM0Val;
13641385
continue;
13651386
}
13661387

0 commit comments

Comments
 (0)