[PATCH][RegAlloc] Make tryInstructionSplit less aggressive.

Jakob Stoklund Olesen stoklund at 2pi.dk
Mon Dec 23 15:00:14 PST 2013


On Dec 23, 2013, at 2:35 PM, Quentin Colombet <qcolombet at apple.com> wrote:

> Hi Jakob,
> 
> Here is the reworked patch.
> 
> Now the MachineInstr API offers new methods to query the effect of the operand constraints on the register class of a virtual register or on a given register class.
> The new API is used in MachineRegisterInfo::recomputeRegClass as well as in RAGreedy::tryInstructionSplit.

Thanks, Quentin.

This is looking good.

I think I would prefer to omit the MI::getLargest* functions. You will almost always be looking at multiple instructions, and I’m afraid it can get expensive to call getLargestLegalSuperClass() redundantly for all of them.

The getRegClassConstraintEffect* functions look great.

+  const TargetRegisterClass *SuperRC = TRI->getLargestLegalSuperClass(CurRC);
+  // Split around every non-copy instruction if this split will relax
+  // the constraints on the virtual register.
+  // Otherwise, splitting just inserts uncoalescable copies that do not help
+  // the allocation.
   for (unsigned i = 0; i != Uses.size(); ++i) {
     if (const MachineInstr *MI = Indexes->getInstructionFromIndex(Uses[i]))
-      if (MI->isFullCopy()) {
+      if (MI->isFullCopy() ||
+          SuperRC == MI->getLargestRegClassForVReg(VirtReg.reg, TII, TRI, MRI,
+                                                   /* ExploreBundle */ true)) {

Here, I would just pass SuperRC to MI->getRegClassConstraintEffectForVReg() instead.

Also, don’t compare the register classes by equality, but check that the returned register class actually has fewer allocatable registers. See for example GPR/rGPR on ARM. RegisterClassInfo::getNumAllocatableRegs() is very fast.

+  if (ExploreBundle && (isBundle() || isBundled())) {
+    MachineBasicBlock::const_instr_iterator I = this;
+    MachineBasicBlock::const_instr_iterator E = getParent()->instr_end();
+    while (CurRC && ++I != E && I->isInsideBundle())
+      // Accumulate the constraints through the instructions.
+      CurRC = I->getRegClassConstraintEffectForVRegImpl(Reg, CurRC, TII, TRI);
+  }

See MIBundleOperands.

Go ahead and commit with those changes.

Thanks,
/jakob





More information about the llvm-commits mailing list