From ba4e437c6ad18746cd2684410c6679be7d1376e4 Mon Sep 17 00:00:00 2001 From: Carlos Alberto Enciso Date: Wed, 19 Sep 2018 08:16:56 +0000 Subject: [DebugInfo][Dexter] Speculated BB presents illegal variable value to debugger. When SimplifyCFG changes the PHI node into a select instruction, the debug information becomes ambiguous. It causes the debugger to display wrong variable value. Differential Revision: https://reviews.llvm.org/D51976 llvm-svn: 342527 --- llvm/lib/Transforms/Utils/Local.cpp | 7 +++++++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index c65a0b7a436..879145cea6b 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -2522,6 +2522,13 @@ void llvm::copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, } } +void llvm::dropDebugUsers(Instruction &I) { + SmallVector DbgUsers; + findDbgUsers(DbgUsers, &I); + for (auto *DII : DbgUsers) + DII->eraseFromParent(); +} + 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 422d1c9ef0a..493d1688226 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -2370,15 +2370,19 @@ 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) + 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) + for (auto &I : *IfBlock2) { I.dropUnknownNonDebugMetadata(); + dropDebugUsers(I); + } DomBlock->getInstList().splice(InsertPt->getIterator(), IfBlock2->getInstList(), IfBlock2->begin(), IfBlock2->getTerminator()->getIterator()); -- cgit v1.2.3