Skip to content

Commit a369e49

Browse files
[InstrRef] Preserve debug instr num in aarch64-expand-pseudo LOADgot expansion
The aarch64-expand-pseudo pass expands the LOADgot instruction to an ADRP instruction and a LDRXui instruction. If the LOADgot had a debug-instr-number, the pass doesn't preserve this to the new expansion. This patch fixes the issue by making sure the debug-instr-number is correctly applied to the LDRXui instruction generated.
1 parent 6c54ab5 commit a369e49

File tree

2 files changed

+288
-0
lines changed

2 files changed

+288
-0
lines changed

llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,11 @@ bool AArch64ExpandPseudo::expandMI(MachineBasicBlock &MBB,
13821382
AArch64II::MO_NC);
13831383
}
13841384

1385+
// If the LOADgot instruction has a debug-instr-number, annotate the
1386+
// LDRWui instruction that it is expanded to with the same
1387+
// debug-instr-number to preserve debug information.
1388+
if (MI.peekDebugInstrNum() != 0)
1389+
MIB2->setDebugInstrNum(MI.peekDebugInstrNum());
13851390
transferImpOps(MI, MIB1, MIB2);
13861391
}
13871392
MI.eraseFromParent();
Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
# RUN: llc -run-pass=aarch64-expand-pseudo -mtriple=aarch64-unknown-linux-gnu -o - %s | FileCheck %s
2+
3+
# This testcase was obtained by looking at FileCheck.cpp and reducing it down via llvm-reduce
4+
5+
# Check that the LDRXui preserves the debug info by retaining the debug-instr-number 1 in _ZN4llvm12handleErrorsIJZNS_12consumeErrorENS_5ErrorEEUlRKNS_13ErrorInfoBaseEE_EEES1_S1_DpOT_
6+
# CHECK: $x8 = ADRP target-flags(aarch64-page, aarch64-got) @_ZNSt3__16vectorINS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEENS_9allocatorIS6_EEE3endB8nn180100Ev
7+
# CHECK-NEXT: renamable $x8 = LDRXui killed $x8, target-flags(aarch64-pageoff, aarch64-got, aarch64-nc) @_ZNSt3__16vectorINS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEENS_9allocatorIS6_EEE3endB8nn180100Ev, debug-instr-number 1
8+
# CHECK-NEXT: DBG_INSTR_REF !9, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location
9+
10+
--- |
11+
; ModuleID = '/Users/shubhamrastogi/Development/test105791650/FileCheck-extract-reduced.ll'
12+
source_filename = "/Users/shubhamrastogi/Development/test105791650/FileCheck-extract-reduced.ll"
13+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128-Fn32"
14+
target triple = "arm64-apple-macosx15.0.0"
15+
16+
declare i64 @_ZNSt3__16vectorINS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEENS_9allocatorIS6_EEE3endB8nn180100Ev()
17+
18+
; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
19+
define i1 @_ZNSt3__1neB8nn180100IPNS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEEEEbRKNS_11__wrap_iterIT_EESC_(ptr readnone captures(address) %__x, ptr readonly captures(none) %__y) local_unnamed_addr #0 {
20+
%1 = load ptr, ptr %__y, align 8
21+
%cmp = icmp eq ptr %__x, %1
22+
ret i1 %cmp
23+
}
24+
25+
; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
26+
define ptr @_ZNKSt3__111__wrap_iterIPNS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEEE4baseB8nn180100Ev(ptr readonly captures(none) %this) local_unnamed_addr #0 {
27+
entry:
28+
%0 = load ptr, ptr %this, align 8
29+
ret ptr %0
30+
}
31+
32+
; Function Attrs: mustprogress nofree norecurse nounwind willreturn
33+
define void @_ZN4llvm12handleErrorsIJZNS_12consumeErrorENS_5ErrorEEUlRKNS_13ErrorInfoBaseEE_EEES1_S1_DpOT_(ptr readnone captures(address) %call6) local_unnamed_addr #1 !dbg !4 {
34+
%call8 = load volatile i64, ptr null, align 4294967296, !dbg !24
35+
#dbg_value(ptr @_ZNSt3__16vectorINS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEENS_9allocatorIS6_EEE3endB8nn180100Ev, !9, !DIExpression(), !25)
36+
%cmp.i = icmp eq ptr %call6, @_ZNSt3__16vectorINS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEENS_9allocatorIS6_EEE3endB8nn180100Ev
37+
br i1 %cmp.i, label %for.body, label %common.ret
38+
39+
common.ret: ; preds = %0
40+
ret void
41+
42+
for.body: ; preds = %0
43+
tail call void @llvm.lifetime.start.p0(i64 0, ptr null)
44+
ret void
45+
}
46+
47+
; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
48+
declare void @llvm.lifetime.start.p0(i64 immarg, ptr captures(none)) #2
49+
50+
attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) }
51+
attributes #1 = { mustprogress nofree norecurse nounwind willreturn }
52+
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
53+
54+
!llvm.module.flags = !{!0}
55+
!llvm.dbg.cu = !{!1}
56+
57+
!0 = !{i32 2, !"Debug Info Version", i32 3}
58+
!1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !2, producer: "clang version 21.0.0git (\0A\0A\0A\[email protected]:llvm/llvm-project.git 6deee0d5b36c8b4b83209759df8d4933e4922bc8\0A\0A\0A\0A)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, retainedTypes: !3, globals: !3, imports: !3, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/Library/Developer/CommandLineTools/SDKs/MacOSX15.3.sdk", sdk: "MacOSX15.3.sdk")
59+
!2 = !DIFile(filename: "/Users/shubhamrastogi/Development/llvm-project-instr-ref/llvm-project/llvm/lib/FileCheck/FileCheck.cpp", directory: "/Users/shubhamrastogi/Development/llvm-project-instr-ref/llvm-project/build-instr-ref-stage2", checksumkind: CSK_MD5, checksum: "e718c2a5b2d3baab240a5e370113901e")
60+
!3 = !{}
61+
!4 = distinct !DISubprogram(name: "handleErrors<(\0A\0A\0A\0Alambda at /Users/shubhamrastogi/Development/llvm-project-instr-ref/llvm-project/llvm/include/llvm/Support/Error.h:1070:35\0A\0A\0A\0A)>", linkageName: "_ZN4llvm12handleErrorsIJZNS_12consumeErrorENS_5ErrorEEUlRKNS_13ErrorInfoBaseEE_EEES1_S1_DpOT_", scope: !6, file: !5, line: 954, type: !7, scopeLine: 954, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !1, templateParams: !3, retainedNodes: !8)
62+
!5 = !DIFile(filename: "llvm/include/llvm/Support/Error.h", directory: "/Users/shubhamrastogi/Development/llvm-project-instr-ref/llvm-project", checksumkind: CSK_MD5, checksum: "0a75676311531ba2140b3f0d994b3c33")
63+
!6 = !DINamespace(name: "llvm", scope: null)
64+
!7 = distinct !DISubroutineType(types: !3)
65+
!8 = !{!9}
66+
!9 = !DILocalVariable(name: "__end3", scope: !10, type: !13, flags: DIFlagArtificial)
67+
!10 = distinct !DILexicalBlock(scope: !11, file: !5, line: 963, column: 5)
68+
!11 = distinct !DILexicalBlock(scope: !12, file: !5, line: 960, column: 34)
69+
!12 = distinct !DILexicalBlock(scope: !4, file: !5, line: 960, column: 7)
70+
!13 = !DIDerivedType(tag: DW_TAG_typedef, name: "iterator", scope: !15, file: !14, line: 403, baseType: !18, flags: DIFlagPublic)
71+
!14 = !DIFile(filename: "/Library/Developer/CommandLineTools/SDKs/MacOSX15.3.sdk/usr/include/c++/v1/vector", directory: "")
72+
!15 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "vector<std::__1::unique_ptr<llvm::ErrorInfoBase,\0A\0A\0A\0Astd::__1::default_delete<llvm::ErrorInfoBase> >,\0A\0A\0A\0Astd::__1::allocator<std::__1::unique_ptr<llvm::ErrorInfoBase,\0A\0A\0A\0Astd::__1::default_delete<llvm::ErrorInfoBase> > > >", scope: !16, file: !14, line: 387, size: 192, flags: DIFlagTypePassByReference | DIFlagNonTrivial, elements: !3, templateParams: !3, identifier: "_ZTSNSt3__16vectorINS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEENS_9allocatorIS6_EEEE")
73+
!16 = !DINamespace(name: "__1", scope: !17, exportSymbols: true)
74+
!17 = !DINamespace(name: "std", scope: null)
75+
!18 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "__wrap_iter<std::__1::unique_ptr<llvm::ErrorInfoBase,\0A\0A\0A\0Astd::__1::default_delete<llvm::ErrorInfoBase> > *>", scope: !16, file: !19, line: 41, baseType: !20, size: 64)
76+
!19 = !DIFile(filename: "/Library/Developer/CommandLineTools/SDKs/MacOSX15.3.sdk/usr/include/c++/v1/__iterator/wrap_iter.h", directory: "")
77+
!20 = !DIDerivedType(tag: DW_TAG_typedef, name: "iterator_type", scope: !18, file: !19, line: 30, baseType: !21, flags: DIFlagPublic)
78+
!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !22, size: 64)
79+
!22 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "unique_ptr<llvm::ErrorInfoBase,\0A\0A\0A\0Astd::__1::default_delete<llvm::ErrorInfoBase> >", scope: !16, file: !23, line: 124, size: 64, flags: DIFlagTypePassByReference | DIFlagNonTrivial, elements: !3, templateParams: !3, identifier: "_ZTSNSt3__110unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS2_EEEE")
80+
!23 = !DIFile(filename: "/Library/Developer/CommandLineTools/SDKs/MacOSX15.3.sdk/usr/include/c++/v1/__memory/unique_ptr.h", directory: "")
81+
!24 = !DILocation(line: 963, column: 18, scope: !10)
82+
!25 = !DILocation(line: 0, scope: !10)
83+
84+
...
85+
---
86+
name: _ZNSt3__1neB8nn180100IPNS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEEEEbRKNS_11__wrap_iterIT_EESC_
87+
alignment: 4
88+
exposesReturnsTwice: false
89+
legalized: false
90+
regBankSelected: false
91+
selected: false
92+
failedISel: false
93+
tracksRegLiveness: true
94+
hasWinCFI: false
95+
noPhis: true
96+
isSSA: false
97+
noVRegs: true
98+
hasFakeUses: false
99+
callsEHReturn: false
100+
callsUnwindInit: false
101+
hasEHCatchret: false
102+
hasEHScopes: false
103+
hasEHFunclets: false
104+
isOutlined: false
105+
debugInstrRef: true
106+
failsVerification: false
107+
tracksDebugUserValues: true
108+
registers: []
109+
liveins:
110+
- { reg: '$x0', virtual-reg: '' }
111+
- { reg: '$x1', virtual-reg: '' }
112+
frameInfo:
113+
isFrameAddressTaken: false
114+
isReturnAddressTaken: false
115+
hasStackMap: false
116+
hasPatchPoint: false
117+
stackSize: 0
118+
offsetAdjustment: 0
119+
maxAlignment: 1
120+
adjustsStack: false
121+
hasCalls: false
122+
stackProtector: ''
123+
functionContext: ''
124+
maxCallFrameSize: 0
125+
cvBytesOfCalleeSavedRegisters: 0
126+
hasOpaqueSPAdjustment: false
127+
hasVAStart: false
128+
hasMustTailInVarArgFunc: false
129+
hasTailCall: false
130+
isCalleeSavedInfoValid: true
131+
localFrameSize: 0
132+
savePoint: ''
133+
restorePoint: ''
134+
fixedStack: []
135+
stack: []
136+
entry_values: []
137+
callSites: []
138+
debugValueSubstitutions: []
139+
constants: []
140+
machineFunctionInfo:
141+
hasRedZone: false
142+
body: |
143+
bb.0 (%ir-block.0):
144+
liveins: $x0, $x1
145+
146+
renamable $x8 = LDRXui killed renamable $x1, 0 :: (load (s64) from %ir.__y)
147+
dead $xzr = SUBSXrr killed renamable $x0, killed renamable $x8, implicit-def $nzcv
148+
renamable $w0 = CSINCWr $wzr, $wzr, 1, implicit killed $nzcv
149+
RET_ReallyLR implicit $w0
150+
151+
...
152+
---
153+
name: _ZNKSt3__111__wrap_iterIPNS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEEE4baseB8nn180100Ev
154+
alignment: 4
155+
exposesReturnsTwice: false
156+
legalized: false
157+
regBankSelected: false
158+
selected: false
159+
failedISel: false
160+
tracksRegLiveness: true
161+
hasWinCFI: false
162+
noPhis: true
163+
isSSA: false
164+
noVRegs: true
165+
hasFakeUses: false
166+
callsEHReturn: false
167+
callsUnwindInit: false
168+
hasEHCatchret: false
169+
hasEHScopes: false
170+
hasEHFunclets: false
171+
isOutlined: false
172+
debugInstrRef: true
173+
failsVerification: false
174+
tracksDebugUserValues: true
175+
registers: []
176+
liveins:
177+
- { reg: '$x0', virtual-reg: '' }
178+
frameInfo:
179+
isFrameAddressTaken: false
180+
isReturnAddressTaken: false
181+
hasStackMap: false
182+
hasPatchPoint: false
183+
stackSize: 0
184+
offsetAdjustment: 0
185+
maxAlignment: 1
186+
adjustsStack: false
187+
hasCalls: false
188+
stackProtector: ''
189+
functionContext: ''
190+
maxCallFrameSize: 0
191+
cvBytesOfCalleeSavedRegisters: 0
192+
hasOpaqueSPAdjustment: false
193+
hasVAStart: false
194+
hasMustTailInVarArgFunc: false
195+
hasTailCall: false
196+
isCalleeSavedInfoValid: true
197+
localFrameSize: 0
198+
savePoint: ''
199+
restorePoint: ''
200+
fixedStack: []
201+
stack: []
202+
entry_values: []
203+
callSites: []
204+
debugValueSubstitutions: []
205+
constants: []
206+
machineFunctionInfo:
207+
hasRedZone: false
208+
body: |
209+
bb.0.entry:
210+
liveins: $x0
211+
212+
renamable $x0 = LDRXui killed renamable $x0, 0 :: (load (s64) from %ir.this)
213+
RET_ReallyLR implicit $x0
214+
215+
...
216+
---
217+
name: _ZN4llvm12handleErrorsIJZNS_12consumeErrorENS_5ErrorEEUlRKNS_13ErrorInfoBaseEE_EEES1_S1_DpOT_
218+
alignment: 4
219+
exposesReturnsTwice: false
220+
legalized: false
221+
regBankSelected: false
222+
selected: false
223+
failedISel: false
224+
tracksRegLiveness: true
225+
hasWinCFI: false
226+
noPhis: true
227+
isSSA: false
228+
noVRegs: true
229+
hasFakeUses: false
230+
callsEHReturn: false
231+
callsUnwindInit: false
232+
hasEHCatchret: false
233+
hasEHScopes: false
234+
hasEHFunclets: false
235+
isOutlined: false
236+
debugInstrRef: true
237+
failsVerification: false
238+
tracksDebugUserValues: true
239+
registers: []
240+
liveins:
241+
- { reg: '$x0', virtual-reg: '' }
242+
frameInfo:
243+
isFrameAddressTaken: false
244+
isReturnAddressTaken: false
245+
hasStackMap: false
246+
hasPatchPoint: false
247+
stackSize: 0
248+
offsetAdjustment: 0
249+
maxAlignment: 1
250+
adjustsStack: false
251+
hasCalls: false
252+
stackProtector: ''
253+
functionContext: ''
254+
maxCallFrameSize: 0
255+
cvBytesOfCalleeSavedRegisters: 0
256+
hasOpaqueSPAdjustment: false
257+
hasVAStart: false
258+
hasMustTailInVarArgFunc: false
259+
hasTailCall: false
260+
isCalleeSavedInfoValid: true
261+
localFrameSize: 0
262+
savePoint: ''
263+
restorePoint: ''
264+
fixedStack: []
265+
stack: []
266+
entry_values: []
267+
callSites: []
268+
debugValueSubstitutions: []
269+
constants: []
270+
machineFunctionInfo:
271+
hasRedZone: false
272+
body: |
273+
bb.0 (%ir-block.0):
274+
liveins: $x0
275+
276+
$x8 = MOVZXi 0, 0
277+
dead $xzr = LDRXui killed renamable $x8, 0, debug-location !24 :: (volatile load (s64) from `ptr null`, align 4294967296)
278+
renamable $x8 = LOADgot target-flags(aarch64-got) @_ZNSt3__16vectorINS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEENS_9allocatorIS6_EEE3endB8nn180100Ev, debug-instr-number 1
279+
DBG_INSTR_REF !9, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !25
280+
dead $xzr = SUBSXrr killed renamable $x0, killed renamable $x8, implicit-def $nzcv
281+
RET_ReallyLR
282+
283+
...

0 commit comments

Comments
 (0)