Skip to content

Commit 0a68bbb

Browse files
[InstrRef] Preserve debug instr num in aarch64-cond-br-tuning.
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 6be6400 commit 0a68bbb

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

llvm/lib/Target/AArch64/AArch64CondBrTuning.cpp

Lines changed: 6 additions & 0 deletions
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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
; RUN: rm -rf %t && mkdir -p %t
2+
; RUN: llc -O2 -mtriple=aarch64-unknown-linux-gnu --filetype=obj -experimental-debug-variable-locations -o %t/file.o %s
3+
; RUN: llvm-dwarfdump %t/file.o -name=_ZN4llvmlsERNS_11raw_ostreamERKNS_5ErrorE -c | FileCheck %s
4+
5+
; CHECK: DW_TAG_variable
6+
; CHECK-NEXT: DW_AT_location (0x{{[0-9a-f]+}}:
7+
; CHECK-NEXT: [0x{{[0-9a-f]+}}, 0x{{[0-9a-f]+}}): DW_OP_reg{{[0-9]+}} W{{[0-9]+}})
8+
; CHECK-NEXT: DW_AT_name ("P")
9+
10+
; RUN: llc -O2 -mtriple=aarch64-unknown-linux-gnu --filetype=obj -experimental-debug-variable-locations -stop-after=aarch64-isel -o - %s | FileCheck %s --check-prefix=INSTR-REF
11+
12+
; INSTR-REF: ![[DBG:[0-9]+]] = !DILocalVariable(name: "P"
13+
; INSTR-REF: DBG_INSTR_REF ![[DBG]]
14+
15+
; This testcase was obtained by looking at FileCheck.cpp and reducing it down via llvm-reduce
16+
17+
18+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128-Fn32"
19+
target triple = "arm64-apple-macosx15.0.0"
20+
21+
define ptr @_ZNK4llvm5Error6getPtrEv(ptr %this) {
22+
entry:
23+
%0 = ptrtoint ptr %this to i64
24+
%and = and i64 %0, -2
25+
%1 = inttoptr i64 %and to ptr
26+
ret ptr %1
27+
}
28+
29+
define ptr @_ZN4llvmlsERNS_11raw_ostreamERKNS_5ErrorE(ptr %E) !dbg !4 {
30+
entry:
31+
%call = call ptr @_ZNK4llvm5Error6getPtrEv(ptr %E), !dbg !13
32+
#dbg_value(ptr %call, !9, !DIExpression(), !14)
33+
%tobool.not = icmp eq ptr %call, null
34+
br i1 %tobool.not, label %if.else, label %if.then
35+
36+
if.then: ; preds = %entry
37+
store volatile ptr null, ptr %call, align 8
38+
unreachable
39+
40+
if.else: ; preds = %entry
41+
ret ptr null
42+
}
43+
44+
!llvm.module.flags = !{!0}
45+
!llvm.dbg.cu = !{!1}
46+
47+
!0 = !{i32 2, !"Debug Info Version", i32 3}
48+
!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 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")
49+
!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")
50+
!3 = !{}
51+
!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)
52+
!5 = !DIFile(filename: "llvm/include/llvm/Support/Error.h", directory: "/Users/shubhamrastogi/Development/llvm-project-instr-ref/llvm-project", checksumkind: CSK_MD5, checksum: "f166cdaeb719f8f71fbae8128cde93e4")
53+
!6 = !DINamespace(name: "llvm", scope: null)
54+
!7 = distinct !DISubroutineType(types: !3)
55+
!8 = !{!9}
56+
!9 = !DILocalVariable(name: "P", scope: !10, file: !5, line: 321, type: !11)
57+
!10 = distinct !DILexicalBlock(scope: !4, file: !5, line: 321, column: 15)
58+
!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
59+
!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")
60+
!13 = !DILocation(line: 321, column: 21, scope: !10)
61+
!14 = !DILocation(line: 0, scope: !10)

0 commit comments

Comments
 (0)