summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/CorrelatedExprs.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-09-23 20:06:22 +0000
committerChris Lattner <sabre@nondot.org>2002-09-23 20:06:22 +0000
commitc017d9132a6318085efbbb1ccd7894168ea20d96 (patch)
tree13bb41c022ac62160a0a00c36127257b4462a862 /lib/Transforms/Scalar/CorrelatedExprs.cpp
parentcba39ca9fe3dc10ad9adcdd000f002271db86adc (diff)
downloadllvm-c017d9132a6318085efbbb1ccd7894168ea20d96.tar.gz
llvm-c017d9132a6318085efbbb1ccd7894168ea20d96.tar.bz2
llvm-c017d9132a6318085efbbb1ccd7894168ea20d96.tar.xz
* Fix bug: CorrelatedExprs/2002-09-23-PHIUpdateBug.ll
* Make sure "Changed" is updated correctly git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3891 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/CorrelatedExprs.cpp')
-rw-r--r--lib/Transforms/Scalar/CorrelatedExprs.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/Transforms/Scalar/CorrelatedExprs.cpp b/lib/Transforms/Scalar/CorrelatedExprs.cpp
index 6d26ffd861..9be508d3a8 100644
--- a/lib/Transforms/Scalar/CorrelatedExprs.cpp
+++ b/lib/Transforms/Scalar/CorrelatedExprs.cpp
@@ -23,6 +23,7 @@
#include "llvm/Pass.h"
#include "llvm/Function.h"
#include "llvm/iTerminators.h"
+#include "llvm/iPHINode.h"
#include "llvm/iOperators.h"
#include "llvm/ConstantHandling.h"
#include "llvm/Assembly/Writer.h"
@@ -349,20 +350,34 @@ bool CEE::TransformRegion(BasicBlock *BB, std::set<BasicBlock*> &VisitedBlocks){
// another conditional branch, one whose outcome is known inside of this
// region, then vector this outgoing edge directly to the known destination.
//
- for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) {
+ for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
while (BasicBlock *Dest = isCorrelatedBranchBlock(TI->getSuccessor(i), RI)){
+ // If there are any PHI nodes in the Dest BB, we must duplicate the entry
+ // in the PHI node for the old successor to now include an entry from the
+ // current basic block.
+ //
+ BasicBlock *OldSucc = TI->getSuccessor(i);
+
+ // Loop over all of the PHI nodes...
+ for (BasicBlock::iterator I = Dest->begin();
+ PHINode *PN = dyn_cast<PHINode>(&*I); ++I) {
+ // Find the entry in the PHI node for OldSucc, create a duplicate entry
+ // for BB now.
+ int BlockIndex = PN->getBasicBlockIndex(OldSucc);
+ assert(BlockIndex != -1 && "Block should have entry in PHI!");
+ PN->addIncoming(PN->getIncomingValue(BlockIndex), BB);
+ }
+
+ // Actually revector the branch now...
TI->setSuccessor(i, Dest);
++BranchRevectors;
+ Changed = true;
}
- }
// Now that all of our successors have information, recursively process them.
for (unsigned i = 0, e = BBN->getChildren().size(); i != e; ++i)
Changed |= TransformRegion(BBN->getChildren()[i]->getNode(), VisitedBlocks);
- // for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
- //Changed |= TransformRegion(TI->getSuccessor(i), VisitedBlocks);
-
return Changed;
}