diff options
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 849f9ee1d19..af9d2eaf253 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1372,6 +1372,14 @@ HoistTerminator: } } + // As the parent basic block terminator is a branch instruction which is + // removed at the end of the current transformation, use its previous + // non-debug instruction, as the reference insertion point, which will + // provide the debug location for the instruction being hoisted. For BBs + // with only debug instructions, use an empty debug location. + Instruction *InsertPt = + BIParent->getTerminator()->getPrevNonDebugInstruction(); + // Okay, it is safe to hoist the terminator. Instruction *NT = I1->clone(); BIParent->getInstList().insert(BI->getIterator(), NT); @@ -1381,6 +1389,14 @@ HoistTerminator: NT->takeName(I1); } + // The instruction NT being hoisted, is the terminator for the true branch, + // with debug location (DILocation) within that branch. We can't retain + // its original debug location value, otherwise 'select' instructions that + // are created from any PHI nodes, will take its debug location, giving + // the impression that those 'select' instructions are in the true branch, + // causing incorrect stepping, affecting the debug experience. + NT->setDebugLoc(InsertPt ? InsertPt->getDebugLoc() : DebugLoc()); + IRBuilder<NoFolder> Builder(NT); // Hoisting one of the terminators from our successor is a great thing. // Unfortunately, the successors of the if/else blocks may have PHI nodes in |