Skip to content

Commit e92e5ee

Browse files
committed
Constrain register classes instead of emitting copies.
Sometimes register class constraints are trivial, like GR32->GR32_NOSP, or GPR->rGPR. Teach InstrEmitter to simply constrain the virtual register instead of emitting a copy in these cases. Normally, these copies are handled by the coalescer. This saves some coalescer work. llvm-svn: 140340
1 parent 0f36544 commit e92e5ee

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,17 @@ InstrEmitter::AddRegisterOperand(MachineInstr *MI, SDValue Op,
280280
MCID.OpInfo[IIOpNum].isOptionalDef();
281281

282282
// If the instruction requires a register in a different class, create
283-
// a new virtual register and copy the value into it.
283+
// a new virtual register and copy the value into it, but first attempt to
284+
// shrink VReg's register class within reason. For example, if VReg == GR32
285+
// and II requires a GR32_NOSP, just constrain VReg to GR32_NOSP.
286+
const unsigned MinRCSize = 4;
284287
if (II) {
285-
const TargetRegisterClass *SrcRC = MRI->getRegClass(VReg);
286288
const TargetRegisterClass *DstRC = 0;
287289
if (IIOpNum < II->getNumOperands())
288290
DstRC = TII->getRegClass(*II, IIOpNum, TRI);
289291
assert((DstRC || (MCID.isVariadic() && IIOpNum >= MCID.getNumOperands())) &&
290292
"Don't have operand info for this instruction!");
291-
if (DstRC && !SrcRC->hasSuperClassEq(DstRC)) {
293+
if (DstRC && !MRI->constrainRegClass(VReg, DstRC, MinRCSize)) {
292294
unsigned NewVReg = MRI->createVirtualRegister(DstRC);
293295
BuildMI(*MBB, InsertPos, Op.getNode()->getDebugLoc(),
294296
TII->get(TargetOpcode::COPY), NewVReg).addReg(VReg);

0 commit comments

Comments
 (0)