Skip to content

Commit d0858bf

Browse files
authored
[DebugInfo][RemoveDIs] Maintain DPValues on skipped instrs in CGP (#74602)
It turns out that CodeGenPrepare will skip over consecutive select instructions as it knows it can optimise them all at the same time. This is unfortunate for the RemoveDIs project to remove intrinsic-based debug-info, because that means debug-info attached to those skipped instructions doesn't get seen by optimizeInst and so updated. Add code to handle debug-info on those skipped instructions manually. This code will also have been slower when it had dbg.values stuffed in between instructions, but with RemoveDIs it'll go faster because the dbg.values won't break up the select sequence.
1 parent 7b83f69 commit d0858bf

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ class CodeGenPrepare : public FunctionPass {
460460
bool dupRetToEnableTailCallOpts(BasicBlock *BB, ModifyDT &ModifiedDT);
461461
bool fixupDbgValue(Instruction *I);
462462
bool fixupDPValue(DPValue &I);
463+
bool fixupDPValuesOnInst(Instruction &I);
463464
bool placeDbgValues(Function &F);
464465
bool placePseudoProbes(Function &F);
465466
bool canFormExtLd(const SmallVectorImpl<Instruction *> &MovedExts,
@@ -6986,6 +6987,11 @@ bool CodeGenPrepare::optimizeSelectInst(SelectInst *SI) {
69866987
// Increment the current iterator to skip all the rest of select instructions
69876988
// because they will be either "not lowered" or "all lowered" to branch.
69886989
CurInstIterator = std::next(LastSI->getIterator());
6990+
// Examine debug-info attached to the consecutive select instructions. They
6991+
// won't be individually optimised by optimizeInst, so we need to perform
6992+
// DPValue maintenence here instead.
6993+
for (SelectInst *SI : ArrayRef(ASI).drop_front())
6994+
fixupDPValuesOnInst(*SI);
69896995

69906996
bool VectorCond = !SI->getCondition()->getType()->isIntegerTy(1);
69916997

@@ -8141,8 +8147,7 @@ static bool optimizeBranch(BranchInst *Branch, const TargetLowering &TLI,
81418147

81428148
bool CodeGenPrepare::optimizeInst(Instruction *I, ModifyDT &ModifiedDT) {
81438149
bool AnyChange = false;
8144-
for (DPValue &DPV : I->getDbgValueRange())
8145-
AnyChange |= fixupDPValue(DPV);
8150+
AnyChange = fixupDPValuesOnInst(*I);
81468151

81478152
// Bail out if we inserted the instruction to prevent optimizations from
81488153
// stepping on each other's toes.
@@ -8408,6 +8413,13 @@ bool CodeGenPrepare::fixupDbgValue(Instruction *I) {
84088413
return AnyChange;
84098414
}
84108415

8416+
bool CodeGenPrepare::fixupDPValuesOnInst(Instruction &I) {
8417+
bool AnyChange = false;
8418+
for (DPValue &DPV : I.getDbgValueRange())
8419+
AnyChange |= fixupDPValue(DPV);
8420+
return AnyChange;
8421+
}
8422+
84118423
// FIXME: should updating debug-info really cause the "changed" flag to fire,
84128424
// which can cause a function to be reprocessed?
84138425
bool CodeGenPrepare::fixupDPValue(DPValue &DPV) {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
; RUN: llc %s -stop-after=codegenprepare -o - | FileCheck %s
2+
; RUN: llc %s -stop-after=codegenprepare -o - --try-experimental-debuginfo-iterators | FileCheck %s
3+
;
4+
; Test that when we skip over multiple selects in CGP, that the debug-info
5+
; attached to those selects is still fixed up.
6+
7+
; CHECK: declare void @llvm.dbg.value(metadata,
8+
; CHECK: call void @llvm.dbg.value(metadata ptr %sunkaddr,
9+
10+
source_filename = "reduced.ll"
11+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
12+
target triple = "x86_64-unknown-linux-gnu"
13+
14+
%"class.(anonymous namespace)::CFIInstrInserter" = type { ptr, ptr, ptr, ptr }
15+
16+
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
17+
declare void @llvm.dbg.value(metadata, metadata, metadata) #0
18+
19+
define i1 @_ZN12_GLOBAL__N_116CFIInstrInserter20runOnMachineFunctionERN4llvm15MachineFunctionE(ptr %this, i1 %or.cond.i) !dbg !5 {
20+
entry:
21+
%CSRLocMap.i = getelementptr %"class.(anonymous namespace)::CFIInstrInserter", ptr %this, i64 0, i32 2, !dbg !16
22+
%bf.load.i.i.i.i = load i32, ptr %CSRLocMap.i, align 8, !dbg !17
23+
br i1 %or.cond.i, label %_ZN4llvm12DenseMapBaseINS_13SmallDenseMapIjN12_GLOBAL__N_116CFIInstrInserter16CSRSavedLocationELj16ENS_12DenseMapInfoIjvEENS_6detail12DenseMapPairIjS4_EEEEjS4_S6_S9_E5clearEv.exit.i, label %if.end.i.i, !dbg !18
24+
25+
if.end.i.i: ; preds = %entry
26+
store ptr null, ptr null, align 8, !dbg !19
27+
%bf.load.i.i.i.pre.i.i.i.i.i = load i32, ptr %CSRLocMap.i, align 8, !dbg !20
28+
%cond.i.i.i.i.i.i.i.i.i = select i1 false, ptr null, ptr null, !dbg !21
29+
tail call void @llvm.dbg.value(metadata ptr %CSRLocMap.i, metadata !14, metadata !DIExpression()), !dbg !21
30+
%cond.i.i.i7.i.i.i.i.i.i = select i1 false, i32 0, i32 0, !dbg !22
31+
br label %_ZN4llvm12DenseMapBaseINS_13SmallDenseMapIjN12_GLOBAL__N_116CFIInstrInserter16CSRSavedLocationELj16ENS_12DenseMapInfoIjvEENS_6detail12DenseMapPairIjS4_EEEEjS4_S6_S9_E5clearEv.exit.i, !dbg !23
32+
33+
_ZN4llvm12DenseMapBaseINS_13SmallDenseMapIjN12_GLOBAL__N_116CFIInstrInserter16CSRSavedLocationELj16ENS_12DenseMapInfoIjvEENS_6detail12DenseMapPairIjS4_EEEEjS4_S6_S9_E5clearEv.exit.i: ; preds = %if.end.i.i, %entry
34+
ret i1 false, !dbg !24
35+
}
36+
37+
attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
38+
39+
!llvm.module.flags = !{!0}
40+
!llvm.dbg.cu = !{!1}
41+
!llvm.debugify = !{!3, !4}
42+
43+
!0 = !{i32 2, !"Debug Info Version", i32 3}
44+
!1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
45+
!2 = !DIFile(filename: "reduced.ll", directory: "/")
46+
!3 = !{i32 9}
47+
!4 = !{i32 5}
48+
!5 = distinct !DISubprogram(name: "_ZN12_GLOBAL__N_116CFIInstrInserter20runOnMachineFunctionERN4llvm15MachineFunctionE", linkageName: "_ZN12_GLOBAL__N_116CFIInstrInserter20runOnMachineFunctionERN4llvm15MachineFunctionE", scope: null, file: !2, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !1, retainedNodes: !8)
49+
!6 = !DISubroutineType(types: !7)
50+
!7 = !{}
51+
!8 = !{!9, !11, !13, !14, !15}
52+
!9 = !DILocalVariable(name: "1", scope: !5, file: !2, line: 1, type: !10)
53+
!10 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned)
54+
!11 = !DILocalVariable(name: "2", scope: !5, file: !2, line: 2, type: !12)
55+
!12 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
56+
!13 = !DILocalVariable(name: "3", scope: !5, file: !2, line: 5, type: !12)
57+
!14 = !DILocalVariable(name: "4", scope: !5, file: !2, line: 6, type: !10)
58+
!15 = !DILocalVariable(name: "5", scope: !5, file: !2, line: 7, type: !12)
59+
!16 = !DILocation(line: 1, column: 1, scope: !5)
60+
!17 = !DILocation(line: 2, column: 1, scope: !5)
61+
!18 = !DILocation(line: 3, column: 1, scope: !5)
62+
!19 = !DILocation(line: 4, column: 1, scope: !5)
63+
!20 = !DILocation(line: 5, column: 1, scope: !5)
64+
!21 = !DILocation(line: 6, column: 1, scope: !5)
65+
!22 = !DILocation(line: 7, column: 1, scope: !5)
66+
!23 = !DILocation(line: 8, column: 1, scope: !5)
67+
!24 = !DILocation(line: 9, column: 1, scope: !5)

0 commit comments

Comments
 (0)