@@ -377,57 +377,39 @@ SystemZRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator MI,
377
377
}
378
378
379
379
bool SystemZRegisterInfo::shouldCoalesce (MachineInstr *MI,
380
- const TargetRegisterClass *SrcRC,
381
- unsigned SubReg,
382
- const TargetRegisterClass *DstRC,
383
- unsigned DstSubReg,
384
- const TargetRegisterClass *NewRC,
385
- LiveIntervals &LIS) const {
380
+ const TargetRegisterClass *SrcRC,
381
+ unsigned SubReg,
382
+ const TargetRegisterClass *DstRC,
383
+ unsigned DstSubReg,
384
+ const TargetRegisterClass *NewRC,
385
+ LiveIntervals &LIS) const {
386
386
assert (MI->isCopy () && " Only expecting COPY instructions" );
387
387
388
388
// Coalesce anything which is not a COPY involving a subreg to/from GR128.
389
389
if (!(NewRC->hasSuperClassEq (&SystemZ::GR128BitRegClass) &&
390
390
(getRegSizeInBits (*SrcRC) <= 64 || getRegSizeInBits (*DstRC) <= 64 )))
391
391
return true ;
392
392
393
- // Allow coalescing of a GR128 subreg COPY only if the live ranges are small
394
- // and local to one MBB with not too much interferring registers . Otherwise
393
+ // Allow coalescing of a GR128 subreg COPY only if the subreg liverange is
394
+ // local to one MBB with not too many interferring physreg clobbers . Otherwise
395
395
// regalloc may run out of registers.
396
+ unsigned SubregOpIdx = getRegSizeInBits (*SrcRC) == 128 ? 0 : 1 ;
397
+ LiveInterval &LI = LIS.getInterval (MI->getOperand (SubregOpIdx).getReg ());
396
398
397
- unsigned WideOpNo = (getRegSizeInBits (*SrcRC) == 128 ? 1 : 0 );
398
- Register GR128Reg = MI->getOperand (WideOpNo).getReg ();
399
- Register GRNarReg = MI->getOperand ((WideOpNo == 1 ) ? 0 : 1 ).getReg ();
400
- LiveInterval &IntGR128 = LIS.getInterval (GR128Reg);
401
- LiveInterval &IntGRNar = LIS.getInterval (GRNarReg);
402
-
403
- // Check that the two virtual registers are local to MBB.
399
+ // Check that the subreg is local to MBB.
404
400
MachineBasicBlock *MBB = MI->getParent ();
405
- MachineInstr *FirstMI_GR128 =
406
- LIS.getInstructionFromIndex (IntGR128.beginIndex ());
407
- MachineInstr *FirstMI_GRNar =
408
- LIS.getInstructionFromIndex (IntGRNar.beginIndex ());
409
- MachineInstr *LastMI_GR128 = LIS.getInstructionFromIndex (IntGR128.endIndex ());
410
- MachineInstr *LastMI_GRNar = LIS.getInstructionFromIndex (IntGRNar.endIndex ());
411
- if ((!FirstMI_GR128 || FirstMI_GR128->getParent () != MBB) ||
412
- (!FirstMI_GRNar || FirstMI_GRNar->getParent () != MBB) ||
413
- (!LastMI_GR128 || LastMI_GR128->getParent () != MBB) ||
414
- (!LastMI_GRNar || LastMI_GRNar->getParent () != MBB))
401
+ MachineInstr *FirstMI = LIS.getInstructionFromIndex (LI.beginIndex ());
402
+ MachineInstr *LastMI = LIS.getInstructionFromIndex (LI.endIndex ());
403
+ if (!FirstMI || FirstMI->getParent () != MBB ||
404
+ !LastMI || LastMI->getParent () != MBB)
415
405
return false ;
416
406
417
- MachineBasicBlock::iterator MII = nullptr , MEE = nullptr ;
418
- if (WideOpNo == 1 ) {
419
- MII = FirstMI_GR128;
420
- MEE = LastMI_GRNar;
421
- } else {
422
- MII = FirstMI_GRNar;
423
- MEE = LastMI_GR128;
424
- }
425
-
426
407
// Check if coalescing seems safe by finding the set of clobbered physreg
427
408
// pairs in the region.
428
409
BitVector PhysClobbered (getNumRegs ());
429
- MEE++;
430
- for (; MII != MEE; ++MII) {
410
+ for (MachineBasicBlock::iterator MII = FirstMI,
411
+ MEE = std::next (LastMI->getIterator ());
412
+ MII != MEE; ++MII)
431
413
for (const MachineOperand &MO : MII->operands ())
432
414
if (MO.isReg () && MO.getReg ().isPhysical ()) {
433
415
for (MCPhysReg SI : superregs_inclusive (MO.getReg ()))
@@ -436,7 +418,6 @@ bool SystemZRegisterInfo::shouldCoalesce(MachineInstr *MI,
436
418
break ;
437
419
}
438
420
}
439
- }
440
421
441
422
// Demand an arbitrary margin of free regs.
442
423
unsigned const DemandedFreeGR128 = 3 ;
0 commit comments