Skip to content

Commit e01a6c6

Browse files
[InstrRef] Preserve debug instr num in aarch64-expand-pseudo LOADgot expansion (llvm#128081)
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. (cherry picked from commit b3c51db)
1 parent cdf2a52 commit e01a6c6

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,11 @@ bool AArch64ExpandPseudo::expandMI(MachineBasicBlock &MBB,
13541354
AArch64II::MO_NC);
13551355
}
13561356

1357+
// If the LOADgot instruction has a debug-instr-number, annotate the
1358+
// LDRWui instruction that it is expanded to with the same
1359+
// debug-instr-number to preserve debug information.
1360+
if (MI.peekDebugInstrNum() != 0)
1361+
MIB2->setDebugInstrNum(MI.peekDebugInstrNum());
13571362
transferImpOps(MI, MIB1, MIB2);
13581363
}
13591364
MI.eraseFromParent();
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
declare i64 @_ZNSt3__16vectorINS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEENS_9allocatorIS6_EEE3endB8nn180100Ev()
12+
define i1 @_ZNSt3__1neB8nn180100IPNS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEEEEbRKNS_11__wrap_iterIT_EESC_(ptr readnone %__x, ptr nocapture readonly %__y) local_unnamed_addr #0 {
13+
%1 = load ptr, ptr %__y, align 8
14+
%cmp = icmp eq ptr %1, %__x
15+
ret i1 %cmp
16+
}
17+
define ptr @_ZNKSt3__111__wrap_iterIPNS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEEE4baseB8nn180100Ev(ptr nocapture readonly %this) local_unnamed_addr #0 {
18+
entry:
19+
%0 = load ptr, ptr %this, align 8
20+
ret ptr %0
21+
}
22+
define void @_ZN4llvm12handleErrorsIJZNS_12consumeErrorENS_5ErrorEEUlRKNS_13ErrorInfoBaseEE_EEES1_S1_DpOT_(ptr readnone %call6) local_unnamed_addr #1 !dbg !4 {
23+
ret void
24+
}
25+
!llvm.module.flags = !{!0}
26+
!llvm.dbg.cu = !{!1}
27+
!0 = !{i32 2, !"Debug Info Version", i32 3}
28+
!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")
29+
!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")
30+
!3 = !{}
31+
!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)
32+
!5 = !DIFile(filename: "llvm/include/llvm/Support/Error.h", directory: "/Users/shubhamrastogi/Development/llvm-project-instr-ref/llvm-project", checksumkind: CSK_MD5, checksum: "0a75676311531ba2140b3f0d994b3c33")
33+
!6 = !DINamespace(name: "llvm", scope: null)
34+
!7 = distinct !DISubroutineType(types: !3)
35+
!8 = !{!9}
36+
!9 = !DILocalVariable(name: "__end3", scope: !10, type: !13, flags: DIFlagArtificial)
37+
!10 = distinct !DILexicalBlock(scope: !11, file: !5, line: 963, column: 5)
38+
!11 = distinct !DILexicalBlock(scope: !12, file: !5, line: 960, column: 34)
39+
!12 = distinct !DILexicalBlock(scope: !4, file: !5, line: 960, column: 7)
40+
!13 = !DIDerivedType(tag: DW_TAG_typedef, name: "iterator", scope: !15, file: !14, line: 403, baseType: !18, flags: DIFlagPublic)
41+
!14 = !DIFile(filename: "/Library/Developer/CommandLineTools/SDKs/MacOSX15.3.sdk/usr/include/c++/v1/vector", directory: "")
42+
!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")
43+
!16 = !DINamespace(name: "__1", scope: !17, exportSymbols: true)
44+
!17 = !DINamespace(name: "std", scope: null)
45+
!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)
46+
!19 = !DIFile(filename: "/Library/Developer/CommandLineTools/SDKs/MacOSX15.3.sdk/usr/include/c++/v1/__iterator/wrap_iter.h", directory: "")
47+
!20 = !DIDerivedType(tag: DW_TAG_typedef, name: "iterator_type", scope: !18, file: !19, line: 30, baseType: !21, flags: DIFlagPublic)
48+
!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !22, size: 64)
49+
!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")
50+
!23 = !DIFile(filename: "/Library/Developer/CommandLineTools/SDKs/MacOSX15.3.sdk/usr/include/c++/v1/__memory/unique_ptr.h", directory: "")
51+
!25 = !DILocation(line: 0, scope: !10)
52+
name: _ZNSt3__1neB8nn180100IPNS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEEEEbRKNS_11__wrap_iterIT_EESC_
53+
body: |
54+
bb.0 (%ir-block.0):
55+
renamable $x8 = LOADgot target-flags(aarch64-got) @_ZNSt3__16vectorINS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEENS_9allocatorIS6_EEE3endB8nn180100Ev, debug-instr-number 1
56+
DBG_INSTR_REF !9, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !25

0 commit comments

Comments
 (0)