338 lines · plain
1# RUN: llc -mtriple=x86_64-unknown-unknown -mcpu=btver2 -run-pass=post-RA-sched -o - %s | FileCheck %s2# RUN: llc -mtriple=x86_64-unknown-unknown -mcpu=btver2 -passes=post-RA-sched -o - %s | FileCheck %s3# RUN: llc -mtriple=x86_64-unknown-unknown -mcpu=btver2 -run-pass=post-RA-sched -o - %s -experimental-debug-variable-locations| FileCheck %s4# RUN: llc -mtriple=x86_64-unknown-unknown -mcpu=btver2 -passes=post-RA-sched -o - %s -experimental-debug-variable-locations| FileCheck %s5 6# Test that multiple DBG_VALUE's and DBG_PHIs following an instruction whose7# register needs # to be changed during the post-RA scheduler pass are updated8# correctly.9 10# Test case was derived from the output from the following command and11# the source code below. DBG_PHIs added manually later:12#13# clang -S -emit-llvm -target x86_64 -march=btver2 -O2 -g -o - <srcfile> |14# llc -stop-before=post-RA-sched -o -15#16# Source code reduced from the original 8MB source file:17#18# struct a;19# class b {20# public:21# a *c = ap;22# unsigned *d() { return (unsigned *)c; }23# a *ap;24# };25# enum { e = 2 };26# template <typename f> f *g(f *h, f *i) {27# long j = long(i), k = -!h;28# return reinterpret_cast<f *>(long(h) | k & j);29# }30# class l {31# public:32# l(int);33# int m;34# };35# unsigned *n;36# unsigned o;37# class p {38# public:39# int aa();40# unsigned *q() {41# n = r.d();42# return g(n, &o);43# }44# b r;45# };46# class s : l {47# public:48# p t;49# s(int h) : l(h), ab(t), ac(~0 << h) { ae(); }50# p &ab;51# int ac;52# void ae() {53# const unsigned *v;54# const unsigned u = 0;55# v = ab.q();56# const unsigned *x = g(v, &u);57# int w = x[m] & ac;58# while (w) {59# int z = (ab.aa() - 1) / e;60# if (m <= z)61# return;62# }63# }64# };65# class ad {66# public:67# ~ad() {68# for (y();;)69# ;70# }71# class y {72# public:73# y() : af(0) {}74# s af;75# };76# };77# class ag {78# ad ah;79# };80# enum ai {};81# class aj {82# public:83# aj(unsigned(ai));84# ag ak;85# };86# struct al {87# static unsigned am(ai);88# };89# template <int> struct an : al { static aj ao; };90# template <> aj an<0>::ao(am);91 92--- |93 94 %class.s = type <{ %class.l, [4 x i8], %class.p, ptr, i32, [4 x i8] }>95 %class.l = type { i32 }96 %class.p = type { %class.b }97 %class.b = type { ptr, ptr }98 %struct.a = type opaque99 100 @n = local_unnamed_addr global ptr null, align 8101 @o = global i32 0, align 4102 103 define linkonce_odr void @_ZN1sC2Ei(ptr, i32) unnamed_addr #0 align 2 !dbg !4 {104 %3 = alloca i32, align 4105 %4 = bitcast ptr %0 to ptr106 tail call void @_ZN1lC2Ei(ptr %4, i32 %1)107 %5 = getelementptr inbounds %class.s, ptr %0, i64 0, i32 2108 tail call void @llvm.dbg.value(metadata ptr %5, i64 0, metadata !10, metadata !17), !dbg !18109 tail call void @llvm.dbg.value(metadata ptr %5, i64 0, metadata !20, metadata !17), !dbg !27110 %6 = getelementptr inbounds %class.s, ptr %0, i64 0, i32 2, i32 0, i32 1111 %7 = bitcast ptr %6 to ptr112 %8 = load i64, ptr %7, align 8113 %9 = bitcast ptr %5 to ptr114 store i64 %8, ptr %9, align 8115 %10 = getelementptr inbounds %class.s, ptr %0, i64 0, i32 3116 store ptr %5, ptr %10, align 8117 %11 = getelementptr inbounds %class.s, ptr %0, i64 0, i32 4118 %12 = shl i32 -1, %1119 store i32 %12, ptr %11, align 8120 store i32 0, ptr %3, align 4121 %13 = bitcast ptr %5 to ptr122 %14 = load ptr, ptr %13, align 8123 store ptr %14, ptr @n, align 8124 %15 = icmp eq ptr %14, null125 %16 = ptrtoint ptr %14 to i64126 %17 = select i1 %15, i64 ptrtoint (ptr @o to i64), i64 0127 %18 = or i64 %17, %16128 tail call void @llvm.dbg.value(metadata ptr %3, i64 0, metadata !29, metadata !35), !dbg !36129 tail call void @llvm.dbg.value(metadata ptr %3, i64 0, metadata !39, metadata !17), !dbg !44130 %19 = ptrtoint ptr %3 to i64131 call void @llvm.dbg.value(metadata i64 %19, i64 0, metadata !46, metadata !17), !dbg !48132 %20 = icmp eq i64 %18, 0133 %21 = select i1 %20, i64 %19, i64 0134 %22 = or i64 %21, %18135 %23 = inttoptr i64 %22 to ptr136 %24 = bitcast ptr %0 to ptr137 %25 = load i32, ptr %24, align 8138 %26 = sext i32 %25 to i64139 %27 = getelementptr inbounds i32, ptr %23, i64 %26140 %28 = load i32, ptr %27, align 4141 %29 = and i32 %12, %28142 %30 = icmp eq i32 %29, 0143 br i1 %30, label %47, label %31144 145 ; <label>:31: ; preds = %2146 %32 = bitcast ptr %0 to ptr147 %33 = call i32 @_ZN1p2aaEv(ptr %5)148 %34 = add nsw i32 %33, -1149 %35 = sdiv i32 %34, 2150 %36 = load i32, ptr %32, align 8151 %37 = icmp sgt i32 %36, %35152 br i1 %37, label %38, label %47153 154 ; <label>:38: ; preds = %31155 br label %39156 157 ; <label>:39: ; preds = %39, %38158 %40 = bitcast ptr %0 to ptr159 %sunkaddr = ptrtoint ptr %0 to i64160 %sunkaddr1 = add i64 %sunkaddr, 24161 %sunkaddr2 = inttoptr i64 %sunkaddr1 to ptr162 %41 = load ptr, ptr %sunkaddr2, align 8163 %42 = call i32 @_ZN1p2aaEv(ptr %41)164 %43 = add nsw i32 %42, -1165 %44 = sdiv i32 %43, 2166 %45 = load i32, ptr %40, align 8167 %46 = icmp sgt i32 %45, %44168 br i1 %46, label %39, label %47169 170 ; <label>:47: ; preds = %39, %31, %2171 ret void172 }173 174 declare void @_ZN1lC2Ei(ptr, i32) unnamed_addr #1175 176 declare i32 @_ZN1p2aaEv(ptr) local_unnamed_addr #1177 178 ; Function Attrs: nounwind readnone179 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2180 181 !llvm.dbg.cu = !{!0}182 !llvm.module.flags = !{!2, !3}183 184 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)185 !1 = !DIFile(filename: "test.cpp", directory: "")186 !2 = !{i32 2, !"Dwarf Version", i32 4}187 !3 = !{i32 2, !"Debug Info Version", i32 3}188 !4 = distinct !DISubprogram(name: "s", linkageName: "_ZN1sC2Ei", scope: !5, file: !1, line: 32, type: !6, isLocal: false, isDefinition: true, scopeLine: 32, flags: DIFlagPrototyped, isOptimized: true, unit: !0)189 !5 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "s", file: !1, line: 29, size: 320, identifier: "_ZTS1s")190 !6 = !DISubroutineType(types: !7)191 !7 = !{null, !8, !9}192 !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)193 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)194 !10 = !DILocalVariable(name: "this", arg: 1, scope: !11, type: !16, flags: DIFlagArtificial | DIFlagObjectPointer)195 !11 = distinct !DISubprogram(name: "p", linkageName: "_ZN1pC2Ev", scope: !12, file: !1, line: 20, type: !13, isLocal: false, isDefinition: true, scopeLine: 20, flags: DIFlagArtificial | DIFlagPrototyped, isOptimized: true, unit: !0)196 !12 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "p", file: !1, line: 20, size: 128, identifier: "_ZTS1p")197 !13 = !DISubroutineType(types: !14)198 !14 = !{null, !15}199 !15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)200 !16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)201 !17 = !DIExpression()202 !18 = !DILocation(line: 0, scope: !11, inlinedAt: !19)203 !19 = distinct !DILocation(line: 32, column: 3, scope: !4)204 !20 = !DILocalVariable(name: "this", arg: 1, scope: !21, type: !26, flags: DIFlagArtificial | DIFlagObjectPointer)205 !21 = distinct !DISubprogram(name: "b", linkageName: "_ZN1bC2Ev", scope: !22, file: !1, line: 2, type: !23, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagArtificial | DIFlagPrototyped, isOptimized: true, unit: !0)206 !22 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "b", file: !1, line: 2, size: 128, identifier: "_ZTS1b")207 !23 = !DISubroutineType(types: !24)208 !24 = !{null, !25}209 !25 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !22, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)210 !26 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !22, size: 64)211 !27 = !DILocation(line: 0, scope: !21, inlinedAt: !28)212 !28 = distinct !DILocation(line: 20, column: 7, scope: !11, inlinedAt: !19)213 !29 = !DILocalVariable(name: "u", scope: !30, file: !1, line: 37, type: !33)214 !30 = distinct !DISubprogram(name: "ae", linkageName: "_ZN1s2aeEv", scope: !5, file: !1, line: 35, type: !31, isLocal: false, isDefinition: true, scopeLine: 35, flags: DIFlagPrototyped, isOptimized: true, unit: !0)215 !31 = !DISubroutineType(types: !32)216 !32 = !{null, !8}217 !33 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !34)218 !34 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)219 !35 = !DIExpression(DW_OP_deref)220 !36 = !DILocation(line: 37, column: 20, scope: !30, inlinedAt: !37)221 !37 = distinct !DILocation(line: 32, column: 41, scope: !38)222 !38 = distinct !DILexicalBlock(scope: !4, file: !1, line: 32, column: 39)223 !39 = !DILocalVariable(name: "i", arg: 2, scope: !40, file: !1, line: 9, type: !43)224 !40 = distinct !DISubprogram(name: "g<const unsigned int>", linkageName: "_Z1gIKjEPT_S2_S2_", scope: !1, file: !1, line: 9, type: !41, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: true, unit: !0)225 !41 = !DISubroutineType(types: !42)226 !42 = !{!43, !43, !43}227 !43 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !33, size: 64)228 !44 = !DILocation(line: 9, column: 37, scope: !40, inlinedAt: !45)229 !45 = distinct !DILocation(line: 39, column: 25, scope: !30, inlinedAt: !37)230 !46 = !DILocalVariable(name: "j", scope: !40, file: !1, line: 10, type: !47)231 !47 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)232 !48 = !DILocation(line: 10, column: 8, scope: !40, inlinedAt: !45)233 234# CHECK: ![[I_VAR:[0-9]+]] = !DILocalVariable(name: "i", {{.*}}line: 9, {{.*}})235# CHECK: ![[I_LOC:[0-9]+]] = !DILocation(line: 9, column: 37, {{.*}})236# CHECK: ![[J_VAR:[0-9]+]] = !DILocalVariable(name: "j", {{.*}}line: 10, {{.*}})237# CHECK: ![[J_LOC:[0-9]+]] = !DILocation(line: 10, column: 8, {{.*}})238 239...240---241name: _ZN1sC2Ei242tracksRegLiveness: true243liveins:244 - { reg: '$rdi' }245 - { reg: '$esi' }246fixedStack:247 - { id: 0, type: spill-slot, offset: -32, size: 8, alignment: 16, callee-saved-register: '$rbx' }248 - { id: 1, type: spill-slot, offset: -24, size: 8, alignment: 8, callee-saved-register: '$r14' }249 - { id: 2, type: spill-slot, offset: -16, size: 8, alignment: 16 }250stack:251 - { id: 0, offset: -36, size: 4, alignment: 4 }252body: |253 bb.0:254 successors: %bb.3, %bb.2255 liveins: $esi, $rdi, $r14, $rbx, $rbp256 257 ; CHECK: [[REGISTER:\$r[a-z0-9]+]] = LEA64r {{\$r[a-z0-9]+}}, 1, $noreg, -20, $noreg258 ; CHECK-NEXT: DBG_VALUE [[REGISTER]], $noreg, ![[J_VAR]], !DIExpression(), debug-location ![[J_LOC]]259 ; CHECK-NEXT: DBG_VALUE [[REGISTER]], $noreg, ![[I_VAR]], !DIExpression(), debug-location ![[I_LOC]]260 ; CHECK-NEXT: DBG_PHI [[REGISTER]], 0261 ; CHECK-NEXT: DBG_PHI [[REGISTER]], 1262 263 frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp264 CFI_INSTRUCTION def_cfa_offset 16265 CFI_INSTRUCTION offset $rbp, -16266 $rbp = frame-setup MOV64rr $rsp267 CFI_INSTRUCTION def_cfa_register $rbp268 frame-setup PUSH64r killed $r14, implicit-def $rsp, implicit $rsp269 frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp270 $rsp = frame-setup SUB64ri8 $rsp, 16, implicit-def dead $eflags271 CFI_INSTRUCTION offset $rbx, -32272 CFI_INSTRUCTION offset $r14, -24273 $r14d = MOV32rr $esi274 $rbx = MOV64rr $rdi275 CALL64pcrel32 @_ZN1lC2Ei, csr_64, implicit $rsp, implicit $rdi, implicit $esi, implicit-def $rsp276 $rdi = LEA64r $rbx, 1, $noreg, 8, $noreg277 DBG_VALUE $rdi, $noreg, !20, !17, debug-location !27278 DBG_VALUE $rdi, $noreg, !10, !17, debug-location !18279 $rax = MOV64rm $rbx, 1, $noreg, 16, $noreg :: (load (s64))280 MOV64mr $rbx, 1, $noreg, 8, $noreg, killed $rax :: (store (s64))281 MOV64mr $rbx, 1, $noreg, 24, $noreg, $rdi :: (store (s64))282 $eax = MOV32ri -1283 $cl = MOV8rr $r14b, implicit killed $r14d284 $eax = SHL32rCL killed $eax, implicit-def dead $eflags, implicit $cl285 MOV32mr $rbx, 1, $noreg, 32, $noreg, $eax :: (store (s32), align 8)286 MOV32mi $rbp, 1, $noreg, -20, $noreg, 0 :: (store (s32))287 $rcx = MOV64rm $rbx, 1, $noreg, 8, $noreg :: (load (s64))288 MOV64mr $rip, 1, $noreg, @n, $noreg, $rcx :: (store (s64))289 $edx = XOR32rr undef $edx, undef $edx, implicit-def dead $eflags, implicit-def $rdx290 TEST64rr $rcx, $rcx, implicit-def $eflags291 $esi = MOV32ri @o, implicit-def $rsi292 $rsi = CMOV64rr killed $rsi, $rdx, 5, implicit killed $eflags293 $rsi = OR64rr killed $rsi, killed $rcx, implicit-def $eflags294 $rcx = LEA64r $rbp, 1, $noreg, -20, $noreg295 DBG_VALUE $rcx, $noreg, !46, !17, debug-location !48296 DBG_VALUE $rcx, $noreg, !39, !17, debug-location !44297 DBG_PHI $rcx, 0298 DBG_PHI $rcx, 1299 DBG_VALUE $rbp, -20, !29, !17, debug-location !36300 $rcx = CMOV64rr killed $rcx, killed $rdx, 5, implicit killed $eflags301 $rcx = OR64rr killed $rcx, killed $rsi, implicit-def dead $eflags302 $rdx = MOVSX64rm32 $rbx, 1, $noreg, 0, $noreg :: (load (s32), align 8)303 DBG_INSTR_REF !46, !17, dbg-instr-ref(1, 0), debug-location !48304 DBG_INSTR_REF !39, !17, dbg-instr-ref(2, 0), debug-location !44305 TEST32mr killed $rcx, 4, killed $rdx, 0, $noreg, killed $eax, implicit-def $eflags :: (load (s32))306 JCC_1 %bb.2, 5, implicit $eflags307 JMP_1 %bb.3308 309 bb.1:310 successors: %bb.2311 liveins: $rbx, $rbp312 313 $rdi = MOV64rm $rbx, 1, $noreg, 24, $noreg :: (load (s64))314 315 bb.2:316 successors: %bb.1, %bb.3317 liveins: $rbx, $rbp, $rsp, $rdi318 319 CALL64pcrel32 @_ZN1p2aaEv, csr_64, implicit $rsp, implicit $rdi, implicit-def $rsp, implicit-def $eax320 $eax = KILL $eax, implicit-def $rax321 $ecx = LEA64_32r $rax, 1, $noreg, -1, $noreg, implicit-def $rcx322 $ecx = SHR32ri $ecx, 31, implicit-def dead $eflags, implicit killed $rcx, implicit-def $rcx323 $eax = LEA64_32r killed $rax, 1, killed $rcx, -1, $noreg324 $eax = SAR32r1 killed $eax, implicit-def dead $eflags325 CMP32mr $rbx, 1, $noreg, 0, $noreg, killed $eax, implicit-def $eflags :: (load (s32), align 8), (load (s32), align 8)326 JCC_1 %bb.1, 15, implicit killed $eflags327 328 bb.3:329 liveins: $rbp330 331 $rsp = ADD64ri8 $rsp, 16, implicit-def dead $eflags332 $rbx = POP64r implicit-def $rsp, implicit $rsp333 $r14 = POP64r implicit-def $rsp, implicit $rsp334 $rbp = POP64r implicit-def $rsp, implicit $rsp335 RET64336 337...338