221 lines · plain
1# RUN: llc %s -o - -run-pass=machine-cse -mtriple=x86_64-- | FileCheck %s2# RUN: llc %s -o - -passes=machine-cse -mtriple=x86_64-- | FileCheck %s3#4# This test examines machine-cse's behaviour when dealing with copy propagation,5# the code for which is lifted from test/CodeGen/X86/machine-cse.ll. There are6# two (MIR) function that have SHL/LEA instructions CSE'd in the bb.1.bb1 block.7# They both depend on the COPY of a vreg to %100 in the entry block.8#9# In the first (@t) there's only one use of %100, and that gets CSE'd away. The10# corresponding COPY is deleted, and all DBG_VALUEs that refer to it must be11# updated.12#13# In the second (@u) there are two uses of %100, one of which isn't deleted. The14# DBG_VALUE users of %100 don't need to be updated -- test that they're not.15--- |16 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"17 target triple = "x86_64-unknown-unknown"18 19 %struct.s2 = type { i32, ptr, ptr, [256 x ptr], [8 x i32], i64, ptr, i32, i64, i64, i32, ptr, ptr, [49 x i64] }20 %struct.s1 = type { %ptr, %ptr }21 %ptr = type { ptr }22 %struct.s3 = type { ptr, ptr, i32, i32, i32 }23 24 ; Function Attrs: nounwind readnone speculatable25 declare void @llvm.dbg.value(metadata, metadata, metadata) #026 27 define fastcc ptr @t(i32 %base, i1 %arg) !dbg !3 {28 entry:29 %0 = zext i32 %base to i6430 %1 = getelementptr inbounds %struct.s2, ptr null, i64 %031 br i1 %arg, label %bb1, label %bb232 33 bb1: ; preds = %entry34 %2 = getelementptr inbounds %struct.s2, ptr null, i64 %0, i32 035 call void @llvm.dbg.value(metadata ptr %2, metadata !4, metadata !DIExpression()), !dbg !736 call void @bar(ptr %2)37 unreachable38 39 bb2: ; preds = %entry40 %3 = ptrtoint ptr %1 to i6441 call void @baz(i64 %3)42 unreachable43 }44 45 ; This is a stub replicating bb structure of @t46 define fastcc ptr @u(i32 %base, i1 %arg) !dbg !33 {47 entry:48 br i1 %arg, label %bb1, label %bb249 50 bb1: ; preds = %entry51 unreachable52 53 bb2: ; preds = %entry54 unreachable55 }56 57 58 declare void @bar(ptr)59 60 declare void @baz(i64)61 62 declare ptr @foo(ptr)63 64 ; Function Attrs: nounwind65 declare void @llvm.stackprotector(ptr, ptr) #166 67 attributes #0 = { nounwind readnone speculatable }68 attributes #1 = { nounwind }69 70 !llvm.module.flags = !{!0}71 !llvm.dbg.cu = !{!1}72 73 !0 = !{i32 2, !"Debug Info Version", i32 3}74 !1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "beards", isOptimized: true, runtimeVersion: 4, emissionKind: FullDebug)75 !2 = !DIFile(filename: "bees.cpp", directory: "")76 !3 = distinct !DISubprogram(name: "nope", scope: !1, file: !2, line: 1, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !9)77 !33 = distinct !DISubprogram(name: "alsonope", scope: !1, file: !2, line: 1, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !9)78 !4 = !DILocalVariable(name: "bees", scope: !3, type: !5)79 !5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64)80 !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)81 !7 = !DILocation(line: 0, scope: !3)82 !8 = !{!4}83 !9 = !{}84 85 86 ; CHECK: ![[METAVAR:[0-9]+]] = !DILocalVariable(name: "bees",87 88...89---90name: t91# CHECK-LABEL: name: t92tracksRegLiveness: true93liveins: 94 - { reg: '$edi', virtual-reg: '%2' }95frameInfo: 96 hasCalls: true97body: |98 bb.0.entry:99 successors: %bb.1(0x40000000), %bb.2(0x40000000)100 liveins: $edi101 102 ; Capture vreg num for subreg move for later checks; test that the COPY103 ; of that vreg is optimized out.104 ; CHECK-LABEL: bb.0.entry:105 ; CHECK: %[[BASEVREG:[0-9]+]]:gr64 = SUBREG_TO_REG106 ; CHECK-NOT: COPY %[[BASEVREG]]:gr64107 108 %2:gr32 = COPY $edi109 %3:gr32 = MOV32rr %2110 %0:gr64 = SUBREG_TO_REG 0, killed %3, %subreg.sub_32bit111 %4:gr64_nosp = SHL64ri %0, 9, implicit-def dead $eflags112 %1:gr64 = LEA64r %4, 4, %4, 0, $noreg113 %5:gr32 = MOV32r0 implicit-def dead $eflags114 %6:gr8 = COPY %5.sub_8bit115 %100:gr64 = COPY %0:gr64116 TEST8rr %6, %6, implicit-def $eflags117 JCC_1 %bb.2, 5, implicit $eflags118 JMP_1 %bb.1119 120 bb.1.bb1:121 successors: 122 123 ; Check for CSE happening and DBG_VALUE updating.124 ; CHECK-LABEL: bb.1.bb1:125 ; CHECK-NOT: SHL64ri126 ; CHECK-NOT: LEA64r127 ; CHECK: DBG_VALUE %[[BASEVREG]], $noreg, ![[METAVAR]],128 ; CHECK-NEXT: ADJCALLSTACKDOWN64129 130 %7:gr64_nosp = SHL64ri %100, 9, implicit-def dead $eflags131 %8:gr64 = LEA64r %7, 4, %7, 0, $noreg132 DBG_VALUE %100, $noreg, !4, !DIExpression(), debug-location !7133 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp134 $rdi = COPY %8135 CALL64pcrel32 @bar, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp136 ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp137 138 bb.2.bb2:139 ; As the COPY to %100 dies, the DBG_VALUE below should be updated too.140 ; CHECK-LABEL: bb.2.bb2:141 ; CHECK: ADJCALLSTACKDOWN64142 ; CHECK-NEXT: $rdi = COPY143 ; CHECK-NEXT: DBG_VALUE %[[BASEVREG]], $noreg, ![[METAVAR]],144 ; CHECK-NEXT: CALL64pcrel32145 146 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp147 $rdi = COPY %1148 DBG_VALUE %100, $noreg, !4, !DIExpression(), debug-location !7149 CALL64pcrel32 @baz, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp150 ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp151 152...153---154name: u155# CHECK-LABEL: name: u156tracksRegLiveness: true157liveins: 158 - { reg: '$edi', virtual-reg: '%2' }159frameInfo: 160 hasCalls: true161body: |162 bb.0.entry:163 successors: %bb.1(0x40000000), %bb.2(0x40000000)164 liveins: $edi165 166 ; In this function, the COPY to %100 should not be optimized out, and as a167 ; result the DBG_VALUEs should not be rewritten.168 ; CHECK-LABEL: bb.0.entry:169 ; CHECK: %[[BASEVREG:[0-9]+]]:gr64 = SUBREG_TO_REG170 ; CHECK: %[[COPIEDVREG:[0-9]+]]:gr64 = COPY %[[BASEVREG]]171 172 %2:gr32 = COPY $edi173 %3:gr32 = MOV32rr %2174 %0:gr64 = SUBREG_TO_REG 0, killed %3, %subreg.sub_32bit175 %4:gr64_nosp = SHL64ri %0, 9, implicit-def dead $eflags176 %1:gr64 = LEA64r %4, 4, %4, 0, $noreg177 %5:gr32 = MOV32r0 implicit-def dead $eflags178 %6:gr8 = COPY %5.sub_8bit179 %100:gr64 = COPY %0:gr64180 TEST8rr %6, %6, implicit-def $eflags181 JCC_1 %bb.2, 5, implicit $eflags182 JMP_1 %bb.1183 184 bb.1.bb1:185 successors: 186 187 ; CSE should happen, DBG_VALUE updating should not.188 ; CHECK-LABEL: bb.1.bb1:189 ; CHECK-NOT: SHL64ri190 ; CHECK-NOT: LEA64r191 ; CHECK: DBG_VALUE %[[COPIEDVREG]], $noreg, ![[METAVAR]],192 ; CHECK-NEXT: ADJCALLSTACKDOWN64193 194 195 196 %7:gr64_nosp = SHL64ri %100, 9, implicit-def dead $eflags197 %8:gr64 = LEA64r %7, 4, %7, 0, $noreg198 DBG_VALUE %100, $noreg, !4, !DIExpression(), debug-location !7199 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp200 $rdi = COPY %8201 CALL64pcrel32 @bar, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp202 ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp203 204 bb.2.bb2:205 206 ; Test that the copy-read of %100 below is preserved, and the DBG_VALUE207 ; operand is too.208 ; CHECK-LABEL: bb.2.bb2:209 ; CHECK: ADJCALLSTACKDOWN64210 ; CHECK-NEXT: $rdi = COPY %[[COPIEDVREG]]211 ; CHECK-NEXT: DBG_VALUE %[[COPIEDVREG]], $noreg, ![[METAVAR]],212 ; CHECK-NEXT: CALL64pcrel32213 214 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp215 $rdi = COPY %100216 DBG_VALUE %100, $noreg, !4, !DIExpression(), debug-location !7217 CALL64pcrel32 @baz, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp218 ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp219 220...221