Skip to content

Conversation

@sjoerdmeijer
Copy link
Collaborator

Move the mayLoad/mayStore checks out of hasMemoryOperands; there are instructions with these properties that don't have operands.

…on set" (llvm#156735)

Move the mayLoad/mayStore checks out of hasMemoryOperands; there are
instructions with these properties that don't have operands.
@llvmbot
Copy link
Member

llvmbot commented Sep 17, 2025

@llvm/pr-subscribers-tools-llvm-exegesis

Author: Sjoerd Meijer (sjoerdmeijer)

Changes

Move the mayLoad/mayStore checks out of hasMemoryOperands; there are instructions with these properties that don't have operands.


Full diff: https://github.com/llvm/llvm-project/pull/159366.diff

2 Files Affected:

  • (added) llvm/test/tools/llvm-exegesis/AArch64/no-aliasing-ld-str.s (+8)
  • (modified) llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp (+6)
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..707e6ee2d434b 100644
--- a/llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp
+++ b/llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp
@@ -57,6 +57,12 @@ computeAliasingInstructions(const LLVMState &State, const Instruction *Instr,
       continue;
     if (OtherInstr.hasMemoryOperands())
       continue;
+    // Filtering out loads/stores might belong in hasMemoryOperands(), but that
+    // complicates things as there are instructions with may load/store that
+    // don't have operands (e.g. X86's CLUI instruction). So, it's easier to
+    // filter them out here.
+    if (OtherInstr.Description.mayLoad() || OtherInstr.Description.mayStore())
+      continue;
     if (!ET.allowAsBackToBack(OtherInstr))
       continue;
     if (Instr->hasAliasingRegistersThrough(OtherInstr, ForbiddenRegisters))

Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please add the commit SHA of the patch this is relanding in the commit/PR description.

@sjoerdmeijer
Copy link
Collaborator Author

sjoerdmeijer commented Sep 17, 2025

Hi @boomanaiden154, I had to revert the previous commit because I broke all the x86 bots. I have reverted the implementation back to one of my first versions, and have hoisted the extra checks out of hasMemoryOperands function. As I wrote in the comments, I hit problems with X86 instructions that don't have any operands, so that would require checks at the call sites of hasMemoryOperands, and I thought it was just easier to filter the mayLoad and mayStore here.

After breaking all the x86 bots, I released that there are actually quite a few x86 regression tests that involve running and evaluating latency/throughput measurements and thus running it on hardware. I am on a non-x86 platform, do have the X86 backend built, but realised that I am not running those test when I develop locally, so that was a little lesson learned.

@sjoerdmeijer
Copy link
Collaborator Author

LGTM. Please add the commit SHA of the patch this is relanding in the commit/PR description.

Thanks for the review, and will do.

@boomanaiden154
Copy link
Contributor

After breaking all the x86 bots, I released that there are actually quite a few x86 regression tests that involve running and evaluating latency/throughput measurements and thus running it on hardware. I am on a non-x86 platform, do have the X86 backend built, but realised that I am not running those test when I develop locally, so that was a little lesson learned.

Yeah, those tests are nice to have to test the execution flow, but definitely run extremely sparingly. You need to be on Linux with perf counter access, and quite a few of the bots are virtualized which prevents perf counter access.

@sjoerdmeijer sjoerdmeijer merged commit af20597 into llvm:main Oct 6, 2025
11 checks passed
@sjoerdmeijer sjoerdmeijer deleted the exegesis-no-aliasing-ld-st-2 branch October 6, 2025 08:49
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 6, 2025
…on set" (llvm#156735) (llvm#159366)

Move the mayLoad/mayStore checks out of hasMemoryOperands; there are
instructions with these properties that don't have operands.

This is relanding 899ee37 with a 
minor tweak.
@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is %d a standard lit substitution? I don't see it in https://llvm.org/docs/CommandGuide/lit.html#substitutions.

@DavidSpickett
Copy link
Collaborator

The added test is failing on our 2 stage SVE builders, not on single stage for reasons I don't understand. Also it has passed once on one of the builders, so it could be something about our host machines.

https://lab.llvm.org/buildbot/#/builders/41/builds/9394

--
# RUN: at line 3
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/bin/llvm-exegesis -mtriple=aarch64 -mcpu=neoverse-v2 -mode=latency --dump-object-to-disk=%d --opcode-name=FMOVWSr --benchmark-phase=assemble-measured-code 2>&1
# executed command: /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/bin/llvm-exegesis -mtriple=aarch64 -mcpu=neoverse-v2 -mode=latency --dump-object-to-disk=%d --opcode-name=FMOVWSr --benchmark-phase=assemble-measured-code
# .---command stdout------------
# | Check generated assembly with: /usr/bin/objdump -d %d
# | ---
# | mode:            latency
# | key:
# |   instructions:
# |     - 'FMOVWSr S22 W27'
# |     - 'FCVTNUUWSr W21 S22'
# |   config:          ''
# |   register_initial_values:
# |     - 'W27=0x0'
# |     - 'FPCR=0x0'
# | cpu_name:        neoverse-v2
# | llvm_triple:     aarch64
# | min_instructions: 10000
# | measurements:    []
# | error:           actual measurements skipped.
# | info:            Repeating two instructions
# | assembled_snippet: FB57BFA91B008052080080D208441BD57603271ED502211E7603271ED502211E7603271ED502211E7603271ED502211EFB57C1A8C0035FD6
# | ...
# `-----------------------------
# RUN: at line 4
/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/bin/llvm-objdump -d %d > /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/test/tools/llvm-exegesis/AArch64/Output/no-aliasing-ld-str.s.tmp.s
# executed command: /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/bin/llvm-objdump -d %d
# .---redirected output from '/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/test/tools/llvm-exegesis/AArch64/Output/no-aliasing-ld-str.s.tmp.s'
# | 
# | %d:	file format elf64-littleaarch64
# | 
# | Disassembly of section .text:
# | 
# | 0000000000000000 <foo>:
# |        0: a9bf57fb     	stp	x27, x21, [sp, #-0x10]!
# |        4: 5280001b     	mov	w27, #0x0               // =0
# |        8: d2800008     	mov	x8, #0x0                // =0
# |        c: d51b4408     	msr	FPCR, x8
# |       10: 1e270376     	fmov	s22, w27
# |       14: 1e2102d5     	fcvtnu	w21, s22
# |       18: 1e270376     	fmov	s22, w27
# |       1c: 1e2102d5     	fcvtnu	w21, s22
# |       20: 1e270376     	fmov	s22, w27
# |       24: 1e2102d5     	fcvtnu	w21, s22
# |       28: 1e270376     	fmov	s22, w27
# |       2c: 1e2102d5     	fcvtnu	w21, s22
# |       30: 1e270376     	fmov	s22, w27
# |       34: 1e2102d5     	fcvtnu	w21, s22
# |       38: 1e270376     	fmov	s22, w27
# |       3c: 1e2102d5     	fcvtnu	w21, s22
# |       40: 1e270376     	fmov	s22, w27
# |       44: 1e2102d5     	fcvtnu	w21, s22
# |       48: 1e270376     	fmov	s22, w27
# |       4c: 1e2102d5     	fcvtnu	w21, s22
# |       50: 1e270376     	fmov	s22, w27
# |       54: 1e2102d5     	fcvtnu	w21, s22
# |       58: 1e270376     	
# | ...
# `---data was truncated--------
# .---command stderr------------
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
# | Stack dump:
# | 0.	Program arguments: /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/bin/llvm-objdump -d %d
# |  #0 0x0000ac231dbf32c0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/bin/llvm-objdump+0x23632c0)
# |  #1 0x0000ac231dbf0ed4 llvm::sys::RunSignalHandlers() (/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/bin/llvm-objdump+0x2360ed4)
# |  #2 0x0000ac231dbf404c SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
# |  #3 0x0000ed33f8f27968 (linux-vdso.so.1+0x968)
# |  #4 0x0000ac231dac51b8 llvm::object::ELFFile<llvm::object::ELFType<(llvm::endianness)1, true>>::sections() const (/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/bin/llvm-objdump+0x22351b8)
# |  #5 0x0000ac231daff9b0 llvm::object::ELFObjectFile<llvm::object::ELFType<(llvm::endianness)1, true>>::getSectionIndex(llvm::object::DataRefImpl) const (/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/bin/llvm-objdump+0x226f9b0)
# |  #6 0x0000ac231d573ed0 disassembleObject(llvm::object::ObjectFile&, llvm::object::ObjectFile const&, (anonymous namespace)::DisassemblerTarget&, std::optional<(anonymous namespace)::DisassemblerTarget>&, llvm::objdump::SourcePrinter&, bool, llvm::raw_ostream&) llvm-objdump.cpp:0:0
# |  #7 0x0000ac231d56b14c dumpObject(llvm::object::ObjectFile*, llvm::object::Archive const*, llvm::object::Archive::Child const*) llvm-objdump.cpp:0:0
# |  #8 0x0000ac231d55df0c llvm_objdump_main(int, char**, llvm::ToolContext const&) (/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/bin/llvm-objdump+0x1ccdf0c)
# |  #9 0x0000ac231d604578 main (/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/bin/llvm-objdump+0x1d74578)
# | #10 0x0000ed33f8a373fc __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
# | #11 0x0000ed33f8a374cc call_init ./csu/../csu/libc-start.c:128:20
# | #12 0x0000ed33f8a374cc __libc_start_main ./csu/../csu/libc-start.c:379:5
# | #13 0x0000ac231d554b70 _start (/home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/stage2/bin/llvm-objdump+0x1cc4b70)
# `-----------------------------
# error: command failed with exit status: -7

Seems like it's llvm-objdump crashing so it could be a disassembly issue we've not hit before. I won't have time to reproduce it until tomorrow.

Let me know if anything in there stands out or there's any reason having SVE or SVE2 on the machine would be a problem. For instance, is this expected?

# | error:           actual measurements skipped.

DavidSpickett added a commit that referenced this pull request Oct 6, 2025
Test added by #159366

This is causing objdump to crash more often than not on our 2 stage
SVE bots, disabling it and I will investigate tomorrow.

Could be the changes in the PR, or a pre-existing codegen or
llvm-objdump problem.
@DavidSpickett
Copy link
Collaborator

I disabled the test, will have time to look into it tomorrow.

@boomanaiden154
Copy link
Contributor

Let me know if anything in there stands out or there's any reason having SVE or SVE2 on the machine would be a problem.

I don't why SVE in particular would change things, especially in regards to objdump crashing. My only guess would be that it changes the exegesis codegen which then hits an edge case in objdump.

For instance, is this expected?

Yes, that is expected.

@sjoerdmeijer
Copy link
Collaborator Author

Ah, sorry about the late response, I now see I missed a few buildbot messages.
Thanks @DavidSpickett for disabling the test. Like you, I am very much surprised, and don't understand what's going on. Let me know what you find or if I can help.

DavidSpickett added a commit that referenced this pull request Oct 7, 2025
I assume that %d was meant to be %t. It did work with %d but it was
making a file literally called that. Which if nothing else, looks
like it's broken.

Test remains disabled as I haven't found the cause of the llvm-objdump
failure yet.

Test added by #159366.
@DavidSpickett
Copy link
Collaborator

Unrelated to llvm-objdump failing, I hammered the test with the first stage build on an AArch64 machine without SVE and sometimes (1 in a 1000 runs maybe) would fail with an error about operands:

$ ./bin/llvm-lit ../llvm-project/llvm/test/tools/llvm-exegesis/AArch64/no-aliasing-ld-str.s -a
-- Testing: 1 tests, 1 workers --
FAIL: LLVM :: tools/llvm-exegesis/AArch64/no-aliasing-ld-str.s (1 of 1)
******************** TEST 'LLVM :: tools/llvm-exegesis/AArch64/no-aliasing-ld-str.s' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 3
/home/david.spickett/build-llvm-aarch64/bin/llvm-exegesis -mtriple=aarch64 -mcpu=neoverse-v2 -mode=latency --dump-object-to-disk=/home/david.spickett/build-llvm-aarch64/test/tools/llvm-exegesis/AArch64/Output/no-aliasing-ld-str.s.tmp --opcode-name=FMOVWSr --benchmark-phase=assemble-measured-code 2>&1
# executed command: /home/david.spickett/build-llvm-aarch64/bin/llvm-exegesis -mtriple=aarch64 -mcpu=neoverse-v2 -mode=latency --dump-object-to-disk=/home/david.spickett/build-llvm-aarch64/test/tools/llvm-exegesis/AArch64/Output/no-aliasing-ld-str.s.tmp --opcode-name=FMOVWSr --benchmark-phase=assemble-measured-code
# .---command stdout------------
# | FMOVWSr: Not all operands were initialized by the snippet generator for UMOVvi8 opcode.
# `-----------------------------
# RUN: at line 4
/home/david.spickett/build-llvm-aarch64/bin/llvm-objdump -d /home/david.spickett/build-llvm-aarch64/test/tools/llvm-exegesis/AArch64/Output/no-aliasing-ld-str.s.tmp > /home/david.spickett/build-llvm-aarch64/test/tools/llvm-exegesis/AArch64/Output/no-aliasing-ld-str.s.tmp.s
# executed command: /home/david.spickett/build-llvm-aarch64/bin/llvm-objdump -d /home/david.spickett/build-llvm-aarch64/test/tools/llvm-exegesis/AArch64/Output/no-aliasing-ld-str.s.tmp
# .---command stderr------------
# | /home/david.spickett/build-llvm-aarch64/bin/llvm-objdump: error: '/home/david.spickett/build-llvm-aarch64/test/tools/llvm-exegesis/AArch64/Output/no-aliasing-ld-str.s.tmp': No such file or directory
# `-----------------------------
# error: command failed with exit status: 1

--

********************
********************
Failed Tests (1):
  LLVM :: tools/llvm-exegesis/AArch64/no-aliasing-ld-str.s


Testing Time: 0.06s

Total Discovered Tests: 1
  Failed: 1 (100.00%)
❌ Failed on run 813 (exit 1). Output:
-- Testing: 1 tests, 1 workers --
FAIL: LLVM :: tools/llvm-exegesis/AArch64/no-aliasing-ld-str.s (1 of 1)
******************** TEST 'LLVM :: tools/llvm-exegesis/AArch64/no-aliasing-ld-str.s' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 3
/home/david.spickett/build-llvm-aarch64/bin/llvm-exegesis -mtriple=aarch64 -mcpu=neoverse-v2 -mode=latency --dump-object-to-disk=/home/david.spickett/build-llvm-aarch64/test/tools/llvm-exegesis/AArch64/Output/no-aliasing-ld-str.s.tmp.obj --opcode-name=FMOVWSr --benchmark-phase=assemble-measured-code 2>&1
# executed command: /home/david.spickett/build-llvm-aarch64/bin/llvm-exegesis -mtriple=aarch64 -mcpu=neoverse-v2 -mode=latency --dump-object-to-disk=/home/david.spickett/build-llvm-aarch64/test/tools/llvm-exegesis/AArch64/Output/no-aliasing-ld-str.s.tmp.obj --opcode-name=FMOVWSr --benchmark-phase=assemble-measured-code
# .---command stdout------------
# | FMOVWSr: Not all operands were initialized by the snippet generator for FCVTZSSWSri opcode.
# `-----------------------------
# RUN: at line 4
/home/david.spickett/build-llvm-aarch64/bin/llvm-objdump -d /home/david.spickett/build-llvm-aarch64/test/tools/llvm-exegesis/AArch64/Output/no-aliasing-ld-str.s.tmp.obj > /home/david.spickett/build-llvm-aarch64/test/tools/llvm-exegesis/AArch64/Output/no-aliasing-ld-str.s.tmp.s
# executed command: /home/david.spickett/build-llvm-aarch64/bin/llvm-objdump -d /home/david.spickett/build-llvm-aarch64/test/tools/llvm-exegesis/AArch64/Output/no-aliasing-ld-str.s.tmp.obj
# .---command stderr------------
# | /home/david.spickett/build-llvm-aarch64/bin/llvm-objdump: error: '/home/david.spickett/build-llvm-aarch64/test/tools/llvm-exegesis/AArch64/Output/no-aliasing-ld-str.s.tmp.obj': No such file or directory
# `-----------------------------
# error: command failed with exit status: 1

--

********************
********************
Failed Tests (1):
  LLVM :: tools/llvm-exegesis/AArch64/no-aliasing-ld-str.s


Testing Time: 0.06s

Total Discovered Tests: 1
  Failed: 1 (100.00%)

Just in case that error means anything to you.

@DavidSpickett
Copy link
Collaborator

Another one:

# .---command stdout------------
# | FMOVWSr: Not all operands were initialized by the snippet generator for FCVTZUSXDri opcode.
# `-----------------------------

@boomanaiden154
Copy link
Contributor

Unrelated to llvm-objdump failing, I hammered the test with the first stage build on an AArch64 machine without SVE and sometimes (1 in a 1000 runs maybe) would fail with an error about operands:

Exegesis uses a random seed for generating operands, and it occasionally will trip a case that hasn't been properly handled. I think there are one or two other tests that need fixing because of this. That should be a separate issue from what you're observing with llvm-objdump crashing though.

@DavidSpickett
Copy link
Collaborator

I enabled the test again.

The CHECK-NOT was picking up the file path that llvm-objdump prints, I fixed that. llvm-objdump no longer crashes, so I have no idea why that was happening. We have refreshed all the bot containers since then, that could have "fixed" it.

Unfortunately I got more failure notifications like:

# .---command stdout------------
# | FMOVWSr: Not all operands were initialized by the snippet generator for UMOVvi32 opcode.
# `-----------------------------

And I don't think it's worth the spam to leave this enabled. Please fix the errors before enabling it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants