[llvm] [llvm-exegesis] Exclude loads/stores from aliasing instruction set (PR #156300)

Sjoerd Meijer via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 3 06:34:35 PDT 2025


https://github.com/sjoerdmeijer updated https://github.com/llvm/llvm-project/pull/156300

>From 33f15e18e5715b87599da146ea0b4d63c6c3e868 Mon Sep 17 00:00:00 2001
From: Sjoerd Meijer <smeijer at nvidia.com>
Date: Mon, 1 Sep 2025 00:37:39 -0700
Subject: [PATCH 1/2] [llvm-exegesis] Exclude loads/stores from aliasing
 instruction set

In the serial snippet generator and function that computes the aliasing
instructions, I don't think we want to include load/store instructions
to create a chain as that could make the results more unreliable.

There is a hasMemoryOperands() check, but I think that's an X86 way for
checking for loads/stores. For AArch64, we should check mayLoad() and
mayStore(), and probably for other architectures too.
---
 .../test/tools/llvm-exegesis/AArch64/no-aliasing-ld-str.s | 8 ++++++++
 llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp   | 2 ++
 2 files changed, 10 insertions(+)
 create mode 100644 llvm/test/tools/llvm-exegesis/AArch64/no-aliasing-ld-str.s

diff --git a/llvm/test/tools/llvm-exegesis/AArch64/no-aliasing-ld-str.s b/llvm/test/tools/llvm-exegesis/AArch64/no-aliasing-ld-str.s
new file mode 100644
index 0000000000000..65e1203bb275d
--- /dev/null
+++ b/llvm/test/tools/llvm-exegesis/AArch64/no-aliasing-ld-str.s
@@ -0,0 +1,8 @@
+REQUIRES: aarch64-registered-target
+
+RUN: llvm-exegesis -mtriple=aarch64 -mcpu=neoverse-v2 -mode=latency --dump-object-to-disk=%d --opcode-name=FMOVWSr --benchmark-phase=assemble-measured-code 2>&1
+RUN: llvm-objdump -d %d > %t.s
+RUN: FileCheck %s < %t.s
+
+CHECK-NOT: ld{{[1-4]}}
+CHECK-NOT: st{{[1-4]}}
diff --git a/llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp b/llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp
index bdfc93e22273b..551da570685d2 100644
--- a/llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp
+++ b/llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp
@@ -57,6 +57,8 @@ computeAliasingInstructions(const LLVMState &State, const Instruction *Instr,
       continue;
     if (OtherInstr.hasMemoryOperands())
       continue;
+    if (OtherInstr.Description.mayLoad() || OtherInstr.Description.mayStore())
+      continue;
     if (!ET.allowAsBackToBack(OtherInstr))
       continue;
     if (Instr->hasAliasingRegistersThrough(OtherInstr, ForbiddenRegisters))

>From 69032ba0719a6451451fb115d615fd4f2967103d Mon Sep 17 00:00:00 2001
From: Sjoerd Meijer <smeijer at nvidia.com>
Date: Wed, 3 Sep 2025 06:31:22 -0700
Subject: [PATCH 2/2] Move checks to hasMemoryOperands()

---
 llvm/tools/llvm-exegesis/lib/MCInstrDescView.cpp        | 2 ++
 llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp | 2 --
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/tools/llvm-exegesis/lib/MCInstrDescView.cpp b/llvm/tools/llvm-exegesis/lib/MCInstrDescView.cpp
index 66c770d9ca86b..d2d9b31df5197 100644
--- a/llvm/tools/llvm-exegesis/lib/MCInstrDescView.cpp
+++ b/llvm/tools/llvm-exegesis/lib/MCInstrDescView.cpp
@@ -206,6 +206,8 @@ const Operand &Instruction::getPrimaryOperand(const Variable &Var) const {
 }
 
 bool Instruction::hasMemoryOperands() const {
+  if (Description.mayLoad() || Description.mayStore())
+    return true;
   return any_of(Operands, [](const Operand &Op) {
     return Op.isReg() && Op.isExplicit() && Op.isMemory();
   });
diff --git a/llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp b/llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp
index 551da570685d2..bdfc93e22273b 100644
--- a/llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp
+++ b/llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp
@@ -57,8 +57,6 @@ computeAliasingInstructions(const LLVMState &State, const Instruction *Instr,
       continue;
     if (OtherInstr.hasMemoryOperands())
       continue;
-    if (OtherInstr.Description.mayLoad() || OtherInstr.Description.mayStore())
-      continue;
     if (!ET.allowAsBackToBack(OtherInstr))
       continue;
     if (Instr->hasAliasingRegistersThrough(OtherInstr, ForbiddenRegisters))



More information about the llvm-commits mailing list