Skip to content

Conversation

s-barannikov
Copy link
Contributor

@s-barannikov s-barannikov commented Sep 1, 2025

These instructions encode two operands in the same field. Instead of fixing them after they have been incorrectly decoded, provide a custom decoder.

This will allow to remove -ignore-non-decodable-operands option from AArch64/CMakeLists.txt, see #156358 for the context.

@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-4-aarch64-tsb branch from fa1e14d to fe7aa77 Compare September 1, 2025 18:19
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-5-aarch64-spill-fill branch from 294e56f to 5cc7d7a Compare September 1, 2025 18:19
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-4-aarch64-tsb branch from fe7aa77 to 8b1424a Compare September 1, 2025 19:11
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-5-aarch64-spill-fill branch 2 times, most recently from 261f86f to d72f713 Compare September 1, 2025 20:58
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-4-aarch64-tsb branch from 8b1424a to c82858d Compare September 1, 2025 21:05
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-5-aarch64-spill-fill branch from d72f713 to 772f655 Compare September 1, 2025 21:05
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-4-aarch64-tsb branch from c82858d to f7326ba Compare September 2, 2025 16:08
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-5-aarch64-spill-fill branch 2 times, most recently from 7112890 to ed950c3 Compare September 2, 2025 16:40
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-5-aarch64-spill-fill branch from ed950c3 to f3b4f27 Compare September 3, 2025 19:51
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-4-aarch64-tsb branch 2 times, most recently from d80acf2 to f8f5688 Compare September 3, 2025 20:17
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-5-aarch64-spill-fill branch from f3b4f27 to 6830ba2 Compare September 3, 2025 20:17
@s-barannikov s-barannikov marked this pull request as ready for review September 3, 2025 21:35
@llvmbot
Copy link
Member

llvmbot commented Sep 3, 2025

@llvm/pr-subscribers-backend-aarch64

Author: Sergei Barannikov (s-barannikov)

Changes

These are the only instructions that encode two operands in the same
field. Instead of fixing them after they have been incorrectly decoded,
provide a custom decoder.

This will allow to remove -ignore-non-decodable-operands option from AArch64/CMakeLists.txt, see #156358 for the context.


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

2 Files Affected:

  • (modified) llvm/lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp (+19-10)
  • (modified) llvm/lib/Target/AArch64/SMEInstrFormats.td (+4)
diff --git a/llvm/lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp b/llvm/lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp
index 23e46b84f6278..8c1e9f61693fb 100644
--- a/llvm/lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp
+++ b/llvm/lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp
@@ -1563,6 +1563,25 @@ static DecodeStatus DecodePRFMRegInstruction(MCInst &Inst, uint32_t insn,
   return Success;
 }
 
+static DecodeStatus
+DecodeSMESpillFillInstruction(MCInst &Inst, uint32_t Bits, uint64_t Addr,
+                              const MCDisassembler *Decoder) {
+  unsigned RvBits = fieldFromInstruction(Bits, 13, 2);
+  unsigned RnBits = fieldFromInstruction(Bits, 5, 5);
+  unsigned Imm4Bits = fieldFromInstruction(Bits, 0, 4);
+
+  DecodeSimpleRegisterClass<AArch64::MatrixIndexGPR32_12_15RegClassID, 0, 4>(
+      Inst, RvBits, Addr, Decoder);
+  Inst.addOperand(MCOperand::createImm(Imm4Bits));
+  DecodeSimpleRegisterClass<AArch64::GPR64spRegClassID, 0, 32>(Inst, RnBits,
+                                                               Addr, Decoder);
+  // Spill and fill instructions have a single immediate used for both
+  // the vector select offset and optional memory offset. Replicate
+  // the decoded immediate.
+  Inst.addOperand(MCOperand::createImm(Imm4Bits));
+  return Success;
+}
+
 #include "AArch64GenDisassemblerTables.inc"
 #include "AArch64GenInstrInfo.inc"
 
@@ -1621,16 +1640,6 @@ DecodeStatus AArch64Disassembler::getInstruction(MCInst &MI, uint64_t &Size,
       }
     }
 
-    if (MI.getOpcode() == AArch64::LDR_ZA ||
-        MI.getOpcode() == AArch64::STR_ZA) {
-      // Spill and fill instructions have a single immediate used for both
-      // the vector select offset and optional memory offset. Replicate
-      // the decoded immediate.
-      const MCOperand &Imm4Op = MI.getOperand(2);
-      assert(Imm4Op.isImm() && "Unexpected operand type!");
-      MI.addOperand(Imm4Op);
-    }
-
     if (Result != MCDisassembler::Fail)
       return Result;
   }
diff --git a/llvm/lib/Target/AArch64/SMEInstrFormats.td b/llvm/lib/Target/AArch64/SMEInstrFormats.td
index b3005d5120229..40ec371fe79d3 100644
--- a/llvm/lib/Target/AArch64/SMEInstrFormats.td
+++ b/llvm/lib/Target/AArch64/SMEInstrFormats.td
@@ -1108,6 +1108,10 @@ class sme_spill_fill_base<bit isStore, dag outs, dag ins, string opcodestr>
     : I<outs, ins, opcodestr, "\t$ZAt[$Rv, $imm4], [$Rn, $offset, mul vl]", "",
         []>,
       Sched<[]> {
+  // 'offset' operand is encoded in the same bits as 'imm4'. There is currently
+  // no way to tell TableGen about this.
+  let DecoderMethod = "DecodeSMESpillFillInstruction";
+  bits<0> ZAt;
   bits<2> Rv;
   bits<5> Rn;
   bits<4> imm4;

@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-4-aarch64-tsb branch from f8f5688 to 914f19d Compare September 4, 2025 13:37
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-5-aarch64-spill-fill branch from 6830ba2 to b95e187 Compare September 4, 2025 13:37
@s-barannikov s-barannikov requested a review from MacDue September 4, 2025 14:10
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-4-aarch64-tsb branch from 914f19d to 4789335 Compare September 4, 2025 14:14
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-5-aarch64-spill-fill branch from b95e187 to 9758552 Compare September 4, 2025 14:14
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-4-aarch64-tsb branch from 4789335 to a233e69 Compare September 4, 2025 14:59
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-5-aarch64-spill-fill branch from 9758552 to d296885 Compare September 4, 2025 14:59
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-4-aarch64-tsb branch from a233e69 to cefa6c8 Compare September 4, 2025 16:07
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-5-aarch64-spill-fill branch from d296885 to d6f8e49 Compare September 4, 2025 16:07
@davemgreen davemgreen requested a review from ostannard September 5, 2025 08:56
Copy link
Collaborator

@ostannard ostannard left a comment

Choose a reason for hiding this comment

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

LGTM

Base automatically changed from users/s.barannikov/decoder-operands-4-aarch64-tsb to main September 5, 2025 11:35
These are the only instructions that encode two operands in the same
field. Instead of fixing them after they have been incorrectly decoded,
provide a custom decoder.
@s-barannikov s-barannikov force-pushed the users/s.barannikov/decoder-operands-5-aarch64-spill-fill branch from d6f8e49 to 92ae372 Compare September 5, 2025 11:38
@s-barannikov s-barannikov enabled auto-merge (squash) September 5, 2025 12:16
@s-barannikov s-barannikov merged commit 25498df into main Sep 5, 2025
9 checks passed
@s-barannikov s-barannikov deleted the users/s.barannikov/decoder-operands-5-aarch64-spill-fill branch September 5, 2025 12:43
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 5, 2025

LLVM Buildbot has detected a new failure on builder lldb-aarch64-ubuntu running on linaro-lldb-aarch64-ubuntu while building llvm at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/59/builds/23746

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: functionalities/breakpoint/breakpoint_locations/after_rebuild/TestLocationsAfterRebuild.py (317 of 2316)
PASS: lldb-api :: driver/terminal/TestTerminalDimensions.py (318 of 2316)
PASS: lldb-api :: driver/quit_speed/TestQuitWithProcess.py (319 of 2316)
PASS: lldb-api :: functionalities/breakpoint/breakpoint_on_overload/TestBreakOnOverload.py (320 of 2316)
PASS: lldb-api :: functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py (321 of 2316)
PASS: lldb-api :: functionalities/breakpoint/breakpoint_names/TestBreakpointNames.py (322 of 2316)
PASS: lldb-api :: functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py (323 of 2316)
PASS: lldb-api :: functionalities/breakpoint/breakpoint_with_realpath_and_source_map/TestBreakpoint.py (324 of 2316)
PASS: lldb-api :: functionalities/breakpoint/breakpoint_options/TestBreakpointOptions.py (325 of 2316)
PASS: lldb-api :: functionalities/breakpoint/breakpoint_reset_upon_run/TestBreakpointResetUponRun.py (326 of 2316)
FAIL: lldb-api :: commands/watchpoints/hello_watchlocation/TestWatchLocation.py (327 of 2316)
******************** TEST 'lldb-api :: commands/watchpoints/hello_watchlocation/TestWatchLocation.py' FAILED ********************
Script:
--
/usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --arch aarch64 --build-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/lldb --compiler /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib --cmake-build-type Release /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/commands/watchpoints/hello_watchlocation -p TestWatchLocation.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 22.0.0git (https://github.com/llvm/llvm-project.git revision 25498dfef000f906ad4287d09c4e036a27552cb6)
  clang revision 25498dfef000f906ad4287d09c4e036a27552cb6
  llvm revision 25498dfef000f906ad4287d09c4e036a27552cb6
Skipping the following test categories: ['libc++', 'msvcstl', 'dsym', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
FAIL: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_hello_watchlocation (TestWatchLocation.HelloWatchLocationTestCase)
======================================================================
FAIL: test_hello_watchlocation (TestWatchLocation.HelloWatchLocationTestCase)
   Test watching a location with '-s size' option.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/commands/watchpoints/hello_watchlocation/TestWatchLocation.py", line 97, in test_hello_watchlocation
    self.expect(
  File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 2440, in expect
    self.runCmd(
  File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 1005, in runCmd
    self.assertTrue(self.res.Succeeded(), msg + output)
AssertionError: False is not true : Process should be stopped due to watchpoint
Error output:
error: process must be launched

Config=aarch64-/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang
----------------------------------------------------------------------
Ran 1 test in 10.581s

FAILED (failures=1)

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