Skip to content

Commit 389dd45

Browse files
jthackraydvbuka
authored andcommitted
[AArch64][llvm] Armv9.7-A: Add support for SVE2p3 shift operations (llvm#163163)
Add instructions for SVE2p3 shift operations: - SQRSHRN - SQRSHRUN - SQSHRN - SQSHRUN - UQRSHRN - UQSHRN as documented here: * https://developer.arm.com/documentation/ddi0602/2025-09/ * https://developer.arm.com/documentation/109697/2025_09/2025-Architecture-Extensions
1 parent 3fe88ff commit 389dd45

File tree

4 files changed

+627
-10
lines changed

4 files changed

+627
-10
lines changed

llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4272,9 +4272,9 @@ def : Pat<(nxv4i32 (partial_reduce_smla nxv4i32:$Acc, nxv8i16:$MulLHS, nxv8i16:$
42724272
defm SQCVTN_Z2Z_StoH : sve2p1_multi_vec_extract_narrow<"sqcvtn", 0b00, int_aarch64_sve_sqcvtn_x2>;
42734273
defm UQCVTN_Z2Z_StoH : sve2p1_multi_vec_extract_narrow<"uqcvtn", 0b01, int_aarch64_sve_uqcvtn_x2>;
42744274
defm SQCVTUN_Z2Z_StoH : sve2p1_multi_vec_extract_narrow<"sqcvtun", 0b10, int_aarch64_sve_sqcvtun_x2>;
4275-
defm SQRSHRN_Z2ZI_StoH : sve2p1_multi_vec_shift_narrow<"sqrshrn", 0b101, int_aarch64_sve_sqrshrn_x2>;
4276-
defm UQRSHRN_Z2ZI_StoH : sve2p1_multi_vec_shift_narrow<"uqrshrn", 0b111, int_aarch64_sve_uqrshrn_x2>;
4277-
defm SQRSHRUN_Z2ZI_StoH : sve2p1_multi_vec_shift_narrow<"sqrshrun", 0b001, int_aarch64_sve_sqrshrun_x2>;
4275+
defm SQRSHRN_Z2ZI_StoH : sve_multi_vec_shift_narrow<"sqrshrn", 0b101, int_aarch64_sve_sqrshrn_x2>;
4276+
defm UQRSHRN_Z2ZI_StoH : sve_multi_vec_shift_narrow<"uqrshrn", 0b111, int_aarch64_sve_uqrshrn_x2>;
4277+
defm SQRSHRUN_Z2ZI_StoH : sve_multi_vec_shift_narrow<"sqrshrun", 0b001, int_aarch64_sve_sqrshrun_x2>;
42784278

42794279
defm WHILEGE_2PXX : sve2p1_int_while_rr_pair<"whilege", 0b000>;
42804280
defm WHILEGT_2PXX : sve2p1_int_while_rr_pair<"whilegt", 0b001>;
@@ -4648,6 +4648,17 @@ let Predicates = [HasSVE2p3_or_SME2p3] in {
46484648
defm SCVTFLT_ZZ : sve2_int_to_fp_upcvt<"scvtflt", 0b10>;
46494649
defm UCVTF_ZZ : sve2_int_to_fp_upcvt<"ucvtf", 0b01>;
46504650
defm UCVTFLT_ZZ : sve2_int_to_fp_upcvt<"ucvtflt", 0b11>;
4651+
4652+
// SVE2 saturating shift right narrow by immediate and interleave
4653+
defm SQRSHRN_Z2ZI_HtoB : sve_multi_vec_round_shift_narrow<"sqrshrn", 0b101>;
4654+
defm SQRSHRUN_Z2ZI_HtoB : sve_multi_vec_round_shift_narrow<"sqrshrun", 0b001>;
4655+
defm SQSHRN_Z2ZI_HtoB : sve_multi_vec_round_shift_narrow<"sqshrn", 0b000>;
4656+
defm SQSHRUN_Z2ZI_HtoB : sve_multi_vec_round_shift_narrow<"sqshrun", 0b100>;
4657+
defm UQRSHRN_Z2ZI_HtoB : sve_multi_vec_round_shift_narrow<"uqrshrn", 0b111>;
4658+
defm UQSHRN_Z2ZI_HtoB : sve_multi_vec_round_shift_narrow<"uqshrn", 0b010>;
4659+
defm SQSHRUN_Z2ZI_StoH : sve_multi_vec_shift_narrow<"sqshrun", 0b100, null_frag>;
4660+
defm SQSHRN_Z2ZI_StoH : sve_multi_vec_shift_narrow<"sqshrn", 0b000, null_frag>;
4661+
defm UQSHRN_Z2ZI_StoH : sve_multi_vec_shift_narrow<"uqshrn", 0b010, null_frag>;
46514662
} // End HasSME2p3orSVE2p3
46524663

46534664
//===----------------------------------------------------------------------===//

llvm/lib/Target/AArch64/SVEInstrFormats.td

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10050,18 +10050,19 @@ multiclass sve2p1_multi_vec_extract_narrow<string mnemonic, bits<2> opc, SDPatte
1005010050
}
1005110051

1005210052
// SVE2 multi-vec shift narrow
10053-
class sve2p1_multi_vec_shift_narrow<string mnemonic, bits<3> opc, bits<2> tsz>
10054-
: I<(outs ZPR16:$Zd), (ins ZZ_s_mul_r:$Zn, vecshiftR16:$imm4),
10055-
mnemonic, "\t$Zd, $Zn, $imm4",
10053+
class sve2p1_multi_vec_shift_narrow<string mnemonic, ZPRRegOp ZdRC, RegisterOperand ZSrcOp,
10054+
Operand immtype, bits<3> opc, bits<2> tsz>
10055+
: I<(outs ZdRC:$Zd), (ins ZSrcOp:$Zn, immtype:$imm),
10056+
mnemonic, "\t$Zd, $Zn, $imm",
1005610057
"", []>, Sched<[]> {
1005710058
bits<5> Zd;
1005810059
bits<4> Zn;
10059-
bits<4> imm4;
10060+
bits<4> imm;
1006010061
let Inst{31-23} = 0b010001011;
1006110062
let Inst{22} = tsz{1};
1006210063
let Inst{21} = 0b1;
1006310064
let Inst{20} = tsz{0};
10064-
let Inst{19-16} = imm4;
10065+
let Inst{18-16} = imm{2-0}; // imm3
1006510066
let Inst{15-14} = 0b00;
1006610067
let Inst{13-11} = opc;
1006710068
let Inst{10} = 0b0;
@@ -10072,12 +10073,19 @@ class sve2p1_multi_vec_shift_narrow<string mnemonic, bits<3> opc, bits<2> tsz>
1007210073
let hasSideEffects = 0;
1007310074
}
1007410075

10075-
multiclass sve2p1_multi_vec_shift_narrow<string mnemonic, bits<3> opc, SDPatternOperator intrinsic> {
10076-
def NAME : sve2p1_multi_vec_shift_narrow<mnemonic, opc, 0b01>;
10076+
multiclass sve_multi_vec_shift_narrow<string mnemonic, bits<3> opc, SDPatternOperator intrinsic> {
10077+
def NAME : sve2p1_multi_vec_shift_narrow<mnemonic, ZPR16, ZZ_s_mul_r, vecshiftR16, opc, 0b01> {
10078+
let Inst{19} = imm{3}; // imm4
10079+
}
1007710080

1007810081
def : SVE2p1_Sat_Shift_VG2_Pat<NAME, intrinsic, nxv8i16, nxv4i32, vecshiftR16>;
1007910082
}
1008010083

10084+
multiclass sve_multi_vec_round_shift_narrow<string mnemonic, bits<3> opc> {
10085+
def NAME : sve2p1_multi_vec_shift_narrow<mnemonic, ZPR8, ZZ_h_mul_r, vecshiftR8, opc, 0b00> {
10086+
let Inst{19} = 0b1; // always 1 for imm3 version
10087+
}
10088+
}
1008110089

1008210090
// SME2 multi-vec contiguous load (scalar plus scalar, two registers)
1008310091
class sve2p1_mem_cld_ss_2z<string mnemonic, bits<2> msz, bit n,

0 commit comments

Comments
 (0)