From: Jakob Stoklund Olesen Date: Fri, 29 Oct 2010 00:40:59 +0000 (+0000) Subject: Fix broken equivalence class calculation. We could probably also use X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=eeaae20be02979a5d1459cc479c4533be3c05ed5;p=oota-llvm.git Fix broken equivalence class calculation. We could probably also use EquvivalenceClasses.h except it looks like overkill when elements are continuous integers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117631 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/LiveInterval.cpp b/lib/CodeGen/LiveInterval.cpp index 6fb60362be6..27a572c0ea7 100644 --- a/lib/CodeGen/LiveInterval.cpp +++ b/lib/CodeGen/LiveInterval.cpp @@ -709,15 +709,14 @@ void LiveRange::print(raw_ostream &os) const { /// multiple LiveIntervals. void ConnectedVNInfoEqClasses::Connect(unsigned a, unsigned b) { - unsigned eqa = eqClass_[a]; - unsigned eqb = eqClass_[b]; - if (eqa == eqb) - return; - // Make sure a and b are in the same class while maintaining eqClass_[i] <= i. - if (eqa > eqb) - eqClass_[a] = eqb; - else - eqClass_[b] = eqa; + while (eqClass_[a] != eqClass_[b]) { + if (eqClass_[a] > eqClass_[b]) + std::swap(a, b); + unsigned t = eqClass_[b]; + assert(t <= b && "Invariant broken"); + eqClass_[b] = eqClass_[a]; + b = t; + } } unsigned ConnectedVNInfoEqClasses::Renumber() { @@ -745,8 +744,6 @@ unsigned ConnectedVNInfoEqClasses::Classify(const LiveInterval *LI) { for (LiveInterval::const_vni_iterator I = LI->vni_begin(), E = LI->vni_end(); I != E; ++I) { const VNInfo *VNI = *I; - if (VNI->id == eqClass_.size()) - eqClass_.push_back(VNI->id); assert(!VNI->isUnused() && "Cannot handle unused values"); if (VNI->isPHIDef()) { const MachineBasicBlock *MBB = lis_.getMBBFromIndex(VNI->def);