1 # RUN: llc %s -run-pass=machine-sink --aarch64-enable-sink-fold=true -o - | FileCheck %s
3 target triple = "aarch64-linux"
5 @.str = private unnamed_addr constant [12 x i8] c"result: %d\0A\00", align 1, !dbg !0
7 define i32 @foo(i32 %x, i32 %y) !dbg !18 {
9 %add = add i32 %x, 3, !dbg !25
10 %add1 = add i32 %add, %y, !dbg !26
11 ret i32 %add1, !dbg !27
14 define i32 @baz(i32 %y) !dbg !28 {
16 %add1.i = add i32 %y, 23, !dbg !34
17 tail call void @bar(ptr nonnull @.str, i32 %add1.i), !dbg !36
21 declare !dbg !38 void @bar(ptr noundef, i32 noundef)
24 !llvm.module.flags = !{!9, !10, !11, !12, !13, !14, !15, !16}
27 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
28 !1 = distinct !DIGlobalVariable(scope: null, file: !2, line: 9, type: !3, isLocal: true, isDefinition: true)
29 !2 = !DIFile(filename: "m.c", directory: "/home/chill")
30 !3 = !DICompositeType(tag: DW_TAG_array_type, baseType: !4, size: 96, elements: !5)
31 !4 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_unsigned_char)
33 !6 = !DISubrange(count: 12)
34 !7 = distinct !DICompileUnit(language: DW_LANG_C11, file: !2, producer: "clang version 18.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !8, splitDebugInlining: false, nameTableKind: None)
36 !9 = !{i32 7, !"Dwarf Version", i32 5}
37 !10 = !{i32 2, !"Debug Info Version", i32 3}
38 !11 = !{i32 1, !"wchar_size", i32 4}
39 !12 = !{i32 8, !"PIC Level", i32 2}
40 !13 = !{i32 7, !"PIE Level", i32 2}
41 !14 = !{i32 7, !"uwtable", i32 2}
42 !15 = !{i32 7, !"frame-pointer", i32 1}
43 !16 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
44 !17 = !{!"clang version 18.0.0"}
45 !18 = distinct !DISubprogram(name: "foo", scope: !2, file: !2, line: 1, type: !19, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !7, retainedNodes: !22)
46 !19 = !DISubroutineType(types: !20)
47 !20 = !{!21, !21, !21}
48 !21 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
50 !23 = !DILocalVariable(name: "x", arg: 1, scope: !18, file: !2, line: 1, type: !21)
51 !24 = !DILocalVariable(name: "y", arg: 2, scope: !18, file: !2, line: 1, type: !21)
52 !25 = !DILocation(line: 2, column: 12, scope: !18)
53 !26 = !DILocation(line: 2, column: 16, scope: !18)
54 !27 = !DILocation(line: 2, column: 3, scope: !18)
55 !28 = distinct !DISubprogram(name: "baz", scope: !2, file: !2, line: 7, type: !29, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !7, retainedNodes: !31)
56 !29 = !DISubroutineType(types: !30)
59 !32 = !DILocalVariable(name: "y", arg: 1, scope: !28, file: !2, line: 7, type: !21)
60 !33 = !DILocalVariable(name: "result", scope: !28, file: !2, line: 8, type: !21)
61 !34 = !DILocation(line: 2, column: 16, scope: !18, inlinedAt: !35)
62 !35 = distinct !DILocation(line: 8, column: 16, scope: !28)
63 !36 = !DILocation(line: 9, column: 3, scope: !28)
64 !37 = !DILocation(line: 10, column: 3, scope: !28)
65 !38 = !DISubprogram(name: "bar", scope: !2, file: !2, line: 5, type: !39, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
66 !39 = !DISubroutineType(types: !40)
67 !40 = !{null, !41, !21}
68 !41 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !42, size: 64)
69 !42 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !4)
75 exposesReturnsTwice: false
77 regBankSelected: false
80 tracksRegLiveness: true
83 callsUnwindInit: false
89 failsVerification: false
90 tracksDebugUserValues: false
92 - { id: 0, class: gpr32, preferred-register: '' }
93 - { id: 1, class: gpr32, preferred-register: '' }
94 - { id: 2, class: gpr32common, preferred-register: '' }
95 - { id: 3, class: gpr32sp, preferred-register: '' }
97 - { reg: '$w0', virtual-reg: '%0' }
98 - { reg: '$w1', virtual-reg: '%1' }
100 isFrameAddressTaken: false
101 isReturnAddressTaken: false
112 cvBytesOfCalleeSavedRegisters: 0
113 hasOpaqueSPAdjustment: false
115 hasMustTailInVarArgFunc: false
124 debugValueSubstitutions: []
126 machineFunctionInfo: {}
131 ; CHECK-LABEL: name: foo
133 ; Check the source location of the ADDWri was reused (usually the
134 ; copy to $w0 carries the same debug location as the return)
136 ; CHECK: $w0 = ADDWri {{.*}}, 3, 0, debug-location !26
137 ; CHECK-NEXT: RET_ReallyLR implicit $w0, debug-location !27
140 %2:gpr32common = ADDWrr %0, %1, debug-location !25
141 $w0 = ADDWri %2, 3, 0, debug-location !26
142 RET_ReallyLR implicit $w0, debug-location !27
148 exposesReturnsTwice: false
150 regBankSelected: false
153 tracksRegLiveness: true
156 callsUnwindInit: false
162 failsVerification: false
163 tracksDebugUserValues: false
165 - { id: 0, class: gpr32common, preferred-register: '' }
166 - { id: 1, class: gpr32sp, preferred-register: '' }
167 - { id: 2, class: gpr64common, preferred-register: '' }
168 - { id: 3, class: gpr32all, preferred-register: '' }
170 - { reg: '$w0', virtual-reg: '%0' }
172 isFrameAddressTaken: false
173 isReturnAddressTaken: false
184 cvBytesOfCalleeSavedRegisters: 0
185 hasOpaqueSPAdjustment: false
187 hasMustTailInVarArgFunc: false
196 debugValueSubstitutions: []
198 machineFunctionInfo: {}
203 ; CHECK-LABEL: name: baz
205 ; Check the source location of the ADDWri was reused (usually the
206 ; copy to $w1 carries the same debug location as the BL)
208 ; CHECK: $x0 = COPY {{.*}}, debug-location !36
209 ; CHECK-NEXT: $w1 = ADDWri {{.*}}, 23, 0, debug-location !34
210 ; CHECK-NEXT: BL @bar, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $x0, implicit $w1, implicit-def $sp, debug-location !36
212 %0:gpr32common = COPY $w0
213 ADJCALLSTACKDOWN 0, 0, implicit-def dead $sp, implicit $sp, debug-location !36
214 %2:gpr64common = MOVaddr target-flags(aarch64-page) @.str, target-flags(aarch64-pageoff, aarch64-nc) @.str, debug-location !36
215 $x0 = COPY %2, debug-location !36
216 $w1 = ADDWri %0, 23, 0, debug-location !34
217 BL @bar, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $x0, implicit $w1, implicit-def $sp, debug-location !36
218 ADJCALLSTACKUP 0, 0, implicit-def dead $sp, implicit $sp, debug-location !36
219 %3:gpr32all = COPY $wzr
220 $w0 = COPY %3, debug-location !37
221 RET_ReallyLR implicit $w0, debug-location !37