@@ -406,62 +406,23 @@ void VirtRegRewriter::expandCopyBundle(MachineInstr &MI) const {
406
406
return ;
407
407
408
408
if (MI.isBundledWithPred () && !MI.isBundledWithSucc ()) {
409
- SmallVector<MachineInstr *, 2 > MIs ({&MI});
410
-
411
409
// Only do this when the complete bundle is made out of COPYs.
412
410
MachineBasicBlock &MBB = *MI.getParent ();
413
411
for (MachineBasicBlock::reverse_instr_iterator I =
414
412
std::next (MI.getReverseIterator ()), E = MBB.instr_rend ();
415
413
I != E && I->isBundledWithSucc (); ++I) {
416
414
if (!I->isCopy ())
417
415
return ;
418
- MIs.push_back (&*I);
419
- }
420
- MachineInstr *FirstMI = MIs.back ();
421
-
422
- auto anyRegsAlias = [](const MachineInstr *Dst,
423
- ArrayRef<MachineInstr *> Srcs,
424
- const TargetRegisterInfo *TRI) {
425
- for (const MachineInstr *Src : Srcs)
426
- if (Src != Dst)
427
- if (TRI->regsOverlap (Dst->getOperand (0 ).getReg (),
428
- Src->getOperand (1 ).getReg ()))
429
- return true ;
430
- return false ;
431
- };
432
-
433
- // If any of the destination registers in the bundle of copies alias any of
434
- // the source registers, try to schedule the instructions to avoid any
435
- // clobbering.
436
- for (int E = MIs.size (), PrevE; E > 1 ; PrevE = E) {
437
- for (int I = E; I--; )
438
- if (!anyRegsAlias (MIs[I], makeArrayRef (MIs).take_front (E), TRI)) {
439
- if (I + 1 != E)
440
- std::swap (MIs[I], MIs[E - 1 ]);
441
- --E;
442
- }
443
- if (PrevE == E) {
444
- MF->getFunction ().getContext ().emitError (
445
- " register rewriting failed: cycle in copy bundle" );
446
- break ;
447
- }
448
416
}
449
417
450
- MachineInstr *BundleStart = FirstMI;
451
- for (MachineInstr *BundledMI : llvm::reverse (MIs)) {
452
- // If instruction is in the middle of the bundle, move it before the
453
- // bundle starts, otherwise, just unbundle it. When we get to the last
454
- // instruction, the bundle will have been completely undone.
455
- if (BundledMI != BundleStart) {
456
- BundledMI->removeFromBundle ();
457
- MBB.insert (FirstMI, BundledMI);
458
- } else if (BundledMI->isBundledWithSucc ()) {
459
- BundledMI->unbundleFromSucc ();
460
- BundleStart = &*std::next (BundledMI->getIterator ());
461
- }
418
+ for (MachineBasicBlock::reverse_instr_iterator I = MI.getReverseIterator ();
419
+ I->isBundledWithPred (); ) {
420
+ MachineInstr &MI = *I;
421
+ ++I;
462
422
463
- if (Indexes && BundledMI != FirstMI)
464
- Indexes->insertMachineInstrInMaps (*BundledMI);
423
+ MI.unbundleFromPred ();
424
+ if (Indexes)
425
+ Indexes->insertMachineInstrInMaps (MI);
465
426
}
466
427
}
467
428
}
0 commit comments