Skip to content

Commit 4eda2cb

Browse files
committed
MergeValueInto is too smart: it might choose to do the merge the opposite direction.
Live interval reconstruction needs to account for this, and scour its maps to prevent dangling references. llvm-svn: 63558
1 parent 026bcde commit 4eda2cb

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

llvm/include/llvm/CodeGen/LiveInterval.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ namespace llvm {
276276
/// are found to be equivalent. This eliminates V1, replacing all
277277
/// LiveRanges with the V1 value number with the V2 value number. This can
278278
/// cause merging of V1/V2 values numbers and compaction of the value space.
279-
void MergeValueNumberInto(VNInfo *V1, VNInfo *V2);
279+
VNInfo* MergeValueNumberInto(VNInfo *V1, VNInfo *V2);
280280

281281
/// MergeInClobberRanges - For any live ranges that are not defined in the
282282
/// current interval, but are defined in the Clobbers interval, mark them

llvm/lib/CodeGen/LiveInterval.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ void LiveInterval::MergeInClobberRanges(const LiveInterval &Clobbers,
591591
/// are found to be equivalent. This eliminates V1, replacing all
592592
/// LiveRanges with the V1 value number with the V2 value number. This can
593593
/// cause merging of V1/V2 values numbers and compaction of the value space.
594-
void LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
594+
VNInfo* LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
595595
assert(V1 != V2 && "Identical value#'s are always equivalent!");
596596

597597
// This code actually merges the (numerically) larger value number into the
@@ -652,6 +652,8 @@ void LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
652652
} else {
653653
V1->def = ~1U;
654654
}
655+
656+
return V2;
655657
}
656658

657659
void LiveInterval::Copy(const LiveInterval &RHS,

llvm/lib/CodeGen/PreAllocSplitting.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,24 @@ PreAllocSplitting::PerformPHIConstructionFallBack(MachineBasicBlock::iterator Us
654654
}
655655

656656
if (MBB->pred_size() == 1 && !RetVNI->hasPHIKill) {
657-
LI->MergeValueNumberInto(RetVNI, IncomingVNs.begin()->second);
658-
Phis[MBB] = RetVNI = IncomingVNs.begin()->second;
657+
VNInfo* OldVN = RetVNI;
658+
VNInfo* NewVN = IncomingVNs.begin()->second;
659+
VNInfo* MergedVN = LI->MergeValueNumberInto(OldVN, NewVN);
660+
if (MergedVN == OldVN) std::swap(OldVN, NewVN);
661+
662+
for (DenseMap<MachineBasicBlock*, VNInfo*>::iterator LOI = LiveOut.begin(),
663+
LOE = LiveOut.end(); LOI != LOE; ++LOI)
664+
if (LOI->second == OldVN)
665+
LOI->second = MergedVN;
666+
for (DenseMap<MachineInstr*, VNInfo*>::iterator NVI = NewVNs.begin(),
667+
NVE = NewVNs.end(); NVI != NVE; ++NVI)
668+
if (NVI->second == OldVN)
669+
NVI->second = MergedVN;
670+
for (DenseMap<MachineBasicBlock*, VNInfo*>::iterator PI = Phis.begin(),
671+
PE = Phis.end(); PI != PE; ++PI)
672+
if (PI->second == OldVN)
673+
PI->second = MergedVN;
674+
RetVNI = MergedVN;
659675
} else {
660676
// Otherwise, merge the incoming VNInfos with a phi join. Create a new
661677
// VNInfo to represent the joined value.

0 commit comments

Comments
 (0)