[PATCH] D142974: [AArch64] Avoid using JumpTableEntryInfo when lowering jump tables when it is not initialized
Sinan Lin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 31 04:41:34 PST 2023
sinan created this revision.
sinan added reviewers: t.p.northover, efriedma.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
sinan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
JumpTableEntryInfo is initialized during the instruction selection phase via AArch64FunctionInfo::setJumpTableEntryInfo. However, if we try to run a mir file containing jump tables with llc, then it will crash since no elements in JumpTableEntryInfo. With this patch, we don't need to look up JumpTableEntryInfo for element size and a local label will be created if JumpTableEntryInfo is not initialized.
e.g.
asm.ll (https://reviews.llvm.org/F26307823)
llc -mtriple=aarch64 -stop-after=unpack-mi-bundles asm.ll -o asm.mir
llc -mtriple=aarch64 -start-after=unpack-mi-bundles asm.mir -o asm.s
llc: /root/sinan/llvm-project/llvm/include/llvm/ADT/SmallVector.h:298: const T& llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::operator[](llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type) const [with T = std::pair<unsigned int, llvm::MCSymbol*>; <template-parameter-1-2> = void; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::const_reference = const std::pair<unsigned int, llvm::MCSymbol*>&; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type = long unsigned int]: Assertion `idx < size()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: ./../../../../llvm-dev-install/bin/llc -mtriple=aarch64 -start-after=unpack-mi-bundles asm.mir -o asm.s
1. Running pass 'Function Pass Manager' on module 'asm.mir'.
2. Running pass 'AArch64 Assembly Printer' on function '@sum'
#0 0x00000000019fecfc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./../../../../llvm-dev-install/bin/llc+0x19fecfc)
#1 0x00000000019fd420 llvm::sys::RunSignalHandlers() (./../../../../llvm-dev-install/bin/llc+0x19fd420)
#2 0x00000000019fd5e4 SignalHandler(int) Signals.cpp:0:0
#3 0x0000ffff84f377b0 (linux-vdso.so.1+0x7b0)
#4 0x0000ffff849e9e98 raise (/lib64/libc.so.6+0x37e98)
#5 0x0000ffff849d650c abort (/lib64/libc.so.6+0x2450c)
#6 0x0000ffff849e31e8 __assert_fail_base (/lib64/libc.so.6+0x311e8)
#7 0x0000ffff849e324c .annobin___GI___assert_fail.end assert.c:0:0
This change has no impact on the normal routine and enables writing mir test with a jump table.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D142974
Files:
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
llvm/test/CodeGen/AArch64/arm64-jumptable.ll
Index: llvm/test/CodeGen/AArch64/arm64-jumptable.ll
===================================================================
--- llvm/test/CodeGen/AArch64/arm64-jumptable.ll
+++ llvm/test/CodeGen/AArch64/arm64-jumptable.ll
@@ -2,6 +2,9 @@
; RUN: llc -mtriple=arm64-linux-gnu < %s | FileCheck %s --check-prefix=CHECK-LINUX
; <rdar://11417675>
+; RUN: llc -mtriple=aarch64 -stop-after=unpack-mi-bundles -o %t.mir %s
+; RUN: llc %t.mir -mtriple=aarch64 -start-after=unpack-mi-bundles -o - | FileCheck %s --check-prefix=CHECK-MIR
+
define void @sum(i32 %a, ptr %to, i32 %c) {
entry:
switch i32 %a, label %exit [
@@ -32,3 +35,9 @@
; CHECK-LINUX-LABEL: sum:
; CHECK-LINUX: adrp {{x[0-9]+}}, .LJTI0_0
; CHECK-LINUX: add {{x[0-9]+}}, {{x[0-9]+}}, :lo12:.LJTI0_0
+
+; CHECK-MIR: sum:
+; CHECK-MIR: adrp {{x[0-9]+}}, .LJTI0_0
+; CHECK-MIR: add {{x[0-9]+}}, {{x[0-9]+}}, :lo12:.LJTI0_0
+; CHECK-MIR: .Ltmp0:
+; CHECK-MIR: adr {{x[0-9]+}}, .Ltmp0
Index: llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
===================================================================
--- llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
+++ llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
@@ -361,7 +361,9 @@
return JumpTableEntryInfo[Idx].first;
}
MCSymbol *getJumpTableEntryPCRelSymbol(int Idx) const {
- return JumpTableEntryInfo[Idx].second;
+ return (unsigned)Idx < JumpTableEntryInfo.size()
+ ? JumpTableEntryInfo[Idx].second
+ : nullptr;
}
void setJumpTableEntryInfo(int Idx, unsigned Size, MCSymbol *PCRelSym) {
if ((unsigned)Idx >= JumpTableEntryInfo.size())
Index: llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -998,7 +998,15 @@
Register TableReg = MI.getOperand(2).getReg();
Register EntryReg = MI.getOperand(3).getReg();
int JTIdx = MI.getOperand(4).getIndex();
- int Size = AArch64FI->getJumpTableEntrySize(JTIdx);
+
+ int Size;
+ switch (MI.getOpcode()) {
+ case AArch64::JumpTableDest32: Size = 4; break;
+ case AArch64::JumpTableDest16: Size = 2; break;
+ case AArch64::JumpTableDest8: Size = 1; break;
+ default:
+ llvm_unreachable("Unknown jump table size.");
+ }
// This has to be first because the compression pass based its reachability
// calculations on the start of the JumpTableDest instruction.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142974.493544.patch
Type: text/x-patch
Size: 2487 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230131/c6aea71b/attachment.bin>
More information about the llvm-commits
mailing list