Skip to content

Commit f5f6af8

Browse files
[InstrRef] Preserve debug instr num in aarch64-cond-br-tuning. (llvm#132081)
The aarch64-cond-br-tuning pass transforms a CBZX instruction into a conditional branch (B.cond). One of the by products of the transformation is that the source instruction of the CBZX, which is an ANDXri instruction, gets transformed into a ANDSXri instruction, however this transformation doesn't preserve it's debug instruction number. This patch fixes that issue.
1 parent 75c6fd3 commit f5f6af8

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

llvm/lib/Target/AArch64/AArch64CondBrTuning.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ MachineInstr *AArch64CondBrTuning::convertToFlagSetting(MachineInstr &MI,
102102

103103
MachineInstrBuilder MIB = BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
104104
TII->get(NewOpc), NewDestReg);
105+
106+
// If the MI has a debug instruction number, preserve that in the new Machine
107+
// Instruction that is created.
108+
if (MI.peekDebugInstrNum() != 0)
109+
MIB->setDebugInstrNum(MI.peekDebugInstrNum());
110+
105111
for (const MachineOperand &MO : llvm::drop_begin(MI.operands()))
106112
MIB.add(MO);
107113

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# RUN: llc -mtriple=aarch64-unknown-linux-gnu -o - %s -run-pass=aarch64-cond-br-tuning | 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 ANDXri preserves the debug info by retaining the debug-instr-number 1 in _ZN4llvmlsERNS_11raw_ostreamERKNS_5ErrorE after the aarch64-cond-br-tuning pass transforms it into a ANDSXri instruction.
6+
7+
# CHECK: %{{[0-9]+}}:gpr64common = ANDSXri %{{[0-9]+}}, {{[0-9]+}}, implicit-def $nzcv, debug-instr-number 1
8+
# CHECK-NEXT: DBG_INSTR_REF !{{[0-9]+}}, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0)
9+
10+
--- |
11+
define ptr @_ZNK4llvm5Error6getPtrEv(ptr %this) local_unnamed_addr #0 {
12+
entry:
13+
%0 = ptrtoint ptr %this to i64
14+
%and = and i64 %0, -2
15+
%1 = inttoptr i64 %and to ptr
16+
ret ptr %1
17+
}
18+
define noalias noundef ptr @_ZN4llvmlsERNS_11raw_ostreamERKNS_5ErrorE(ptr %E) local_unnamed_addr #1 !dbg !4 {
19+
entry:
20+
%0 = ptrtoint ptr %E to i64, !dbg !13
21+
%and.i = and i64 %0, -2, !dbg !13
22+
%tobool.not = icmp eq i64 %and.i, 0
23+
br i1 %tobool.not, label %if.else, label %if.then
24+
if.then: ; preds = %entry
25+
unreachable
26+
if.else: ; preds = %entry
27+
ret ptr null
28+
}
29+
!llvm.module.flags = !{!0}
30+
!llvm.dbg.cu = !{!1}
31+
!0 = !{i32 2, !"Debug Info Version", i32 3}
32+
!1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !2, producer: "clang version 21.0.0git (\0A\0A\[email protected]:llvm/llvm-project.git 6be6400848eeec027d0cca0662c105683bcc896b\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")
33+
!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: "ac1d2352ab68b965fe7993c780cf92d7")
34+
!3 = !{}
35+
!4 = distinct !DISubprogram(name: "operator<<", linkageName: "_ZN4llvmlsERNS_11raw_ostreamERKNS_5ErrorE", scope: !6, file: !5, line: 320, type: !7, scopeLine: 320, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !1, retainedNodes: !8)
36+
!5 = !DIFile(filename: "llvm/include/llvm/Support/Error.h", directory: "/Users/shubhamrastogi/Development/llvm-project-instr-ref/llvm-project", checksumkind: CSK_MD5, checksum: "f166cdaeb719f8f71fbae8128cde93e4")
37+
!6 = !DINamespace(name: "llvm", scope: null)
38+
!7 = distinct !DISubroutineType(types: !3)
39+
!8 = !{!9}
40+
!9 = !DILocalVariable(name: "P", scope: !10, file: !5, line: 321, type: !11)
41+
!10 = distinct !DILexicalBlock(scope: !4, file: !5, line: 321, column: 15)
42+
!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
43+
!12 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "ErrorInfoBase", scope: !6, file: !5, line: 44, size: 64, flags: DIFlagTypePassByReference | DIFlagNonTrivial, elements: !3, vtableHolder: !12, identifier: "_ZTSN4llvm13ErrorInfoBaseE")
44+
!13 = !DILocation(line: 321, column: 21, scope: !10)
45+
!14 = !DILocation(line: 0, scope: !10)
46+
name: _ZN4llvmlsERNS_11raw_ostreamERKNS_5ErrorE
47+
body: |
48+
bb.0.entry:
49+
%1:gpr64 = COPY $x0
50+
%2:gpr64common = ANDXri %1, 8190, debug-instr-number 1, debug-location !13
51+
DBG_INSTR_REF !9, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !14
52+
%0:gpr64sp = COPY %2, debug-location !13
53+
CBZX %2, %bb.2
54+
bb.2.if.else:

0 commit comments

Comments
 (0)