Skip to content

Commit b3c51db

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.
1 parent 366dadd commit b3c51db

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp

+5
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();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 captures(address) %__x, ptr readonly captures(none) %__y) local_unnamed_addr #0 {
13+
%1 = load ptr, ptr %__y, align 8
14+
%cmp = icmp eq ptr %__x, %1
15+
ret i1 %cmp
16+
}
17+
define ptr @_ZNKSt3__111__wrap_iterIPNS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEEE4baseB8nn180100Ev(ptr readonly captures(none) %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 captures(address) %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, 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)>", scope: !6, file: !5, type: !7, unit: !1, 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, flags: DIFlagArtificial)
37+
!10 = distinct !DILexicalBlock(scope: !11, line: 963, column: 5)
38+
!11 = distinct !DILexicalBlock(scope: !12, line: 960, column: 34)
39+
!12 = distinct !DILexicalBlock(scope: !4, line: 960, column: 7)
40+
!25 = !DILocation(line: 0, scope: !10)
41+
name: _ZN4llvm12handleErrorsIJZNS_12consumeErrorENS_5ErrorEEUlRKNS_13ErrorInfoBaseEE_EEES1_S1_DpOT_
42+
body: |
43+
bb.0 (%ir-block.0):
44+
renamable $x8 = LOADgot target-flags(aarch64-got) @_ZNSt3__16vectorINS_10unique_ptrIN4llvm13ErrorInfoBaseENS_14default_deleteIS3_EEEENS_9allocatorIS6_EEE3endB8nn180100Ev, debug-instr-number 1
45+
DBG_INSTR_REF !9, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !25

0 commit comments

Comments
 (0)