brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.3 KiB · bd49278 Raw
238 lines · plain
1# RUN: llc -mtriple=x86_64-unknown-unknown -run-pass=machine-sink -o - %s | FileCheck %s2# In the first test, check various things when we sink machine instructions:3#   a) DBG_VALUEs should sink with defs4#   b) Undefs should be left behind5#   c) DBG_VALUEs not immediately following the defining inst should sink too6#   d) If we generate debug-use-before-defs through sinking, and can copy7#      propagate to a different value, we should do that.8#9# Test two checks DBG_VALUEs do not sink past a DBG_VALUE in the same block10# that redefines the variable location, while three checks that copy-propagation11# happens in the same scenario.12--- |13  target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"14  target triple = "x86_64-unknown-linux-gnu"15 16  @x = common local_unnamed_addr global i32 0, align 4, !dbg !017 18  ; Function Attrs: noreturn nounwind uwtable19  define void @Process(ptr nocapture readonly %p) local_unnamed_addr !dbg !9 {20  ; Stripped21  entry:22    br label %nou23  nou:24    br label %exit25  exit:26    ret void27  }28 29  define void @test2(ptr nocapture readonly %p) local_unnamed_addr !dbg !101 {30  ; Stripped31  entry:32    br label %block133  block1:34    br label %exit35  exit:36    ret void37  }38 39  define void @test3(ptr nocapture readonly %p) local_unnamed_addr !dbg !201 {40  ; Stripped41  entry:42    br label %block143  block1:44    br label %exit45  exit:46    ret void47  }48 49  ; Function Attrs: nounwind readnone50  declare void @llvm.dbg.value(metadata, i64, metadata, metadata)51 52  !llvm.dbg.cu = !{!1}53  !llvm.module.flags = !{!6, !7}54  !llvm.ident = !{!8}55 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: "")59  !3 = !{}60  !4 = !{!0}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)67  !11 = !{null, !12}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)71  !15 = !{!16}72  !16 = !DILocalVariable(name: "p", arg: 1, scope: !9, file: !2, line: 2, type: !12)73  !17 = !DIExpression()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)77  !102 = !{!103}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)81  !202 = !{!203}82  !203 = !DILocalVariable(name: "r", arg: 1, scope: !201, file: !2, line: 2, type: !12)83  !204 = !DILocation(line: 1, column: 1, scope: !201)84 85  ; CHECK: [[VARNUM:![0-9]+]] = !DILocalVariable(name: "p",86  ; CHECK: [[VAR2NUM:![0-9]+]] = !DILocalVariable(name: "q",87  ; CHECK: [[VAR3NUM:![0-9]+]] = !DILocalVariable(name: "r",88 89...90---91name:            Process92tracksRegLiveness: true93liveins:94  - { reg: '$rdi', virtual-reg: '%2' }95  - { reg: '$rsi', virtual-reg: '%2' }96body:             |97  bb.0.entry:98    successors: %bb.1.nou(0x80000000), %bb.2.exit99    liveins: $rdi, $esi100 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 $rdi105    ; CHECK-NEXT:  CMP32ri $esi, 0106    ; CHECK-NEXT:  DBG_VALUE [[ARG0VREG]], $noreg, [[VARNUM]]107    ; CHECK-NEXT:  JCC_1 %bb.1, 4108    ; CHECK-NEXT:  JMP_1109 110    %2:gr64 = COPY $rdi111    %5:gr64 = COPY %2112    CMP32ri $esi, 0, implicit-def $eflags113    DBG_VALUE %5, $noreg, !16, !17, debug-location !18114    JCC_1 %bb.1.nou, 4, implicit $eflags115    JMP_1 %bb.2.exit116 117  bb.1.nou:118    successors: %bb.2.exit(0x80000000)119 120    ; This block should receive the sunk copy and DBG_VALUE121    ; CHECK-LABEL: bb.1.nou:122    ; CHECK:       [[SUNKVREG:%[0-9]+]]:gr64 = COPY [[ARG0VREG]]123    ; CHECK-NEXT:  DBG_VALUE [[SUNKVREG]], $noreg, [[VARNUM]]124    ; CHECK-NEXT:  ADD64ri32125    ; CHECK-NEXT:  JMP_1126    %1:gr64 = ADD64ri32 %5, 4, implicit-def dead $eflags127    JMP_1 %bb.2.exit128 129  bb.2.exit:130    ; The DBG_VALUE below should have its operand copy-propagated after131    ; 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]]135    ; CHECK-NEXT:  RET 0136    DBG_VALUE %5, _, !16, !17, debug-location !18137    $rax = MOV64rr %2138    RET 0139...140---141name:            test2142tracksRegLiveness: true143liveins:144  - { reg: '$rdi', virtual-reg: '%2' }145  - { reg: '$rsi', virtual-reg: '%2' }146body:             |147  bb.0.entry:148    successors: %bb.1.block1, %bb.2.exit149    liveins: $rdi, $esi150 151    ; This block should _not_ have the first DBG_VALUE sunk out from it, as it152    ; would pass a later DBG_VALUE of the same variable location. An undef153    ; DBG_VALUE should be left behind though.154    ; CHECK-LABEL: bb.0.entry:155    ; CHECK:       [[TEST2VREG:%[0-9]+]]:gr64 = COPY $rdi156    ; CHECK-NEXT:  CMP32ri $esi, 0157    ; CHECK-NEXT:  DBG_VALUE $noreg, $noreg, [[VAR2NUM]]158    ; CHECK-NEXT:  CMP32ri $esi, 0159    ; CHECK-NEXT:  DBG_VALUE 0, $noreg, [[VAR2NUM]]160    ; CHECK-NEXT:  JCC_1 %bb.1, 4161    ; CHECK-NEXT:  JMP_1162 163    %2:gr64 = COPY $rdi164    %5:gr64 = ADD64ri32 %2, 1, implicit-def dead $eflags165    CMP32ri $esi, 0, implicit-def $eflags166    DBG_VALUE %5, $noreg, !103, !17, debug-location !104167    CMP32ri $esi, 0, implicit-def $eflags168    DBG_VALUE 0, $noreg, !103, !17, debug-location !104169    JCC_1 %bb.1.block1, 4, implicit $eflags170    JMP_1 %bb.2.exit171 172  bb.1.block1:173    successors: %bb.2.exit174 175    ; This block should receive no DBG_VALUE.176    ; CHECK-LABEL: bb.1.block1:177    ; CHECK-NOT:   DBG_VALUE178    ; CHECK:       [[SUNKVREG2:%[0-9]+]]:gr64 = ADD64ri32 [[TEST2VREG]]179    ; CHECK-NOT:   DBG_VALUE180    ; CHECK-NEXT:  ADD64ri32181    ; CHECK: JMP_1 %bb.2182    %1:gr64 = ADD64ri32 %5, 4, implicit-def dead $eflags183    JMP_1 %bb.2.exit184 185  bb.2.exit:186    $rax = MOV64rr %2187    RET 0188...189---190name:            test3191tracksRegLiveness: true192liveins:193  - { reg: '$rdi', virtual-reg: '%2' }194  - { reg: '$rsi', virtual-reg: '%2' }195body:             |196  bb.0.entry:197    successors: %bb.1.block1, %bb.2.exit198    liveins: $rdi, $esi199 200    ; The copy from %2 to %5 will sink into a later block, and the first201    ; DBG_VALUE cannot pass the second. But, we should be able to recover202    ; the variable location through copy propagation.203    ; CHECK-LABEL: bb.0.entry:204    ; CHECK:       [[TEST3VREG:%[0-9]+]]:gr64 = COPY $rdi205    ; CHECK-NEXT:  CMP32ri $esi, 0206    ; CHECK-NEXT:  DBG_VALUE [[TEST3VREG]], $noreg, [[VAR3NUM]]207    ; CHECK-NEXT:  CMP32ri $esi, 0208    ; CHECK-NEXT:  DBG_VALUE 0, $noreg, [[VAR3NUM]]209    ; CHECK-NEXT:  JCC_1 %bb.1, 4210    ; CHECK-NEXT:  JMP_1211 212    %2:gr64 = COPY $rdi213    %5:gr64 = COPY %2214    CMP32ri $esi, 0, implicit-def $eflags215    DBG_VALUE %5, $noreg, !203, !17, debug-location !204216    CMP32ri $esi, 0, implicit-def $eflags217    DBG_VALUE 0, $noreg, !203, !17, debug-location !204218    JCC_1 %bb.1.block1, 4, implicit $eflags219    JMP_1 %bb.2.exit220 221  bb.1.block1:222    successors: %bb.2.exit223 224    ; This block should receive no DBG_VALUE.225    ; CHECK-LABEL: bb.1.block1:226    ; CHECK-NOT:   DBG_VALUE227    ; CHECK:       COPY [[TEST3VREG]]228    ; CHECK-NOT:   DBG_VALUE229    ; CHECK-NEXT:  ADD64ri32230    ; CHECK: JMP_1 %bb.2231    %1:gr64 = ADD64ri32 %5, 4, implicit-def dead $eflags232    JMP_1 %bb.2.exit233 234  bb.2.exit:235    $rax = MOV64rr %2236    RET 0237...238