Skip to content

Conversation

jthackray
Copy link
Contributor

@jthackray jthackray commented Sep 22, 2025

sve_intx_dot and sve2p1_two_way_dot_vv are both very similar, encoding for SDOT instructions. Refactor the sve_intx_dot class so it is more flexible, and delete the sve2p1_two_way_dot_vv class.

Making this change now, to accommodate future SDOT instructions.

@llvmbot
Copy link
Member

llvmbot commented Sep 22, 2025

@llvm/pr-subscribers-backend-aarch64

Author: Jonathan Thackray (jthackray)

Changes

sve_intx_dot and sve2p1_two_way_dot_vv are both very similar, encoding for SDOT instructions. Refactor the sve_intx_dot class so it is more flexible, and delete the sve2p1_two_way_dot_vv class. Making this change now, to accommodate future SDOT instructions.


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

1 Files Affected:

  • (modified) llvm/lib/Target/AArch64/SVEInstrFormats.td (+13-33)
diff --git a/llvm/lib/Target/AArch64/SVEInstrFormats.td b/llvm/lib/Target/AArch64/SVEInstrFormats.td
index 7913e8ca8652e..0b50ba5425704 100644
--- a/llvm/lib/Target/AArch64/SVEInstrFormats.td
+++ b/llvm/lib/Target/AArch64/SVEInstrFormats.td
@@ -3748,18 +3748,18 @@ multiclass sve2_int_mla_long_by_indexed_elem<bits<4> opc, string asm,
 // SVE Integer Dot Product Group
 //===----------------------------------------------------------------------===//
 
-class sve_intx_dot<bit sz, bit U, string asm, ZPRRegOp zprty1,
-                   ZPRRegOp zprty2>
+class sve_intx_dot<bits<2> sz, bits<5> op5, bit U, string asm,
+                   ZPRRegOp zprty1, ZPRRegOp zprty2>
 : I<(outs zprty1:$Zda), (ins zprty1:$_Zda, zprty2:$Zn, zprty2:$Zm), asm,
   "\t$Zda, $Zn, $Zm", "", []>, Sched<[]> {
   bits<5> Zda;
   bits<5> Zn;
   bits<5> Zm;
-  let Inst{31-23} = 0b010001001;
-  let Inst{22}    = sz;
+  let Inst{31-24} = 0b01000100;
+  let Inst{23-22} = sz;
   let Inst{21}    = 0;
   let Inst{20-16} = Zm;
-  let Inst{15-11} = 0;
+  let Inst{15-11} = op5;
   let Inst{10}    = U;
   let Inst{9-5}   = Zn;
   let Inst{4-0}   = Zda;
@@ -3770,13 +3770,19 @@ class sve_intx_dot<bit sz, bit U, string asm, ZPRRegOp zprty1,
 }
 
 multiclass sve_intx_dot<bit opc, string asm, SDPatternOperator op> {
-  def _S : sve_intx_dot<0b0, opc, asm, ZPR32, ZPR8>;
-  def _D : sve_intx_dot<0b1, opc, asm, ZPR64, ZPR16>;
+  def _S : sve_intx_dot<0b10, 0b00000, opc, asm, ZPR32, ZPR8>;
+  def _D : sve_intx_dot<0b11, 0b00000, opc, asm, ZPR64, ZPR16>;
 
   def : SVE_3_Op_Pat<nxv4i32, op, nxv4i32,  nxv16i8, nxv16i8, !cast<Instruction>(NAME # _S)>;
   def : SVE_3_Op_Pat<nxv2i64, op, nxv2i64,  nxv8i16, nxv8i16, !cast<Instruction>(NAME # _D)>;
 }
 
+multiclass sve2p1_two_way_dot_vv<string mnemonic, bit u, SDPatternOperator intrinsic> {
+  def NAME : sve_intx_dot<0b00, 0b11001, u, mnemonic, ZPR32, ZPR16>;
+
+  def : SVE_3_Op_Pat<nxv4i32, intrinsic, nxv4i32, nxv8i16, nxv8i16, !cast<Instruction>(NAME)>;
+}
+
 //===----------------------------------------------------------------------===//
 // SVE Integer Dot Product Group - Indexed Group
 //===----------------------------------------------------------------------===//
@@ -9893,32 +9899,6 @@ multiclass sve_fp_clamp_bfloat<string asm, SDPatternOperator op> {
   def : SVE_3_Op_Pat<nxv8bf16, op, nxv8bf16, nxv8bf16, nxv8bf16, !cast<Instruction>(NAME)>;
 }
 
-// SVE two-way dot product
-class sve2p1_two_way_dot_vv<string mnemonic, bit u>
-    : I<(outs ZPR32:$Zda), (ins ZPR32:$_Zda, ZPR16:$Zn, ZPR16:$Zm),
-        mnemonic, "\t$Zda, $Zn, $Zm",
-        "", []>, Sched<[]> {
-  bits<5> Zda;
-  bits<5> Zn;
-  bits<5> Zm;
-  let Inst{31-21} = 0b01000100000;
-  let Inst{20-16} = Zm;
-  let Inst{15-11} = 0b11001;
-  let Inst{10}    = u;
-  let Inst{9-5}   = Zn;
-  let Inst{4-0}   = Zda;
-
-  let Constraints = "$Zda = $_Zda";
-  let DestructiveInstType = DestructiveOther;
-  let hasSideEffects = 0;
-}
-
-multiclass sve2p1_two_way_dot_vv<string mnemonic, bit u, SDPatternOperator intrinsic> {
-  def NAME : sve2p1_two_way_dot_vv<mnemonic, u>;
-
-  def : SVE_3_Op_Pat<nxv4i32, intrinsic, nxv4i32, nxv8i16, nxv8i16, !cast<Instruction>(NAME)>;
-}
-
 // SVE two-way dot product (indexed)
 class sve2p1_two_way_dot_vvi<string mnemonic, bit u>
     : I<(outs ZPR32:$Zda), (ins ZPR32:$_Zda, ZPR16:$Zn, ZPR3b16:$Zm, VectorIndexS32b:$i2),

@Lukacma
Copy link
Contributor

Lukacma commented Sep 24, 2025

Since we are already merging these 2, we might as well merge both multiclasses together as well. These are the same instructions, its just that intx_dot variants do 4 way sdot while two_way do 2 way sdot. I don't think there is a reason to have separate multiclass for that.

@jthackray
Copy link
Contributor Author

Since we are already merging these 2, we might as well merge both multiclasses together

Thanks, good idea. I tried this, and it looks nice. However, they require different predicates (HasSVE2p1_or_SME2 and HasSVE_or_SME) which precludes joining them easily. So I think I'll have to skip your suggestion.

…1_two_way_dot_vv`

`sve_intx_dot` and `sve2p1_two_way_dot_vv` are both very similar,
encoding for `SDOT` instructions. Refactor the `sve_intx_dot` class
so it is more flexible, and delete the `sve2p1_two_way_dot_vv` class.
Making this change now, to accommodate future SDOT instructions.
@jthackray jthackray force-pushed the users/jthackray/refactor-aarch64-sve_intx_dot branch from 9fd0600 to 2bd1bfa Compare September 24, 2025 15:38
Copy link
Contributor

@Lukacma Lukacma left a comment

Choose a reason for hiding this comment

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

Ah yeah missed that. LGTM then

@jthackray jthackray merged commit 2657c79 into main Sep 25, 2025
9 checks passed
@jthackray jthackray deleted the users/jthackray/refactor-aarch64-sve_intx_dot branch September 25, 2025 14:13
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
…1_two_way_dot_vv` (llvm#160103)

`sve_intx_dot` and `sve2p1_two_way_dot_vv` are both very similar,
encoding for `SDOT` instructions. Refactor the `sve_intx_dot` class so
it is more flexible, and delete the `sve2p1_two_way_dot_vv` class.

Making this change now, to accommodate future SDOT instructions.
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.

3 participants