[llvm] [llvm-exegesis] [AArch64] Resolving Illegal Instruction Error (PR #132346)

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 24 03:35:13 PDT 2025


https://github.com/lakshayk-nv updated https://github.com/llvm/llvm-project/pull/132346

>From f1e1d7ace8910afe37cad2a4834800991ef42b5c Mon Sep 17 00:00:00 2001
From: lakshayk-nv <lakshayk at nvidia.com>
Date: Thu, 20 Mar 2025 23:32:23 -0700
Subject: [PATCH 1/2] [llvm-exegesis] [AArch64] Resolving Illegal Instruction
 Error 1) Checking opcodes specifically for LDGM and AUT opcode instruction
 variants. 2) Gracefully exiting with "<opcode-name> : Unsupported opcode:
 isPointerAuth/isUncheckedAccess" 3) Added corresponding test cases to check
 exit message.

---
 .../AArch64/err_skip_illegal_Instruction.s             |  8 ++++++++
 llvm/tools/llvm-exegesis/lib/Target.cpp                | 10 ++++++++++
 2 files changed, 18 insertions(+)
 create mode 100644 llvm/test/tools/llvm-exegesis/AArch64/err_skip_illegal_Instruction.s

diff --git a/llvm/test/tools/llvm-exegesis/AArch64/err_skip_illegal_Instruction.s b/llvm/test/tools/llvm-exegesis/AArch64/err_skip_illegal_Instruction.s
new file mode 100644
index 0000000000000..74fe5a7c3a60a
--- /dev/null
+++ b/llvm/test/tools/llvm-exegesis/AArch64/err_skip_illegal_Instruction.s
@@ -0,0 +1,8 @@
+REQUIRES: aarch64-registered-target
+
+## Check for skipping of illegal instruction errors (AUT and LDGM)
+RUN: llvm-exegesis -mcpu=neoverse-v2 -mode=latency --dump-object-to-disk=%d --min-instructions=1 --opcode-name=AUTIA --benchmark-phase=assemble-measured-code 2>&1
+CHECK: AUTIA: Unsupported opcode: isPointerAuth/isUncheckedAccess
+
+RUN: llvm-exegesis -mcpu=neoverse-v2 -mode=latency --dump-object-to-disk=%d --min-instructions=1 --opcode-name=LDGM --benchmark-phase=assemble-measured-code 2>&1
+CHECK: LDGM: Unsupported opcode: isPointerAuth/isUncheckedAccess
\ No newline at end of file
diff --git a/llvm/tools/llvm-exegesis/lib/Target.cpp b/llvm/tools/llvm-exegesis/lib/Target.cpp
index 68d19514bedb2..245d1db5d21e8 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Target.cpp
@@ -35,6 +35,14 @@ const ExegesisTarget *ExegesisTarget::lookup(Triple TT) {
   return nullptr;
 }
 
+static bool isPointerAuthOpcode(unsigned Opcode) {
+  return (Opcode >= 1648 && Opcode <= 1667); // AUT instruction class range
+}
+
+static bool isUncheckedAccessOpcode(unsigned Opcode) {
+  return Opcode == 4694; // LDGM instruction
+}
+
 const char *
 ExegesisTarget::getIgnoredOpcodeReasonOrNull(const LLVMState &State,
                                              unsigned Opcode) const {
@@ -45,6 +53,8 @@ ExegesisTarget::getIgnoredOpcodeReasonOrNull(const LLVMState &State,
     return "Unsupported opcode: isBranch/isIndirectBranch";
   if (InstrDesc.isCall() || InstrDesc.isReturn())
     return "Unsupported opcode: isCall/isReturn";
+  if (isPointerAuthOpcode(Opcode) || isUncheckedAccessOpcode(Opcode))
+    return "Unsupported opcode: isPointerAuth/isUncheckedAccess";
   return nullptr;
 }
 

>From 5039c2b1e1c63c4900b113bf6db662303faf7f53 Mon Sep 17 00:00:00 2001
From: lakshayk-nv <lakshayk at nvidia.com>
Date: Mon, 24 Mar 2025 02:29:41 -0700
Subject: [PATCH 2/2] [llvm-exegesis] [AArch64] Use enum values for opcode
 validation

- Replace hardcoded opcode ranges with AArch64::* enum values for pointer auth and
unchecked access instructions.
- Add required AArch64 headers and update tests.
- Style changes for corresponding testcases.
---
 .../AArch64/err_skip_illegal_Instruction.s    | 12 +++----
 llvm/tools/llvm-exegesis/lib/CMakeLists.txt   |  4 +++
 llvm/tools/llvm-exegesis/lib/Target.cpp       | 31 +++++++++++++++++--
 3 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/llvm/test/tools/llvm-exegesis/AArch64/err_skip_illegal_Instruction.s b/llvm/test/tools/llvm-exegesis/AArch64/err_skip_illegal_Instruction.s
index 74fe5a7c3a60a..3e95bf9a376c7 100644
--- a/llvm/test/tools/llvm-exegesis/AArch64/err_skip_illegal_Instruction.s
+++ b/llvm/test/tools/llvm-exegesis/AArch64/err_skip_illegal_Instruction.s
@@ -1,8 +1,8 @@
-REQUIRES: aarch64-registered-target
+# REQUIRES: aarch64-registered-target
 
-## Check for skipping of illegal instruction errors (AUT and LDGM)
-RUN: llvm-exegesis -mcpu=neoverse-v2 -mode=latency --dump-object-to-disk=%d --min-instructions=1 --opcode-name=AUTIA --benchmark-phase=assemble-measured-code 2>&1
-CHECK: AUTIA: Unsupported opcode: isPointerAuth/isUncheckedAccess
+# Check for skipping of illegal instruction errors (AUT and LDGM)
+# RUN: llvm-exegesis -mcpu=neoverse-v2 -mode=latency --opcode-name=AUTIA --benchmark-phase=assemble-measured-code 2>&1
+# CHECK: AUTIA: Unsupported opcode: isPointerAuth/isUncheckedAccess
 
-RUN: llvm-exegesis -mcpu=neoverse-v2 -mode=latency --dump-object-to-disk=%d --min-instructions=1 --opcode-name=LDGM --benchmark-phase=assemble-measured-code 2>&1
-CHECK: LDGM: Unsupported opcode: isPointerAuth/isUncheckedAccess
\ No newline at end of file
+# RUN: llvm-exegesis -mcpu=neoverse-v2 -mode=latency --opcode-name=LDGM --benchmark-phase=assemble-measured-code 2>&1
+# CHECK: LDGM: Unsupported opcode: isPointerAuth/isUncheckedAccess
diff --git a/llvm/tools/llvm-exegesis/lib/CMakeLists.txt b/llvm/tools/llvm-exegesis/lib/CMakeLists.txt
index d95c37ff5426b..2de073eda3810 100644
--- a/llvm/tools/llvm-exegesis/lib/CMakeLists.txt
+++ b/llvm/tools/llvm-exegesis/lib/CMakeLists.txt
@@ -1,3 +1,7 @@
+include_directories(
+  ${LLVM_MAIN_SRC_DIR}/lib/Target/AArch64
+  ${LLVM_BINARY_DIR}/lib/Target/AArch64
+  )
 
 set(LLVM_EXEGESIS_TARGETS)
 if (LLVM_TARGETS_TO_BUILD MATCHES "X86")
diff --git a/llvm/tools/llvm-exegesis/lib/Target.cpp b/llvm/tools/llvm-exegesis/lib/Target.cpp
index 245d1db5d21e8..b6a98ec5aa31f 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Target.cpp
@@ -15,6 +15,8 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Error.h"
 #include "llvm/TargetParser/SubtargetFeature.h"
+#include "AArch64.h"
+#include "AArch64RegisterInfo.h"
 
 namespace llvm {
 namespace exegesis {
@@ -36,12 +38,35 @@ const ExegesisTarget *ExegesisTarget::lookup(Triple TT) {
 }
 
 static bool isPointerAuthOpcode(unsigned Opcode) {
-  return (Opcode >= 1648 && Opcode <= 1667); // AUT instruction class range
+  switch (Opcode) {
+    case AArch64::AUTDA:
+    case AArch64::AUTDB:
+    case AArch64::AUTDZA:
+    case AArch64::AUTDZB:
+    case AArch64::AUTIA:
+    case AArch64::AUTIA1716:
+    case AArch64::AUTIASP:
+    case AArch64::AUTIAZ:
+    case AArch64::AUTIB:
+    case AArch64::AUTIB1716:
+    case AArch64::AUTIBSP:
+    case AArch64::AUTIBZ:
+    case AArch64::AUTIZA:
+    case AArch64::AUTIZB:
+      return true;
+    default:
+      return false;
+  }
 }
 
 static bool isUncheckedAccessOpcode(unsigned Opcode) {
-  return Opcode == 4694; // LDGM instruction
-}
+  switch (Opcode) {
+    case AArch64::LDGM:
+      return true;
+    default:
+      return false;
+  }
+  }
 
 const char *
 ExegesisTarget::getIgnoredOpcodeReasonOrNull(const LLVMState &State,



More information about the llvm-commits mailing list