Fix SSAUpdaterImpl's RecordMatchingPHI to record exactly the

PHI nodes which were matched, rather than climbing up the
original PHI node's operands to rediscover PHI nodes for
recording, since the PHI nodes found that are not
necessarily part of the matched set.
This fixes rdar://10589171.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149654 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2012-02-03 01:07:01 +00:00
parent 1aee22e072
commit 16717a7c56
2 changed files with 88 additions and 32 deletions

View File

@ -380,7 +380,7 @@ public:
if (!SomePHI)
break;
if (CheckIfPHIMatches(SomePHI)) {
RecordMatchingPHI(SomePHI);
RecordMatchingPHIs(BlockList);
break;
}
// Match failed: clear all the PHITag values.
@ -437,38 +437,17 @@ public:
return true;
}
/// RecordMatchingPHI - For a PHI node that matches, record it and its input
/// PHIs in both the BBMap and the AvailableVals mapping.
void RecordMatchingPHI(PhiT *PHI) {
SmallVector<PhiT*, 20> WorkList;
WorkList.push_back(PHI);
// Record this PHI.
BlkT *BB = PHI->getParent();
ValT PHIVal = Traits::GetPHIValue(PHI);
(*AvailableVals)[BB] = PHIVal;
BBMap[BB]->AvailableVal = PHIVal;
while (!WorkList.empty()) {
PHI = WorkList.pop_back_val();
// Iterate through the PHI's incoming values.
for (typename Traits::PHI_iterator I = Traits::PHI_begin(PHI),
E = Traits::PHI_end(PHI); I != E; ++I) {
ValT IncomingVal = I.getIncomingValue();
PhiT *IncomingPHI = Traits::ValueIsPHI(IncomingVal, Updater);
if (!IncomingPHI) continue;
BB = IncomingPHI->getParent();
BBInfo *Info = BBMap[BB];
if (!Info || Info->AvailableVal)
continue;
// Record the PHI and add it to the worklist.
(*AvailableVals)[BB] = IncomingVal;
Info->AvailableVal = IncomingVal;
WorkList.push_back(IncomingPHI);
/// RecordMatchingPHIs - For each PHI node that matches, record it in both
/// the BBMap and the AvailableVals mapping.
void RecordMatchingPHIs(BlockListTy *BlockList) {
for (typename BlockListTy::iterator I = BlockList->begin(),
E = BlockList->end(); I != E; ++I)
if (PhiT *PHI = (*I)->PHITag) {
BlkT *BB = PHI->getParent();
ValT PHIVal = Traits::GetPHIValue(PHI);
(*AvailableVals)[BB] = PHIVal;
BBMap[BB]->AvailableVal = PHIVal;
}
}
}
};