xref: /llvm-project/llvm/test/DebugInfo/X86/salvage-add-node-indirect.ll (revision 5ee088134fb87f7d716c58fa65beb11fb6afcb22)
1; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 3
2; RUN: llc -mtriple=x86_64 %s -start-before=x86-isel -o - -stop-after=x86-isel | FileCheck %s
3; RUN: llc --try-experimental-debuginfo-iterators -mtriple=x86_64 %s -start-before=x86-isel -o - -stop-after=x86-isel | FileCheck %s
4
5; Verify that we don't crash due to attempting to turn the indirect debug value
6; in @test_non_constant variadic when salvaging the ADD node with non-constant
7; RHS (originating from the GEP). This means that the debug location is
8; dropped.
9;
10; We should salvage the debug information in @test_constant.
11; XXX: Is it actually correct to add a stack_value operation in that case?
12
13%struct.x = type { i64, i64, float, i64, double, ptr }
14
15define i64 @test_constant(ptr %rdata) {
16  ; CHECK-LABEL: name: test_constant
17  ; CHECK: bb.0.entry:
18  ; CHECK-NEXT:   successors: %bb.1(0x80000000)
19  ; CHECK-NEXT:   liveins: $rdi
20  ; CHECK-NEXT: {{  $}}
21  ; CHECK-NEXT:   DBG_PHI $rdi, 1
22  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:gr64 = COPY $rdi
23  ; CHECK-NEXT: {{  $}}
24  ; CHECK-NEXT: bb.1.for.body31:
25  ; CHECK-NEXT:   successors: %bb.2(0x04000000), %bb.1(0x7c000000)
26  ; CHECK-NEXT: {{  $}}
27  ; CHECK-NEXT:   DBG_INSTR_REF !4, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_plus_uconst, 144, DW_OP_deref, DW_OP_stack_value), dbg-instr-ref(1, 0), debug-location !8
28  ; CHECK-NEXT:   CMP64mi32 [[COPY]], 1, $noreg, 144, $noreg, 0, implicit-def $eflags :: (load (s64) from %ir.arrayidx33, align 1)
29  ; CHECK-NEXT:   JCC_1 %bb.1, 5, implicit $eflags
30  ; CHECK-NEXT:   JMP_1 %bb.2
31  ; CHECK-NEXT: {{  $}}
32  ; CHECK-NEXT: bb.2.land.lhs.true.i:
33  ; CHECK-NEXT:   [[MOV32r0_:%[0-9]+]]:gr32 = MOV32r0 implicit-def dead $eflags
34  ; CHECK-NEXT:   [[SUBREG_TO_REG:%[0-9]+]]:gr64 = SUBREG_TO_REG 0, killed [[MOV32r0_]], %subreg.sub_32bit
35  ; CHECK-NEXT:   $rax = COPY [[SUBREG_TO_REG]]
36  ; CHECK-NEXT:   RET 0, $rax
37entry:
38  br label %for.body31
39
40for.body31:                                       ; preds = %for.body31, %entry
41  %arrayidx33 = getelementptr [30 x %struct.x], ptr %rdata, i64 0, i64 3
42  call void @llvm.dbg.declare(metadata ptr %arrayidx33, metadata !9, metadata !DIExpression()), !dbg !11
43  %0 = load i64, ptr %arrayidx33, align 1
44  %cmp.i = icmp eq i64 %0, 0
45  br i1 %cmp.i, label %land.lhs.true.i, label %for.body31
46
47land.lhs.true.i:                                  ; preds = %for.body31
48  ret i64 0
49}
50
51define i64 @test_non_constant(ptr %rdata, i64 %i.194) {
52  ; CHECK-LABEL: name: test_non_constant
53  ; CHECK: bb.0.entry:
54  ; CHECK-NEXT:   successors: %bb.1(0x80000000)
55  ; CHECK-NEXT:   liveins: $rdi, $rsi
56  ; CHECK-NEXT: {{  $}}
57  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:gr64_nosp = COPY $rsi
58  ; CHECK-NEXT:   [[COPY1:%[0-9]+]]:gr64 = COPY $rdi
59  ; CHECK-NEXT: {{  $}}
60  ; CHECK-NEXT: bb.1.for.body31:
61  ; CHECK-NEXT:   successors: %bb.2(0x04000000), %bb.1(0x7c000000)
62  ; CHECK-NEXT: {{  $}}
63  ; CHECK-NEXT:   [[LEA64r:%[0-9]+]]:gr64 = LEA64r [[COPY]], 2, [[COPY]], 0, $noreg
64  ; CHECK-NEXT:   [[SHL64ri:%[0-9]+]]:gr64_nosp = SHL64ri [[LEA64r]], 4, implicit-def dead $eflags
65  ; CHECK-NEXT:   CMP64mi32 [[COPY1]], 1, killed [[SHL64ri]], 0, $noreg, 0, implicit-def $eflags :: (load (s64) from %ir.arrayidx33, align 1)
66  ; CHECK-NEXT:   JCC_1 %bb.1, 5, implicit $eflags
67  ; CHECK-NEXT:   JMP_1 %bb.2
68  ; CHECK-NEXT: {{  $}}
69  ; CHECK-NEXT: bb.2.land.lhs.true.i:
70  ; CHECK-NEXT:   [[MOV32r0_:%[0-9]+]]:gr32 = MOV32r0 implicit-def dead $eflags
71  ; CHECK-NEXT:   [[SUBREG_TO_REG:%[0-9]+]]:gr64 = SUBREG_TO_REG 0, killed [[MOV32r0_]], %subreg.sub_32bit
72  ; CHECK-NEXT:   $rax = COPY [[SUBREG_TO_REG]]
73  ; CHECK-NEXT:   RET 0, $rax
74entry:
75  br label %for.body31
76
77for.body31:                                       ; preds = %for.body31, %entry
78  %arrayidx33 = getelementptr [30 x %struct.x], ptr %rdata, i64 0, i64 %i.194
79  call void @llvm.dbg.declare(metadata ptr %arrayidx33, metadata !4, metadata !DIExpression()), !dbg !8
80  %0 = load i64, ptr %arrayidx33, align 1
81  %cmp.i = icmp eq i64 %0, 0
82  br i1 %cmp.i, label %land.lhs.true.i, label %for.body31
83
84land.lhs.true.i:                                  ; preds = %for.body31
85  ret i64 0
86}
87
88declare void @llvm.dbg.declare(metadata, metadata, metadata)
89
90!llvm.dbg.cu = !{!0}
91!llvm.module.flags = !{!3}
92
93!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, globals: !2, splitDebugInlining: false, nameTableKind: None)
94!1 = !DIFile(filename: "foo.c", directory: "/tmp")
95!2 = !{}
96!3 = !{i32 2, !"Debug Info Version", i32 3}
97!4 = !DILocalVariable(name: "a", arg: 1, scope: !5, file: !1, line: 33, type: !7)
98!5 = distinct !DISubprogram(name: "test_non_constant", scope: !1, file: !1, line: 33, type: !6, scopeLine: 34, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
99!6 = distinct !DISubroutineType(types: !2)
100!7 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "x", file: !1, line: 17, size: 160, elements: !2)
101!8 = !DILocation(line: 33, column: 16, scope: !5)
102!9 = !DILocalVariable(name: "a", arg: 1, scope: !10, file: !1, line: 33, type: !7)
103!10 = distinct !DISubprogram(name: "test_constant", scope: !1, file: !1, line: 33, type: !6, scopeLine: 34, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
104!11 = !DILocation(line: 33, column: 16, scope: !10)
105