1 # RUN: llc %s -o - -run-pass=machine-cse -mtriple=x86_64-- | FileCheck %s
3 # This test examines machine-cse's behaviour when dealing with copy propagation,
4 # the code for which is lifted from test/CodeGen/X86/machine-cse.ll. There are
5 # two (MIR) function that have SHL/LEA instructions CSE'd in the bb.1.bb1 block.
6 # They both depend on the COPY of a vreg to %100 in the entry block.
8 # In the first (@t) there's only one use of %100, and that gets CSE'd away. The
9 # corresponding COPY is deleted, and all DBG_VALUEs that refer to it must be
12 # In the second (@u) there are two uses of %100, one of which isn't deleted. The
13 # DBG_VALUE users of %100 don't need to be updated -- test that they're not.
15 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
16 target triple = "x86_64-unknown-unknown"
18 %struct.s2 = type { i32, i8*, i8*, [256 x %struct.s1*], [8 x i32], i64, i8*, i32, i64, i64, i32, %struct.s3*, %struct.s3*, [49 x i64] }
19 %struct.s1 = type { %ptr, %ptr }
21 %struct.s3 = type { %struct.s3*, %struct.s3*, i32, i32, i32 }
23 ; Function Attrs: nounwind readnone speculatable
24 declare void @llvm.dbg.value(metadata, metadata, metadata) #0
26 define fastcc i8* @t(i32 %base) !dbg !3 {
28 %0 = zext i32 %base to i64
29 %1 = getelementptr inbounds %struct.s2, %struct.s2* null, i64 %0
30 br i1 undef, label %bb1, label %bb2
33 %2 = getelementptr inbounds %struct.s2, %struct.s2* null, i64 %0, i32 0
34 call void @llvm.dbg.value(metadata i32* %2, metadata !4, metadata !DIExpression()), !dbg !7
35 call void @bar(i32* %2)
39 %3 = ptrtoint %struct.s2* %1 to i64
40 call void @baz(i64 %3)
44 ; This is a stub replicating bb structure of @t
45 define fastcc i8* @u(i32 %base) !dbg !33 {
47 br i1 undef, label %bb1, label %bb2
57 declare void @bar(i32*)
59 declare void @baz(i64)
61 declare i8* @foo(%struct.s2*)
63 ; Function Attrs: nounwind
64 declare void @llvm.stackprotector(i8*, i8**) #1
66 attributes #0 = { nounwind readnone speculatable }
67 attributes #1 = { nounwind }
69 !llvm.module.flags = !{!0}
72 !0 = !{i32 2, !"Debug Info Version", i32 3}
73 !1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "beards", isOptimized: true, runtimeVersion: 4, emissionKind: FullDebug)
74 !2 = !DIFile(filename: "bees.cpp", directory: "")
75 !3 = distinct !DISubprogram(name: "nope", scope: !1, file: !2, line: 1, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !8)
76 !33 = distinct !DISubprogram(name: "alsonope", scope: !1, file: !2, line: 1, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !8)
77 !4 = !DILocalVariable(name: "bees", scope: !3, type: !5)
78 !5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64)
79 !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
80 !7 = !DILocation(line: 0, scope: !3)
84 ; CHECK: ![[METAVAR:[0-9]+]] = !DILocalVariable(name: "bees",
89 # CHECK-LABEL: name: t
90 tracksRegLiveness: true
92 - { reg: '$edi', virtual-reg: '%2' }
97 successors: %bb.1(0x40000000), %bb.2(0x40000000)
100 ; Capture vreg num for subreg move for later checks; test that the COPY
101 ; of that vreg is optimized out.
102 ; CHECK-LABEL: bb.0.entry:
103 ; CHECK: %[[BASEVREG:[0-9]+]]:gr64 = SUBREG_TO_REG
104 ; CHECK-NOT: COPY %[[BASEVREG]]:gr64
108 %0:gr64 = SUBREG_TO_REG 0, killed %3, %subreg.sub_32bit
109 %4:gr64_nosp = SHL64ri %0, 9, implicit-def dead $eflags
110 %1:gr64 = LEA64r %4, 4, %4, 0, $noreg
111 %5:gr32 = MOV32r0 implicit-def dead $eflags
112 %6:gr8 = COPY %5.sub_8bit
113 %100:gr64 = COPY %0:gr64
114 TEST8rr %6, %6, implicit-def $eflags
115 JCC_1 %bb.2, 5, implicit $eflags
121 ; Check for CSE happening and DBG_VALUE updating.
122 ; CHECK-LABEL: bb.1.bb1:
125 ; CHECK: DBG_VALUE %[[BASEVREG]], $noreg, ![[METAVAR]],
126 ; CHECK-NEXT: ADJCALLSTACKDOWN64
128 %7:gr64_nosp = SHL64ri %100, 9, implicit-def dead $eflags
129 %8:gr64 = LEA64r %7, 4, %7, 0, $noreg
130 DBG_VALUE %100, $noreg, !4, !DIExpression(), debug-location !7
131 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
133 CALL64pcrel32 @bar, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp
134 ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
137 ; As the COPY to %100 dies, the DBG_VALUE below should be updated too.
138 ; CHECK-LABEL: bb.2.bb2:
139 ; CHECK: ADJCALLSTACKDOWN64
140 ; CHECK-NEXT: $rdi = COPY
141 ; CHECK-NEXT: DBG_VALUE %[[BASEVREG]], $noreg, ![[METAVAR]],
142 ; CHECK-NEXT: CALL64pcrel32
144 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
146 DBG_VALUE %100, $noreg, !4, !DIExpression(), debug-location !7
147 CALL64pcrel32 @baz, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp
148 ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
153 # CHECK-LABEL: name: u
154 tracksRegLiveness: true
156 - { reg: '$edi', virtual-reg: '%2' }
161 successors: %bb.1(0x40000000), %bb.2(0x40000000)
164 ; In this function, the COPY to %100 should not be optimized out, and as a
165 ; result the DBG_VALUEs should not be rewritten.
166 ; CHECK-LABEL: bb.0.entry:
167 ; CHECK: %[[BASEVREG:[0-9]+]]:gr64 = SUBREG_TO_REG
168 ; CHECK: %[[COPIEDVREG:[0-9]+]]:gr64 = COPY %[[BASEVREG]]
172 %0:gr64 = SUBREG_TO_REG 0, killed %3, %subreg.sub_32bit
173 %4:gr64_nosp = SHL64ri %0, 9, implicit-def dead $eflags
174 %1:gr64 = LEA64r %4, 4, %4, 0, $noreg
175 %5:gr32 = MOV32r0 implicit-def dead $eflags
176 %6:gr8 = COPY %5.sub_8bit
177 %100:gr64 = COPY %0:gr64
178 TEST8rr %6, %6, implicit-def $eflags
179 JCC_1 %bb.2, 5, implicit $eflags
185 ; CSE should happen, DBG_VALUE updating should not.
186 ; CHECK-LABEL: bb.1.bb1:
189 ; CHECK: DBG_VALUE %[[COPIEDVREG]], $noreg, ![[METAVAR]],
190 ; CHECK-NEXT: ADJCALLSTACKDOWN64
194 %7:gr64_nosp = SHL64ri %100, 9, implicit-def dead $eflags
195 %8:gr64 = LEA64r %7, 4, %7, 0, $noreg
196 DBG_VALUE %100, $noreg, !4, !DIExpression(), debug-location !7
197 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
199 CALL64pcrel32 @bar, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp
200 ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
204 ; Test that the copy-read of %100 below is preserved, and the DBG_VALUE
206 ; CHECK-LABEL: bb.2.bb2:
207 ; CHECK: ADJCALLSTACKDOWN64
208 ; CHECK-NEXT: $rdi = COPY %[[COPIEDVREG]]
209 ; CHECK-NEXT: DBG_VALUE %[[COPIEDVREG]], $noreg, ![[METAVAR]],
210 ; CHECK-NEXT: CALL64pcrel32
212 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
214 DBG_VALUE %100, $noreg, !4, !DIExpression(), debug-location !7
215 CALL64pcrel32 @baz, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp
216 ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp