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