Fix PR5258, jump-threading creating invalid PHIs.

When an incoming value for a PHI is updated, we must also updated all other
incoming values for the same BB to match, otherwise we create invalid PHIs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84638 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Torok Edwin
2009-10-20 15:42:00 +00:00
parent 2b6183d254
commit f993327e71
2 changed files with 358 additions and 2 deletions

View File

@ -178,10 +178,18 @@ Value *SSAUpdater::GetValueInMiddleOfBlock(BasicBlock *BB) {
void SSAUpdater::RewriteUse(Use &U) {
Instruction *User = cast<Instruction>(U.getUser());
BasicBlock *UseBB = User->getParent();
if (PHINode *UserPN = dyn_cast<PHINode>(User))
PHINode *UserPN = dyn_cast<PHINode>(User);
if (UserPN)
UseBB = UserPN->getIncomingBlock(U);
U.set(GetValueInMiddleOfBlock(UseBB));
Value *V = GetValueInMiddleOfBlock(UseBB);
U.set(V);
if (UserPN) {
// Incoming value from the same BB must be consistent
for (unsigned i=0;i<UserPN->getNumIncomingValues();i++)
if (UserPN->getIncomingBlock(i) == UseBB)
UserPN->setIncomingValue(i, V);
}
}