1# RUN: llc -start-after=machine-scheduler %s -o - | FileCheck %s
2
3# C source:
4# void escape(int *);
5# extern int global;
6# void f(int x) {
7#   escape(&x);
8#   x = 1;
9#   global = x;
10#   x = 2;
11#   escape(&x);
12# }
13
14# CHECK-LABEL: f: # @f
15# CHECK: movl    %ecx, [[OFF_X:[0-9]+]](%rsp)
16# CHECK: #DEBUG_VALUE: f:x <- [DW_OP_plus_uconst [[OFF_X]]] [$rsp+0]
17# CHECK: leaq [[OFF_X]](%rsp), %rsi
18# CHECK: callq   escape
19# CHECK: #DEBUG_VALUE: f:x <- 1
20# CHECK: movl    $1, global(%rip)
21# CHECK: #DEBUG_VALUE: f:x <- [DW_OP_plus_uconst [[OFF_X]]] [$rsp+0]
22# CHECK: movl    $2, [[OFF_X]](%rsp)
23# CHECK: callq   escape
24# CHECK: retq
25
26
27--- |
28  ; ModuleID = '<stdin>'
29  source_filename = "dse.c"
30  target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
31  target triple = "x86_64-pc-windows-msvc19.0.24215"
32
33  @global = external global i32, align 4
34
35  ; Function Attrs: nounwind readnone speculatable
36  declare void @llvm.dbg.value(metadata, metadata, metadata) #0
37
38  declare void @escape(i32*)
39
40  ; Function Attrs: nounwind uwtable
41  define void @f(i32 %x) #1 !dbg !8 {
42  entry:
43    %x.addr = alloca i32, align 4
44    store i32 %x, i32* %x.addr, align 4
45    call void @llvm.dbg.value(metadata i32* %x.addr, metadata !13, metadata !DIExpression()), !dbg !14
46    call void @escape(i32* %x.addr), !dbg !15
47    call void @llvm.dbg.value(metadata i32 1, metadata !13, metadata !DIExpression()), !dbg !16
48    store i32 1, i32* @global, align 4, !dbg !17
49    call void @llvm.dbg.value(metadata i32* %x.addr, metadata !13, metadata !DIExpression()), !dbg !18
50    store i32 2, i32* %x.addr, align 4, !dbg !18
51    call void @escape(i32* %x.addr), !dbg !19
52    ret void, !dbg !20
53  }
54
55  ; Function Attrs: nounwind
56  declare void @llvm.stackprotector(i8*, i8**) #2
57
58  attributes #0 = { nounwind readnone speculatable }
59  attributes #1 = { nounwind uwtable }
60  attributes #2 = { nounwind }
61
62  !llvm.dbg.cu = !{!0}
63  !llvm.module.flags = !{!3, !4, !5, !6}
64  !llvm.ident = !{!7}
65
66  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
67  !1 = !DIFile(filename: "dse.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild")
68  !2 = !{}
69  !3 = !{i32 2, !"Dwarf Version", i32 4}
70  !4 = !{i32 2, !"Debug Info Version", i32 3}
71  !5 = !{i32 1, !"wchar_size", i32 2}
72  !6 = !{i32 7, !"PIC Level", i32 2}
73  !7 = !{!"clang version 6.0.0 "}
74  !8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 3, type: !9, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
75  !9 = !DISubroutineType(types: !10)
76  !10 = !{null, !11}
77  !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
78  !12 = !{!13}
79  !13 = !DILocalVariable(name: "x", arg: 1, scope: !8, file: !1, line: 3, type: !11)
80  !14 = !DILocation(line: 3, column: 12, scope: !8)
81  !15 = !DILocation(line: 4, column: 3, scope: !8)
82  !16 = !DILocation(line: 5, column: 5, scope: !8)
83  !17 = !DILocation(line: 6, column: 10, scope: !8)
84  !18 = !DILocation(line: 7, column: 5, scope: !8)
85  !19 = !DILocation(line: 8, column: 3, scope: !8)
86  !20 = !DILocation(line: 9, column: 1, scope: !8)
87
88...
89---
90name:            f
91alignment:       4
92exposesReturnsTwice: false
93legalized:       false
94regBankSelected: false
95selected:        false
96tracksRegLiveness: true
97registers:
98  - { id: 0, class: gr32, preferred-register: '' }
99  - { id: 1, class: gr64, preferred-register: '' }
100liveins:
101  - { reg: '$ecx', virtual-reg: '%0' }
102frameInfo:
103  isFrameAddressTaken: false
104  isReturnAddressTaken: false
105  hasStackMap:     false
106  hasPatchPoint:   false
107  stackSize:       0
108  offsetAdjustment: 0
109  maxAlignment:    8
110  adjustsStack:    false
111  hasCalls:        true
112  stackProtector:  ''
113  maxCallFrameSize: 4294967295
114  hasOpaqueSPAdjustment: false
115  hasVAStart:      false
116  hasMustTailInVarArgFunc: false
117  savePoint:       ''
118  restorePoint:    ''
119fixedStack:
120stack:
121  - { id: 0, name: x.addr, type: default, offset: 0, size: 4, alignment: 4,
122      stack-id: 0, callee-saved-register: '', debug-info-variable: '',
123      debug-info-expression: '', debug-info-location: '' }
124constants:
125body:             |
126  bb.0.entry:
127    liveins: $ecx
128
129    %0 = COPY $ecx
130    MOV32mr %stack.0.x.addr, 1, _, 0, _, %0 :: (store 4 into %ir.x.addr)
131    DBG_VALUE %stack.0.x.addr, 0, !13, !DIExpression(), debug-location !14
132    ADJCALLSTACKDOWN64 32, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !15
133    %1 = LEA64r %stack.0.x.addr, 1, _, 0, _
134    $rcx = COPY %1, debug-location !15
135    CALL64pcrel32 @escape, csr_win64, implicit $rsp, implicit $ssp, implicit $rcx, implicit-def $rsp, implicit-def $ssp, debug-location !15
136    ADJCALLSTACKUP64 32, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !15
137    DBG_VALUE 1, debug-use _, !13, !DIExpression(), debug-location !16
138    MOV32mi $rip, 1, _, @global, _, 1, debug-location !17 :: (store 4 into @global)
139    DBG_VALUE %stack.0.x.addr, 0, !13, !DIExpression(), debug-location !18
140    MOV32mi %stack.0.x.addr, 1, _, 0, _, 2, debug-location !18 :: (store 4 into %ir.x.addr)
141    ADJCALLSTACKDOWN64 32, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !19
142    $rcx = COPY %1, debug-location !19
143    CALL64pcrel32 @escape, csr_win64, implicit $rsp, implicit $ssp, implicit $rcx, implicit-def $rsp, implicit-def $ssp, debug-location !19
144    ADJCALLSTACKUP64 32, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !19
145    RET 0, debug-location !20
146
147...
148