[PATCH] D45425: [DebugInfo] Sink related dbg users when sinking in InstCombine
Bjorn Pettersson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 18 01:11:25 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL330243: [DebugInfo] Sink related dbg users when sinking in InstCombine (authored by bjope, committed by ).
Repository:
rL LLVM
https://reviews.llvm.org/D45425
Files:
llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/trunk/test/DebugInfo/X86/sdagsplit-1.ll
llvm/trunk/test/Transforms/InstCombine/debuginfo_add.ll
Index: llvm/trunk/test/Transforms/InstCombine/debuginfo_add.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/debuginfo_add.ll
+++ llvm/trunk/test/Transforms/InstCombine/debuginfo_add.ll
@@ -28,22 +28,28 @@
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
%call = tail call i32 bitcast (i32 (...)* @use to i32 (i64, %struct.vm_object*)*)(i64 %offset.010, %struct.vm_object* %object) #3, !dbg !34
%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
Index: llvm/trunk/test/DebugInfo/X86/sdagsplit-1.ll
===================================================================
--- llvm/trunk/test/DebugInfo/X86/sdagsplit-1.ll
+++ llvm/trunk/test/DebugInfo/X86/sdagsplit-1.ll
@@ -25,9 +25,9 @@
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
}
Index: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2897,6 +2897,7 @@
/// 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 @@
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45425.142892.patch
Type: text/x-patch
Size: 4767 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180418/c7b02b0d/attachment.bin>
More information about the llvm-commits
mailing list