1 # RUN: llc -mtriple=x86_64-unknown-unknown -run-pass=machine-sink -o - %s | FileCheck %s
2 # In the first test, check various things when we sink machine instructions:
3 # a) DBG_VALUEs should sink with defs
4 # b) Undefs should be left behind
5 # c) DBG_VALUEs not immediately following the defining inst should sink too
6 # d) If we generate debug-use-before-defs through sinking, and can copy
7 # propagate to a different value, we should do that.
9 # Test two checks DBG_VALUEs do not sink past a DBG_VALUE in the same block
10 # that redefines the variable location, while three checks that copy-propagation
11 # happens in the same scenario.
13 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
14 target triple = "x86_64-unknown-linux-gnu"
16 @x = common local_unnamed_addr global i32 0, align 4, !dbg !0
18 ; Function Attrs: noreturn nounwind uwtable
19 define void @Process(i32* nocapture readonly %p) local_unnamed_addr !dbg !9 {
29 define void @test2(i32* nocapture readonly %p) local_unnamed_addr !dbg !101 {
39 define void @test3(i32* nocapture readonly %p) local_unnamed_addr !dbg !201 {
49 ; Function Attrs: nounwind readnone
50 declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
53 !llvm.module.flags = !{!6, !7}
56 !0 = !DIGlobalVariableExpression(var: !DIGlobalVariable(name: "x", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true), expr: !DIExpression())
57 !1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !4)
58 !2 = !DIFile(filename: "t.c", directory: "")
61 !5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
62 !6 = !{i32 2, !"Dwarf Version", i32 4}
63 !7 = !{i32 2, !"Debug Info Version", i32 3}
64 !8 = !{!"clang version 4.0.0 "}
65 !9 = distinct !DISubprogram(name: "Process", scope: !2, file: !2, line: 2, type: !10, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !1, retainedNodes: !15)
66 !10 = !DISubroutineType(types: !11)
68 !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
69 !13 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !14)
70 !14 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
72 !16 = !DILocalVariable(name: "p", arg: 1, scope: !9, file: !2, line: 2, type: !12)
74 !18 = !DILocation(line: 2, column: 34, scope: !9)
75 !28 = !DILexicalBlockFile(scope: !9, file: !2, discriminator: 1)
76 !101 = distinct !DISubprogram(name: "test2", scope: !2, file: !2, line: 2, type: !10, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !1, retainedNodes: !102)
78 !103 = !DILocalVariable(name: "q", arg: 1, scope: !101, file: !2, line: 2, type: !12)
79 !104 = !DILocation(line: 1, column: 1, scope: !101)
80 !201 = distinct !DISubprogram(name: "test2", scope: !2, file: !2, line: 2, type: !10, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !1, retainedNodes: !202)
82 !203 = !DILocalVariable(name: "r", arg: 1, scope: !201, file: !2, line: 2, type: !12)
83 !204 = !DILocation(line: 1, column: 1, scope: !201)
85 ; CHECK: [[VARNUM:![0-9]+]] = !DILocalVariable(name: "p",
86 ; CHECK: [[VAR2NUM:![0-9]+]] = !DILocalVariable(name: "q",
87 ; CHECK: [[VAR3NUM:![0-9]+]] = !DILocalVariable(name: "r",
92 tracksRegLiveness: true
94 - { reg: '$rdi', virtual-reg: '%2' }
95 - { reg: '$rsi', virtual-reg: '%2' }
98 successors: %bb.1.nou(0x80000000), %bb.2.exit
101 ; This block should have the vreg copy sunk from it, the DBG_VALUE with it,
102 ; and a copy-prop'd DBG_VALUE left over.
103 ; CHECK-LABEL: bb.0.entry:
104 ; CHECK: [[ARG0VREG:%[0-9]+]]:gr64 = COPY $rdi
105 ; CHECK-NEXT: CMP32ri $esi, 0
106 ; CHECK-NEXT: DBG_VALUE [[ARG0VREG]], $noreg, [[VARNUM]]
107 ; CHECK-NEXT: JCC_1 %bb.1, 4
112 CMP32ri $esi, 0, implicit-def $eflags
113 DBG_VALUE %5, $noreg, !16, !17, debug-location !18
114 JCC_1 %bb.1.nou, 4, implicit $eflags
118 successors: %bb.2.exit(0x80000000)
120 ; This block should receive the sunk copy and DBG_VALUE
121 ; CHECK-LABEL: bb.1.nou:
122 ; CHECK: [[SUNKVREG:%[0-9]+]]:gr64 = COPY [[ARG0VREG]]
123 ; CHECK-NEXT: DBG_VALUE [[SUNKVREG]], $noreg, [[VARNUM]]
124 ; CHECK-NEXT: ADD64ri8
126 %1:gr64 = ADD64ri8 %5, 4, implicit-def dead $eflags
130 ; The DBG_VALUE below should have its operand copy-propagated after
131 ; the copy to %5 is sunk.
132 ; CHECK-LABEL: bb.2.exit:
133 ; CHECK: DBG_VALUE [[ARG0VREG]], $noreg, [[VARNUM]]
134 ; CHECK-NEXT: $rax = MOV64rr [[ARG0VREG]]
136 DBG_VALUE %5, _, !16, !17, debug-location !18
142 tracksRegLiveness: true
144 - { reg: '$rdi', virtual-reg: '%2' }
145 - { reg: '$rsi', virtual-reg: '%2' }
148 successors: %bb.1.block1, %bb.2.exit
151 ; This block should _not_ have the first DBG_VALUE sunk out from it, as it
152 ; would pass a later DBG_VALUE of the same variable location. An undef
153 ; DBG_VALUE should be left behind though.
154 ; CHECK-LABEL: bb.0.entry:
155 ; CHECK: [[TEST2VREG:%[0-9]+]]:gr64 = COPY $rdi
156 ; CHECK-NEXT: CMP32ri $esi, 0
157 ; CHECK-NEXT: DBG_VALUE $noreg, $noreg, [[VAR2NUM]]
158 ; CHECK-NEXT: CMP32ri $esi, 0
159 ; CHECK-NEXT: DBG_VALUE 0, $noreg, [[VAR2NUM]]
160 ; CHECK-NEXT: JCC_1 %bb.1, 4
164 %5:gr64 = ADD64ri8 %2, 1, implicit-def dead $eflags
165 CMP32ri $esi, 0, implicit-def $eflags
166 DBG_VALUE %5, $noreg, !103, !17, debug-location !104
167 CMP32ri $esi, 0, implicit-def $eflags
168 DBG_VALUE 0, $noreg, !103, !17, debug-location !104
169 JCC_1 %bb.1.block1, 4, implicit $eflags
173 successors: %bb.2.exit
175 ; This block should receive no DBG_VALUE.
176 ; CHECK-LABEL: bb.1.block1:
177 ; CHECK-NOT: DBG_VALUE
178 ; CHECK: [[SUNKVREG2:%[0-9]+]]:gr64 = ADD64ri8 [[TEST2VREG]]
179 ; CHECK-NOT: DBG_VALUE
180 ; CHECK-NEXT: ADD64ri8
182 %1:gr64 = ADD64ri8 %5, 4, implicit-def dead $eflags
191 tracksRegLiveness: true
193 - { reg: '$rdi', virtual-reg: '%2' }
194 - { reg: '$rsi', virtual-reg: '%2' }
197 successors: %bb.1.block1, %bb.2.exit
200 ; The copy from %2 to %5 will sink into a later block, and the first
201 ; DBG_VALUE cannot pass the second. But, we should be able to recover
202 ; the variable location through copy propagation.
203 ; CHECK-LABEL: bb.0.entry:
204 ; CHECK: [[TEST3VREG:%[0-9]+]]:gr64 = COPY $rdi
205 ; CHECK-NEXT: CMP32ri $esi, 0
206 ; CHECK-NEXT: DBG_VALUE [[TEST3VREG]], $noreg, [[VAR3NUM]]
207 ; CHECK-NEXT: CMP32ri $esi, 0
208 ; CHECK-NEXT: DBG_VALUE 0, $noreg, [[VAR3NUM]]
209 ; CHECK-NEXT: JCC_1 %bb.1, 4
214 CMP32ri $esi, 0, implicit-def $eflags
215 DBG_VALUE %5, $noreg, !203, !17, debug-location !204
216 CMP32ri $esi, 0, implicit-def $eflags
217 DBG_VALUE 0, $noreg, !203, !17, debug-location !204
218 JCC_1 %bb.1.block1, 4, implicit $eflags
222 successors: %bb.2.exit
224 ; This block should receive no DBG_VALUE.
225 ; CHECK-LABEL: bb.1.block1:
226 ; CHECK-NOT: DBG_VALUE
227 ; CHECK: COPY [[TEST3VREG]]
228 ; CHECK-NOT: DBG_VALUE
229 ; CHECK-NEXT: ADD64ri8
231 %1:gr64 = ADD64ri8 %5, 4, implicit-def dead $eflags