diff options
author | Chris Lattner <sabre@nondot.org> | 2004-04-01 20:28:45 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-04-01 20:28:45 +0000 |
commit | c24019c825936d26c5fa243115b8a8024c49f247 (patch) | |
tree | d7ede76270797875b96a3382432abe6e2178657d /llvm/lib/Transforms/Utils/DemoteRegToStack.cpp | |
parent | 914a7d0d90d758aa35842bef2524e6645d859a38 (diff) | |
download | llvm-c24019c825936d26c5fa243115b8a8024c49f247.zip llvm-c24019c825936d26c5fa243115b8a8024c49f247.tar.gz llvm-c24019c825936d26c5fa243115b8a8024c49f247.tar.bz2 |
Fix PR310 and TailDup/2004-04-01-DemoteRegToStack.llx
llvm-svn: 12597
Diffstat (limited to 'llvm/lib/Transforms/Utils/DemoteRegToStack.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/DemoteRegToStack.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp b/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp index ea0cf83..a92a066 100644 --- a/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp +++ b/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp @@ -19,6 +19,7 @@ #include "llvm/Transforms/Utils/Local.h" #include "llvm/Function.h" #include "llvm/Instructions.h" +#include <map> using namespace llvm; /// DemoteRegToStack - This function takes a virtual register computed by an @@ -45,13 +46,19 @@ AllocaInst* llvm::DemoteRegToStack(Instruction &I) { // to the incoming value. // // Note that if there are multiple edges from a basic block to this PHI - // node that we'll insert multiple loads. Since DemoteRegToStack requires - // a mem2reg pass after it (to produce reasonable code), we don't care. + // node that we cannot multiple loads. The problem is that the resultant + // PHI node will have multiple values (from each load) coming in from the + // same block, which is illegal SSA form. For this reason, we keep track + // and reuse loads we insert. + std::map<BasicBlock*, Value*> Loads; for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) if (PN->getIncomingValue(i) == &I) { - // Insert the load into the predecessor block - Value *V = new LoadInst(Slot, I.getName()+".reload", - PN->getIncomingBlock(i)->getTerminator()); + Value *&V = Loads[PN->getIncomingBlock(i)]; + if (V == 0) { + // Insert the load into the predecessor block + V = new LoadInst(Slot, I.getName()+".reload", + PN->getIncomingBlock(i)->getTerminator()); + } PN->setIncomingValue(i, V); } |