diff options
| author | Bjorn Pettersson <bjorn.a.pettersson@ericsson.com> | 2018-04-18 08:08:04 +0000 |
|---|---|---|
| committer | Bjorn Pettersson <bjorn.a.pettersson@ericsson.com> | 2018-04-18 08:08:04 +0000 |
| commit | bc4f19b6bdcabee12b9dc8b58e8ac82e9f1a5d38 (patch) | |
| tree | cbd5e4a89d3a3e1cd81e5c634ff8e312189bd358 | |
| parent | 6ae0b1fe2b2bfdc144fc30597dc4ec4d34a10ffc (diff) | |
| download | bcm5719-llvm-bc4f19b6bdcabee12b9dc8b58e8ac82e9f1a5d38.tar.gz bcm5719-llvm-bc4f19b6bdcabee12b9dc8b58e8ac82e9f1a5d38.zip | |
[DebugInfo] Sink related dbg users when sinking in InstCombine
Summary:
When sinking an instruction in InstCombine we now also sink
the DbgInfoIntrinsics that are using the sunken value.
Example)
When sinking the load in this input
bb.X:
%0 = load i64, i64* %start, align 4, !dbg !31
tail call void @llvm.dbg.value(metadata i64 %0, ...)
br i1 %cond, label %for.end, label %for.body.lr.ph
for.body.lr.ph:
br label %for.body
we now also move the dbg.value, like this
bb.X:
br i1 %cond, label %for.end, label %for.body.lr.ph
for.body.lr.ph:
%0 = load i64, i64* %start, align 4, !dbg !31
tail call void @llvm.dbg.value(metadata i64 %0, ...)
br label %for.body
In the past we haven't moved the dbg.value so we got
bb.X:
tail call void @llvm.dbg.value(metadata i64 %0, ...)
br i1 %cond, label %for.end, label %for.body.lr.ph
for.body.lr.ph:
%0 = load i64, i64* %start, align 4, !dbg !31
br label %for.body
So in the past we got a debug-use before the def of %0.
And that dbg.value was also on the path jumping to %for.end, for
which %0 never was defined.
CodeGenPrepare normally comes to rescue later (when not moving
the dbg.value), since it moves dbg.value instrinsics quite
brutally, without really analysing if it is correct to move
the intrinsic (see PR31878).
So at the moment this patch isn't expected to have much impact,
besides that it is moving the dbg.value already in opt, making
the IR look more sane directly.
This can be seen as a preparation to (hopefully) make it possible
to turn off CodeGenPrepare::placeDbgValues later as a solution
to PR31878.
I also adjusted test/DebugInfo/X86/sdagsplit-1.ll to make the
IR in the test case up-to-date with this behavior in InstCombine.
Reviewers: rnk, vsk, aprantl
Reviewed By: vsk, aprantl
Subscribers: mattd, JDevlieghere, llvm-commits
Tags: #debug-info
Differential Revision: https://reviews.llvm.org/D45425
llvm-svn: 330243
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 13 | ||||
| -rw-r--r-- | llvm/test/DebugInfo/X86/sdagsplit-1.ll | 2 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/debuginfo_add.ll | 10 |
3 files changed, 21 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 4e836dde158..c2c3ee1aff1 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2897,6 +2897,7 @@ Instruction *InstCombiner::visitLandingPadInst(LandingPadInst &LI) { /// block. static bool TryToSinkInstruction(Instruction *I, BasicBlock *DestBlock) { assert(I->hasOneUse() && "Invariants didn't hold!"); + BasicBlock *SrcBlock = I->getParent(); // Cannot move control-flow-involving, volatile loads, vaarg, etc. if (isa<PHINode>(I) || I->isEHPad() || I->mayHaveSideEffects() || @@ -2926,10 +2927,20 @@ static bool TryToSinkInstruction(Instruction *I, BasicBlock *DestBlock) { if (Scan->mayWriteToMemory()) return false; } - BasicBlock::iterator InsertPos = DestBlock->getFirstInsertionPt(); I->moveBefore(&*InsertPos); ++NumSunkInst; + + // Also sink all related debug uses from the source basic block. Otherwise we + // get debug use before the def. + SmallVector<DbgInfoIntrinsic *, 1> DbgUsers; + findDbgUsers(DbgUsers, I); + for (auto *DII : DbgUsers) { + if (DII->getParent() == SrcBlock) { + DII->moveBefore(&*InsertPos); + DEBUG(dbgs() << "SINK: " << *DII << '\n'); + } + } return true; } diff --git a/llvm/test/DebugInfo/X86/sdagsplit-1.ll b/llvm/test/DebugInfo/X86/sdagsplit-1.ll index ac32958886a..2fbf1ac8cb9 100644 --- a/llvm/test/DebugInfo/X86/sdagsplit-1.ll +++ b/llvm/test/DebugInfo/X86/sdagsplit-1.ll @@ -25,9 +25,9 @@ define i64 @foo(i64 %a, i64 %b) local_unnamed_addr #0 !dbg !8 { entry: tail call void @llvm.dbg.value(metadata i64 %a, metadata !13, metadata !16), !dbg !17 tail call void @llvm.dbg.value(metadata i64 %b, metadata !14, metadata !16), !dbg !18 - tail call void @llvm.dbg.value(metadata i64 %add, metadata !15, metadata !16), !dbg !19 %cmp = icmp eq i64 %a, %b, !dbg !20 %add = add nsw i64 %b, 1, !dbg !22 + tail call void @llvm.dbg.value(metadata i64 %add, metadata !15, metadata !16), !dbg !19 %retval.0 = select i1 %cmp, i64 %add, i64 0, !dbg !23 ret i64 %retval.0, !dbg !24 } diff --git a/llvm/test/Transforms/InstCombine/debuginfo_add.ll b/llvm/test/Transforms/InstCombine/debuginfo_add.ll index 0d194cc65c7..70dfce75df4 100644 --- a/llvm/test/Transforms/InstCombine/debuginfo_add.ll +++ b/llvm/test/Transforms/InstCombine/debuginfo_add.ll @@ -28,14 +28,20 @@ entry: tail call void @llvm.dbg.value(metadata i64 %0, metadata !25, metadata !DIExpression()), !dbg !30 %offset.08 = add i64 %0, -4096 tail call void @llvm.dbg.value(metadata i64 %offset.08, metadata !26, metadata !DIExpression()), !dbg !31 - ; CHECK: call void @llvm.dbg.value(metadata i64 %0, metadata !26, metadata !DIExpression(DW_OP_constu, 4096, DW_OP_minus, DW_OP_stack_value)), !dbg !30 tail call void @llvm.dbg.value(metadata i32 undef, metadata !23, metadata !DIExpression()), !dbg !32 br i1 undef, label %for.end, label %for.body.lr.ph, !dbg !32 for.body.lr.ph: ; preds = %entry + ; The 'load' and the 'add' are sunken to this basic block. So let's verify that the related dbg.values are sunken as well. + ; The add is later eliminated, so we verify that the dbg.value is salvaged by using DW_OP_minus. + ; CHECK-LABEL: for.body.lr.ph: + ; CHECK-NEXT: %0 = load + ; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 %0, metadata !25, metadata !DIExpression()), !dbg ! + ; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 %0, metadata !26, metadata !DIExpression(DW_OP_constu, 4096, DW_OP_minus, DW_OP_stack_value)), !dbg ! br label %for.body, !dbg !32 for.body: ; preds = %for.body.lr.ph, %for.body + ; CHECK-LABEL: for.body: %offset.010 = phi i64 [ %offset.08, %for.body.lr.ph ], [ %offset.0, %for.body ] %head_size.09 = phi i32 [ undef, %for.body.lr.ph ], [ %sub2, %for.body ] tail call void @llvm.dbg.value(metadata i32 %head_size.09, metadata !23, metadata !DIExpression()), !dbg !31 @@ -43,7 +49,7 @@ for.body: ; preds = %for.body.lr.ph, %fo %sub2 = add i32 %head_size.09, -4096, !dbg !37 %offset.0 = add i64 %offset.010, -4096 tail call void @llvm.dbg.value(metadata i64 %offset.0, metadata !26, metadata !DIExpression()), !dbg !30 - ; CHECK: call void @llvm.dbg.value(metadata i64 %offset.010, metadata !26, metadata !DIExpression(DW_OP_constu, 4096, DW_OP_minus, DW_OP_stack_value)), !dbg !29 + ; CHECK: call void @llvm.dbg.value(metadata i64 %offset.010, metadata !26, metadata !DIExpression(DW_OP_constu, 4096, DW_OP_minus, DW_OP_stack_value)), !dbg ! tail call void @llvm.dbg.value(metadata i32 %sub2, metadata !23, metadata !DIExpression()), !dbg !31 %tobool = icmp eq i32 %sub2, 0, !dbg !32 br i1 %tobool, label %for.end, label %for.body, !dbg !32, !llvm.loop !38 |

