summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp28
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp22
2 files changed, 32 insertions, 18 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 879145cea6b..da9167f06a4 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -2529,6 +2529,34 @@ void llvm::dropDebugUsers(Instruction &I) {
DII->eraseFromParent();
}
+void llvm::hoistAllInstructionsInto(BasicBlock *DomBlock,Instruction *InsertPt,
+ BasicBlock *IfBlock) {
+ // Since we are moving the instructions out of its basic block, we do not
+ // retain their original debug locations (DILocations) and debug intrinsic
+ // instructions (dbg.values).
+ //
+ // Doing so would degrade the debugging experience and adversely affect the
+ // accuracy of profiling information.
+ //
+ // Currently, when hoisting the instructions, we take the following actions:
+ // - Remove their dbg.values.
+ // - Set their debug locations to the values from the insertion point.
+ //
+ // See PR38762 for more details.
+ //
+ // TODO: Extend llvm.dbg.value to take more than one SSA Value (PR39141) to
+ // encode predicated DIExpressions that yield different results on different
+ // code paths.
+ for (auto &I : *IfBlock) {
+ I.dropUnknownNonDebugMetadata();
+ dropDebugUsers(I);
+ I.setDebugLoc(InsertPt->getDebugLoc());
+ }
+ DomBlock->getInstList().splice(InsertPt->getIterator(),
+ IfBlock->getInstList(), IfBlock->begin(),
+ IfBlock->getTerminator()->getIterator());
+}
+
namespace {
/// A potential constituent of a bitreverse or bswap expression. See
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index ebbcf800254..3e73c537292 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2375,24 +2375,10 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
// Move all 'aggressive' instructions, which are defined in the
// conditional parts of the if's up to the dominating block.
- if (IfBlock1) {
- for (auto &I : *IfBlock1) {
- I.dropUnknownNonDebugMetadata();
- dropDebugUsers(I);
- }
- DomBlock->getInstList().splice(InsertPt->getIterator(),
- IfBlock1->getInstList(), IfBlock1->begin(),
- IfBlock1->getTerminator()->getIterator());
- }
- if (IfBlock2) {
- for (auto &I : *IfBlock2) {
- I.dropUnknownNonDebugMetadata();
- dropDebugUsers(I);
- }
- DomBlock->getInstList().splice(InsertPt->getIterator(),
- IfBlock2->getInstList(), IfBlock2->begin(),
- IfBlock2->getTerminator()->getIterator());
- }
+ if (IfBlock1)
+ hoistAllInstructionsInto(DomBlock, InsertPt, IfBlock1);
+ if (IfBlock2)
+ hoistAllInstructionsInto(DomBlock, InsertPt, IfBlock2);
while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) {
// Change the PHI node into a select instruction.
OpenPOWER on IntegriCloud