diff options
-rw-r--r-- | polly/lib/IndependentBlocks.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/polly/lib/IndependentBlocks.cpp b/polly/lib/IndependentBlocks.cpp index 69d79424293..cb636486a90 100644 --- a/polly/lib/IndependentBlocks.cpp +++ b/polly/lib/IndependentBlocks.cpp @@ -394,9 +394,16 @@ bool IndependentBlocks::translateScalarToArray(Instruction *Inst, AllocaInst *Slot = new AllocaInst( Inst->getType(), 0, Inst->getName() + ".s2a", AllocaBlock->begin()); assert(!isa<InvokeInst>(Inst) && "Unexpect Invoke in Scop!"); - // Store right after Inst. - BasicBlock::iterator StorePos = Inst; - (void) new StoreInst(Inst, Slot, ++StorePos); + + // Store right after Inst, and make sure the position is after all phi nodes. + BasicBlock::iterator StorePos; + if (isa<PHINode>(Inst)) { + StorePos = Inst->getParent()->getFirstNonPHI(); + } else { + StorePos = Inst; + StorePos++; + } + (void) new StoreInst(Inst, Slot, StorePos); if (!LoadOutside.empty()) { LoadInst *ExitLoad = new LoadInst(Slot, Inst->getName() + ".loadoutside", |