llvm.org GIT mirror llvm / 8f2514f
[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 Jeremy Morse 9 months ago
2 changed file(s) with 8 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
13721372 }
13731373 }
13741374
1375 // As the parent basic block terminator is a branch instruction which is
1376 // removed at the end of the current transformation, use its previous
1377 // non-debug instruction, as the reference insertion point, which will
1378 // provide the debug location for generated select instructions. For BBs
1379 // with only debug instructions, use an empty debug location.
1380 Instruction *InsertPt =
1381 BIParent->getTerminator()->getPrevNonDebugInstruction();
1382
13831375 // Okay, it is safe to hoist the terminator.
13841376 Instruction *NT = I1->clone();
13851377 BIParent->getInstList().insert(BI->getIterator(), NT);
13931385 // it involves inlinable calls.
13941386 NT->applyMergedLocation(I1->getDebugLoc(), I2->getDebugLoc());
13951387
1388 // PHIs created below will adopt NT's merged DebugLoc.
13961389 IRBuilder Builder(NT);
1397 // If an earlier instruction in this BB had a location, adopt it, otherwise
1398 // clear debug locations.
1399 Builder.SetCurrentDebugLocation(InsertPt ? InsertPt->getDebugLoc()
1400 : DebugLoc());
14011390
14021391 // Hoisting one of the terminators from our successor is a great thing.
14031392 // Unfortunately, the successors of the if/else blocks may have PHI nodes in
66 ; location keep references to its basic block, causing the debug information
77 ; to become ambiguous. It causes the debugger to display unreached lines.
88
9 ; Change the debug location associated with the hoisted instruction, to
10 ; the debug location from the insertion point in the 'if' block.
11
12 ; The insertion point is the previous non-debug instruction before the
13 ; terminator in the parent basic block of the hoisted instruction.
14
15 ; IR with '-g':
16 ;
17 ; [...]
18 ; %frombool = zext i1 %cmp to i8, !dbg !26
19 ; call void @llvm.dbg.value(metadata i8 %frombool, metadata !15, metadata !DIExpression()), !dbg !26
20 ; call void @llvm.dbg.value(metadata i32 0, metadata !17, metadata !DIExpression()), !dbg !27
21 ; br i1 %cmp, label %if.then, label %if.else
22 ; [...]
23 ;
24 ; Insertion point is: %frombool = zext i1 %cmp to i8, !dbg !26
9 ; Check that hoisted instructions get unknown-location line numbers -- there
10 ; is no correct line number for code that has been common'd in this way.
2511
2612 ; IR generated with:
2713 ; clang -S -g -gno-column-info -O2 -emit-llvm pr39187.cpp -o pr39187-g.ll -mllvm -opt-bisect-limit=10
5339 ; CHECK: %frombool = zext i1 %cmp to i8, !dbg !16
5440 ; CHECK: call void @llvm.dbg.value(metadata i8 %frombool, metadata !13, metadata !DIExpression()), !dbg !16
5541 ; CHECK: call void @llvm.dbg.value(metadata i32 0, metadata !15, metadata !DIExpression()), !dbg !17
56 ; CHECK: %. = select i1 %cmp, i32 8, i32 4, !dbg !16
42 ; CHECK: %. = select i1 %cmp, i32 8, i32 4, !dbg ![[MERGEDLOC:[0-9]+]]
43 ; CHECK: ![[MERGEDLOC]] = !DILocation(line: 0, scope: !7)
5744
5845 ; ModuleID = 'pr39187.cpp'
5946 source_filename = "pr39187.cpp"
7663
7764 if.then: ; preds = %entry
7865 call void @llvm.dbg.value(metadata i32 8, metadata !14, metadata !DIExpression()), !dbg !25
79 br label %if.end
66 br label %if.end, !dbg !25
8067
8168 if.else: ; preds = %entry
82 call void @llvm.dbg.value(metadata i32 4, metadata !14, metadata !DIExpression()), !dbg !25
83 br label %if.end
69 call void @llvm.dbg.value(metadata i32 4, metadata !14, metadata !DIExpression()), !dbg !27
70 br label %if.end, !dbg !27
8471
8572 if.end: ; preds = %if.else, %if.then
8673 %beards.0 = phi i32 [ 8, %if.then ], [ 4, %if.else ]