Skip to content

Commit a9b5cf1

Browse files
committed
Remove madeChange assignment, fold def into if statement, clarify comment about how the register coalescer produces unallocatable instructions
1 parent b91c582 commit a9b5cf1

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

llvm/lib/Target/RISCV/RISCVVMV0Elimination.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
// register in the singleton vmv0 register class instead of copying them to $v0
1111
// straight away, to make optimizing masks easier.
1212
//
13-
// However the register allocator struggles with singleton register classes and
14-
// will run into errors like "ran out of registers during register allocation in
15-
// function"
13+
// However register coalescing may end up coleascing copies into vmv0, resulting
14+
// in instructions with multiple uses of vmv0 that the register allocator can't
15+
// allocate:
1616
//
17-
// This pass runs just before register allocation and replaces any uses* of vmv0
18-
// with copies to $v0.
17+
// %x:vrnov0 = PseudoVADD_VV_M1_MASK %0:vrnov0, %1:vr, %2:vmv0, %3:vmv0, ...
18+
//
19+
// To avoid this, this pass replaces any uses* of vmv0 with copies to $v0 before
20+
// register coalescing and allocation:
1921
//
2022
// %x:vrnov0 = PseudoVADD_VV_M1_MASK %0:vrnov0, %1:vr, %2:vr, %3:vmv0, ...
2123
// ->
@@ -128,8 +130,8 @@ bool RISCVVMV0Elimination::runOnMachineFunction(MachineFunction &MF) {
128130
Src.isVirtual() && "vmv0 use in unexpected form");
129131

130132
// Peek through a single copy to match what isel does.
131-
MachineInstr *SrcMI = MRI.getVRegDef(Src);
132-
if (SrcMI->isCopy() && SrcMI->getOperand(1).getReg().isVirtual()) {
133+
if (MachineInstr *SrcMI = MRI.getVRegDef(Src);
134+
SrcMI->isCopy() && SrcMI->getOperand(1).getReg().isVirtual()) {
133135
assert(SrcMI->getOperand(1).getSubReg() == RISCV::NoSubRegister);
134136
Src = SrcMI->getOperand(1).getReg();
135137
}
@@ -161,11 +163,10 @@ bool RISCVVMV0Elimination::runOnMachineFunction(MachineFunction &MF) {
161163
MI.isInlineAsm() ||
162164
MRI.getVRegDef(MO.getReg())->isInlineAsm() &&
163165
"Non-inline-asm use of vmv0 left behind");
164-
MadeChange = true;
165166
}
166167
}
167168
}
168169
}
169170

170-
return MadeChange;
171+
return true;
171172
}

0 commit comments

Comments
 (0)