From 8f2514f11615b32b861bd503c826a599b37bd220 Mon Sep 17 00:00:00 2001 From: Jeremy Morse Date: Mon, 14 Jan 2019 12:13:12 +0000 Subject: [PATCH] [DebugInfo] Remove un-necessary logic from HoistThenElseCodeToIf Following PR39807, the way in which SimplifyCFG hoists common code on branch paths was fixed in r347782. However this left extra code hanging around HoistThenElseCodeToIf that wasn't necessary and needlessly complicated matters -- we no longer need to look up through the 'if' basic block to find a location for hoisted 'select' insts, we can instead use the location chosen by applyMergedLocation. This patch deletes that extra logic, and updates a regression test to reflect the new logic (selects get the merged location, not a previous insts location). Differential Revision: https://reviews.llvm.org/D55272 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351058 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/SimplifyCFG.cpp | 13 +------------ test/CodeGen/X86/pr39187-g.ll | 27 +++++++-------------------- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index ac09ce5a347..03b73954321 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1373,14 +1373,6 @@ 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 generated select instructions. 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); @@ -1394,11 +1386,8 @@ HoistTerminator: // it involves inlinable calls. NT->applyMergedLocation(I1->getDebugLoc(), I2->getDebugLoc()); + // PHIs created below will adopt NT's merged DebugLoc. IRBuilder Builder(NT); - // If an earlier instruction in this BB had a location, adopt it, otherwise - // clear debug locations. - Builder.SetCurrentDebugLocation(InsertPt ? InsertPt->getDebugLoc() - : DebugLoc()); // 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 diff --git a/test/CodeGen/X86/pr39187-g.ll b/test/CodeGen/X86/pr39187-g.ll index 46da6411122..2c9dcc5dfff 100644 --- a/test/CodeGen/X86/pr39187-g.ll +++ b/test/CodeGen/X86/pr39187-g.ll @@ -7,22 +7,8 @@ ; location keep references to its basic block, causing the debug information ; to become ambiguous. It causes the debugger to display unreached lines. -; Change the debug location associated with the hoisted instruction, to -; the debug location from the insertion point in the 'if' block. - -; The insertion point is the previous non-debug instruction before the -; terminator in the parent basic block of the hoisted instruction. - -; IR with '-g': -; -; [...] -; %frombool = zext i1 %cmp to i8, !dbg !26 -; call void @llvm.dbg.value(metadata i8 %frombool, metadata !15, metadata !DIExpression()), !dbg !26 -; call void @llvm.dbg.value(metadata i32 0, metadata !17, metadata !DIExpression()), !dbg !27 -; br i1 %cmp, label %if.then, label %if.else -; [...] -; -; Insertion point is: %frombool = zext i1 %cmp to i8, !dbg !26 +; Check that hoisted instructions get unknown-location line numbers -- there +; is no correct line number for code that has been common'd in this way. ; IR generated with: ; clang -S -g -gno-column-info -O2 -emit-llvm pr39187.cpp -o pr39187-g.ll -mllvm -opt-bisect-limit=10 @@ -54,7 +40,8 @@ ; CHECK: %frombool = zext i1 %cmp to i8, !dbg !16 ; CHECK: call void @llvm.dbg.value(metadata i8 %frombool, metadata !13, metadata !DIExpression()), !dbg !16 ; CHECK: call void @llvm.dbg.value(metadata i32 0, metadata !15, metadata !DIExpression()), !dbg !17 -; CHECK: %. = select i1 %cmp, i32 8, i32 4, !dbg !16 +; CHECK: %. = select i1 %cmp, i32 8, i32 4, !dbg ![[MERGEDLOC:[0-9]+]] +; CHECK: ![[MERGEDLOC]] = !DILocation(line: 0, scope: !7) ; ModuleID = 'pr39187.cpp' source_filename = "pr39187.cpp" @@ -77,11 +64,11 @@ entry: if.then: ; preds = %entry call void @llvm.dbg.value(metadata i32 8, metadata !14, metadata !DIExpression()), !dbg !25 - br label %if.end + br label %if.end, !dbg !25 if.else: ; preds = %entry - call void @llvm.dbg.value(metadata i32 4, metadata !14, metadata !DIExpression()), !dbg !25 - br label %if.end + call void @llvm.dbg.value(metadata i32 4, metadata !14, metadata !DIExpression()), !dbg !27 + br label %if.end, !dbg !27 if.end: ; preds = %if.else, %if.then %beards.0 = phi i32 [ 8, %if.then ], [ 4, %if.else ] -- 2.50.1