llvm.org GIT mirror llvm / 814924d
[DebugInfo] Don't salvage load operations (PR40628). Salvaging a redundant load instruction into a debug expression hides a memory read from optimisation passes. Passes that alter memory behaviour (such as LICM promoting memory to a register) aren't aware of these debug memory reads and leave them unaltered, making the debug variable location point somewhere unsafe. Teaching passes to know about these debug memory reads would be challenging and probably incomplete. Finding dbg.value instructions that need to be fixed would likely be computationally expensive too, as more analysis would be required. It's better to not generate debug-memory-reads instead, alas. Changed tests: * DeadStoreElim: test for salvaging of intermediate operations contributing to the dead store, instead of salvaging of the redundant load, * GVN: remove debuginfo behaviour checks completely, this behaviour is still covered by other tests, * InstCombine: don't test for salvaged loads, we're removing that behaviour. Differential Revision: https://reviews.llvm.org/D57962 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353824 91177308-0d34-0410-b5e6-96231b3b80d8 Jeremy Morse 7 months ago
5 changed file(s) with 69 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
17131713 // TODO: Salvage constants from each kind of binop we know about.
17141714 return nullptr;
17151715 }
1716 } else if (isa(&I)) {
1717 // Rewrite the load into DW_OP_deref.
1718 return DIExpression::prepend(SrcDIExpr, DIExpression::WithDeref);
1716 // *Not* to do: we should not attempt to salvage load instructions,
1717 // because the validity and lifetime of a dbg.value containing
1718 // DW_OP_deref becomes difficult to analyze. See PR40628 for examples.
17191719 }
17201720 return nullptr;
17211721 }
0 ; RUN: opt -early-cse -S %s -o - | FileCheck %s
1
2 ; PR40628: The first load below is determined to be redundant by EarlyCSE.
3 ; During salvaging, the corresponding dbg.value could have a DW_OP_deref used
4 ; in its DIExpression to represent the redundant operation -- however LLVM
5 ; cannot currently determine that the subsequent store should terminate the
6 ; variables location range. A debugger would display zero for the "redundant"
7 ; variable after stepping onto the return instruction.
8
9 ; Test that the load being removed results in the corresponding dbg.value
10 ; being assigned the 'undef' value.
11
12 ; CHECK: @foo
13 ; CHECK-NEXT: dbg.value(metadata i32 undef, metadata ![[DEADVAR:[0-9]+]],
14 ; CHECK-NEXT: load
15 ; CHECK-NEXT: dbg.value(metadata i32 %{{[0-9]+}}, metadata ![[LIVEVAR:[0-9]+]],
16 ; CHECK-NEXT: store
17 ; CHECK-NEXT: ret
18
19 ; CHECK: ![[DEADVAR]] = !DILocalVariable(name: "redundant",
20 ; CHECK: ![[LIVEVAR]] = !DILocalVariable(name: "loaded",
21
22 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
23 target triple = "x86_64-unknown-linux-gnu"
24
25 define dso_local i32 @foo(i32*) !dbg !7 {
26 %2 = load i32, i32* %0, align 4, !dbg !23
27 call void @llvm.dbg.value(metadata i32 %2, metadata !16, metadata !DIExpression()), !dbg !23
28 %3 = load i32, i32* %0, align 4, !dbg !23
29 call void @llvm.dbg.value(metadata i32 %3, metadata !17, metadata !DIExpression()), !dbg !23
30 store i32 0, i32* %0, align 4, !dbg !23
31 ret i32 %3, !dbg !23
32 }
33
34 declare void @llvm.dbg.value(metadata, metadata, metadata)
35
36 !llvm.dbg.cu = !{!0}
37 !llvm.module.flags = !{!3, !4, !5}
38 !llvm.ident = !{!6}
39
40 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
41 !1 = !DIFile(filename: "pr40628.c", directory: ".")
42 !2 = !{}
43 !3 = !{i32 2, !"Dwarf Version", i32 4}
44 !4 = !{i32 2, !"Debug Info Version", i32 3}
45 !5 = !{i32 1, !"wchar_size", i32 4}
46 !6 = !{!"clang"}
47 !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !8, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12)
48 !8 = !DISubroutineType(types: !9)
49 !9 = !{!10, !11}
50 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
51 !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64)
52 !12 = !{!16, !17}
53 !16 = !DILocalVariable(name: "redundant", scope: !7, file: !1, line: 4, type: !10)
54 !17 = !DILocalVariable(name: "loaded", scope: !7, file: !1, line: 5, type: !10)
55 !23 = !DILocation(line: 4, column: 7, scope: !7)
55
66 declare void @test_f()
77
8 define i32* @test_salvage() {
8 define i32* @test_salvage(i32 %arg) {
99 ; Check that all four original local variables have their values preserved.
10 ; CHECK-LABEL: @test_salvage()
10 ; CHECK-LABEL: @test_salvage(
1111 ; CHECK-NEXT: malloc
1212 ; CHECK-NEXT: @llvm.dbg.value(metadata i8* %p, metadata ![[p:.*]], metadata !DIExpression())
1313 ; CHECK-NEXT: bitcast
1414 ; CHECK-NEXT: @llvm.dbg.value(metadata i32* %P, metadata ![[P:.*]], metadata !DIExpression())
15 ; CHECK-NEXT: @llvm.dbg.value(metadata i32* %P, metadata ![[DEAD:.*]], metadata !DIExpression(DW_OP_deref))
16 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32* %P, metadata ![[DEAD2:.*]], metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 1, DW_OP_stack_value))
15 ; CHECK-NEXT: @llvm.dbg.value(metadata i32 %arg, metadata ![[DEAD:.*]], metadata !DIExpression(DW_OP_plus_uconst, 1, DW_OP_stack_value))
1716 ; CHECK-NEXT: call void @test_f()
1817 ; CHECK-NEXT: store i32 0, i32* %P
1918
2019 %p = tail call i8* @malloc(i32 4)
2120 %P = bitcast i8* %p to i32*
22 %DEAD = load i32, i32* %P
23 %DEAD2 = add i32 %DEAD, 1
24 store i32 %DEAD2, i32* %P
21 %DEAD = add i32 %arg, 1
22 store i32 %DEAD, i32* %P
2523 call void @test_f()
2624 store i32 0, i32* %P
2725 ret i32* %P
3028 ; CHECK: ![[p]] = !DILocalVariable(name: "1"
3129 ; CHECK: ![[P]] = !DILocalVariable(name: "2"
3230 ; CHECK: ![[DEAD]] = !DILocalVariable(name: "3"
33 ; CHECK: ![[DEAD2]] = !DILocalVariable(name: "4"
None ; RUN: opt -S -debugify -basicaa -gvn < %s | FileCheck %s
0 ; RUN: opt -S -basicaa -gvn < %s | FileCheck %s
11
22 @a = external constant i32
33 ; We can value forward across the fence since we can (semantically)
1717 ; Same as above
1818 define i32 @test2(i32* %addr.i) {
1919 ; CHECK-LABEL: @test2
20 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32* %addr.i, metadata [[var_a:![0-9]+]], metadata !DIExpression(DW_OP_deref))
2120 ; CHECK-NEXT: fence
2221 ; CHECK-NOT: load
23 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32* %addr.i, metadata [[var_a2:![0-9]+]], metadata !DIExpression(DW_OP_deref))
2422 ; CHECK: ret
2523 %a = load i32, i32* %addr.i, align 4
2624 fence release
8785 ; }
8886 ; Given we chose to forward across the release fence, we clearly can't forward
8987 ; across the acquire fence as well.
90
91 ; CHECK: [[var_a]] = !DILocalVariable
92 ; CHECK-NEXT: [[var_a2]] = !DILocalVariable
2222
2323 %struct.entry = type { %struct.entry* }
2424
25 ; This salvage can't currently occur safely (PR40628), however if/when that's
26 ; ever fixed, then this is definitely a piece of test coverage that should
27 ; be maintained.
2528 define void @salvage_load(%struct.entry** %queue) local_unnamed_addr #0 !dbg !14 {
2629 entry:
2730 %im_not_dead = alloca %struct.entry*
3033 call void @llvm.dbg.value(metadata %struct.entry* %1, metadata !18, metadata !20), !dbg !19
3134 ; CHECK: define void @salvage_load
3235 ; CHECK-NEXT: entry:
33 ; CHECK-NEXT: call void @llvm.dbg.value(metadata %struct.entry** %queue,
34 ; CHECK-SAME: metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 0))
36 ; CHECK-NOT: dbg.value
3537 store %struct.entry* %1, %struct.entry** %im_not_dead, align 8
3638 ret void, !dbg !21
3739 }