@@ -1322,6 +1322,15 @@ bool SimpleRegisterCoalescing::JoinCopy(CopyRec &TheCopy, bool &Again) {
1322
1322
DOUT << " and " ; DstInt.print (DOUT, tri_);
1323
1323
DOUT << " : " ;
1324
1324
1325
+ // Save a copy of the virtual register live interval. We'll manually
1326
+ // merge this into the "real" physical register live interval this is
1327
+ // coalesced with.
1328
+ LiveInterval *SavedLI = 0 ;
1329
+ if (RealDstReg)
1330
+ SavedLI = li_->dupInterval (&SrcInt);
1331
+ else if (RealSrcReg)
1332
+ SavedLI = li_->dupInterval (&DstInt);
1333
+
1325
1334
// Check if it is necessary to propagate "isDead" property.
1326
1335
if (!isExtSubReg && !isInsSubReg) {
1327
1336
MachineOperand *mopd = CopyMI->findRegisterDefOperand (DstReg, false );
@@ -1413,21 +1422,17 @@ bool SimpleRegisterCoalescing::JoinCopy(CopyRec &TheCopy, bool &Again) {
1413
1422
if (RealDstReg || RealSrcReg) {
1414
1423
LiveInterval &RealInt =
1415
1424
li_->getOrCreateInterval (RealDstReg ? RealDstReg : RealSrcReg);
1416
- SmallSet<const VNInfo*, 4 > CopiedValNos;
1417
- for (LiveInterval::Ranges::const_iterator I = ResSrcInt->ranges .begin (),
1418
- E = ResSrcInt->ranges .end (); I != E; ++I) {
1419
- const LiveRange *DstLR = ResDstInt->getLiveRangeContaining (I->start );
1420
- assert (DstLR && " Invalid joined interval!" );
1421
- const VNInfo *DstValNo = DstLR->valno ;
1422
- if (CopiedValNos.insert (DstValNo)) {
1423
- VNInfo *ValNo = RealInt.getNextValue (DstValNo->def , DstValNo->copy ,
1424
- li_->getVNInfoAllocator ());
1425
- ValNo->hasPHIKill = DstValNo->hasPHIKill ;
1426
- RealInt.addKills (ValNo, DstValNo->kills );
1427
- RealInt.MergeValueInAsValue (*ResDstInt, DstValNo, ValNo);
1428
- }
1425
+ for (LiveInterval::const_vni_iterator I = SavedLI->vni_begin (),
1426
+ E = SavedLI->vni_end (); I != E; ++I) {
1427
+ const VNInfo *ValNo = *I;
1428
+ VNInfo *NewValNo = RealInt.getNextValue (ValNo->def , ValNo->copy ,
1429
+ li_->getVNInfoAllocator ());
1430
+ NewValNo->hasPHIKill = ValNo->hasPHIKill ;
1431
+ NewValNo->redefByEC = ValNo->redefByEC ;
1432
+ RealInt.addKills (NewValNo, ValNo->kills );
1433
+ RealInt.MergeValueInAsValue (*SavedLI, ValNo, NewValNo);
1429
1434
}
1430
-
1435
+ RealInt. weight += SavedLI-> weight ;
1431
1436
DstReg = RealDstReg ? RealDstReg : RealSrcReg;
1432
1437
}
1433
1438
@@ -1497,6 +1502,12 @@ bool SimpleRegisterCoalescing::JoinCopy(CopyRec &TheCopy, bool &Again) {
1497
1502
// being merged.
1498
1503
li_->removeInterval (SrcReg);
1499
1504
1505
+ // Manually deleted the live interval copy.
1506
+ if (SavedLI) {
1507
+ SavedLI->clear ();
1508
+ delete SavedLI;
1509
+ }
1510
+
1500
1511
if (isEmpty) {
1501
1512
// Now the copy is being coalesced away, the val# previously defined
1502
1513
// by the copy is being defined by an IMPLICIT_DEF which defines a zero
0 commit comments