Skip to content

Commit 531b1f9

Browse files
committed
[AArch64] Add assembly/disassembly for zeroing SVE2 integer instructions
This patch adds assembly/disassembly for the following SVE2.2 instructions - SQABS (zeroing) - SQNEG (zeroing) - URECPE (zeroing) - USQRTE (zeroing) - Refactor the existing merging forms to remove the now redundant bit 17 argument. - In accordance with: https://developer.arm.com/documentation/ddi0602/latest/
1 parent 9a8292f commit 531b1f9

14 files changed

+366
-20
lines changed

llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,10 +3586,10 @@ let Predicates = [HasSVE2orSME] in {
35863586
defm UMINP_ZPmZ : sve2_int_arith_pred<0b101111, "uminp", int_aarch64_sve_uminp>;
35873587

35883588
// SVE2 integer unary operations (predicated)
3589-
defm URECPE_ZPmZ : sve2_int_un_pred_arit_s<0b000, "urecpe", int_aarch64_sve_urecpe>;
3590-
defm URSQRTE_ZPmZ : sve2_int_un_pred_arit_s<0b001, "ursqrte", int_aarch64_sve_ursqrte>;
3591-
defm SQABS_ZPmZ : sve2_int_un_pred_arit<0b100, "sqabs", int_aarch64_sve_sqabs>;
3592-
defm SQNEG_ZPmZ : sve2_int_un_pred_arit<0b101, "sqneg", int_aarch64_sve_sqneg>;
3589+
defm URECPE_ZPmZ : sve2_int_un_pred_arit_s<0b00, "urecpe", int_aarch64_sve_urecpe>;
3590+
defm URSQRTE_ZPmZ : sve2_int_un_pred_arit_s<0b01, "ursqrte", int_aarch64_sve_ursqrte>;
3591+
defm SQABS_ZPmZ : sve2_int_un_pred_arit< 0b10, "sqabs", int_aarch64_sve_sqabs>;
3592+
defm SQNEG_ZPmZ : sve2_int_un_pred_arit< 0b11, "sqneg", int_aarch64_sve_sqneg>;
35933593

35943594
// SVE2 saturating add/subtract
35953595
defm SQADD_ZPmZ : sve2_int_arith_pred<0b110000, "sqadd", int_aarch64_sve_sqadd>;
@@ -4227,6 +4227,12 @@ let Predicates = [HasSVE2p2orSME2p2] in {
42274227
// SVE2p2 floating-point convert single-to-bf (placing odd), zeroing predicate
42284228
def BFCVTNT_ZPzZ : sve_fp_fcvt2z<0b1010, "bfcvtnt", ZPR16, ZPR32>;
42294229

4230+
// SVE2p2 integer unary operations, zeroing predicate
4231+
def URECPE_ZPzZ : sve2_int_un_pred_arit_z<0b10, 0b00, "urecpe", ZPR32>;
4232+
def URSQRTE_ZPzZ : sve2_int_un_pred_arit_z<0b10, 0b01, "ursqrte", ZPR32>;
4233+
defm SQABS_ZPzZ : sve2_int_un_pred_arit_z<0b10, "sqabs">;
4234+
defm SQNEG_ZPzZ : sve2_int_un_pred_arit_z<0b11, "sqneg">;
4235+
42304236
// Floating point round to integral fp value in integer size range
42314237
// Merging
42324238
defm FRINT32Z_ZPmZ : sve_fp_2op_p_zd_frint<0b00, "frint32z">;

llvm/lib/Target/AArch64/SVEInstrFormats.td

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,7 +3900,7 @@ multiclass sve2_int_sadd_long_accum_pairwise<bit U, string asm, SDPatternOperato
39003900
def : SVE_3_Op_Pat<nxv2i64, op, nxv2i1, nxv2i64, nxv4i32, !cast<Instruction>(NAME # _D)>;
39013901
}
39023902

3903-
class sve2_int_un_pred_arit<bits<2> sz, bit Q, bits<2> opc,
3903+
class sve2_int_un_pred_arit<bits<2> sz, bits<2> opc,
39043904
string asm, ZPRRegOp zprty>
39053905
: I<(outs zprty:$Zd), (ins zprty:$_Zd, PPR3bAny:$Pg, zprty:$Zn),
39063906
asm, "\t$Zd, $Pg/m, $Zn",
@@ -3912,23 +3912,44 @@ class sve2_int_un_pred_arit<bits<2> sz, bit Q, bits<2> opc,
39123912
let Inst{31-24} = 0b01000100;
39133913
let Inst{23-22} = sz;
39143914
let Inst{21-20} = 0b00;
3915-
let Inst{19} = Q;
3916-
let Inst{18} = 0b0;
3917-
let Inst{17-16} = opc;
3915+
let Inst{19} = opc{1};
3916+
let Inst{18-17} = 0b00;
3917+
let Inst{16} = opc{0};
39183918
let Inst{15-13} = 0b101;
39193919
let Inst{12-10} = Pg;
39203920
let Inst{9-5} = Zn;
39213921
let Inst{4-0} = Zd;
3922-
39233922
let Constraints = "$Zd = $_Zd";
39243923
let DestructiveInstType = DestructiveUnaryPassthru;
39253924
let ElementSize = zprty.ElementSize;
39263925
let hasSideEffects = 0;
39273926
}
39283927

3929-
multiclass sve2_int_un_pred_arit_s<bits<3> opc, string asm,
3928+
class sve2_int_un_pred_arit_z<bits<2> sz, bits<2> opc,
3929+
string asm, ZPRRegOp zprty>
3930+
: I<(outs zprty:$Zd), (ins PPR3bAny:$Pg, zprty:$Zn),
3931+
asm, "\t$Zd, $Pg/z, $Zn",
3932+
"",
3933+
[]>, Sched<[]> {
3934+
bits<3> Pg;
3935+
bits<5> Zd;
3936+
bits<5> Zn;
3937+
let Inst{31-24} = 0b01000100;
3938+
let Inst{23-22} = sz;
3939+
let Inst{21-20} = 0b00;
3940+
let Inst{19} = opc{1};
3941+
let Inst{18-17} = 0b01;
3942+
let Inst{16} = opc{0};
3943+
let Inst{15-13} = 0b101;
3944+
let Inst{12-10} = Pg;
3945+
let Inst{9-5} = Zn;
3946+
let Inst{4-0} = Zd;
3947+
let hasSideEffects = 0;
3948+
}
3949+
3950+
multiclass sve2_int_un_pred_arit_s<bits<2> opc, string asm,
39303951
SDPatternOperator op> {
3931-
def _S : sve2_int_un_pred_arit<0b10, opc{2}, opc{1-0}, asm, ZPR32>,
3952+
def _S : sve2_int_un_pred_arit<0b10, opc, asm, ZPR32>,
39323953
SVEPseudo2Instr<NAME # _S, 1>;
39333954

39343955
def : SVE_3_Op_Pat<nxv4i32, op, nxv4i32, nxv4i1, nxv4i32, !cast<Instruction>(NAME # _S)>;
@@ -3938,14 +3959,14 @@ multiclass sve2_int_un_pred_arit_s<bits<3> opc, string asm,
39383959
defm : SVE_3_Op_Undef_Pat<nxv4i32, op, nxv4i32, nxv4i1, nxv4i32, !cast<Pseudo>(NAME # _S_UNDEF)>;
39393960
}
39403961

3941-
multiclass sve2_int_un_pred_arit<bits<3> opc, string asm, SDPatternOperator op> {
3942-
def _B : sve2_int_un_pred_arit<0b00, opc{2}, opc{1-0}, asm, ZPR8>,
3962+
multiclass sve2_int_un_pred_arit<bits<2> opc, string asm, SDPatternOperator op> {
3963+
def _B : sve2_int_un_pred_arit<0b00, opc, asm, ZPR8>,
39433964
SVEPseudo2Instr<NAME # _B, 1>;
3944-
def _H : sve2_int_un_pred_arit<0b01, opc{2}, opc{1-0}, asm, ZPR16>,
3965+
def _H : sve2_int_un_pred_arit<0b01, opc, asm, ZPR16>,
39453966
SVEPseudo2Instr<NAME # _H, 1>;
3946-
def _S : sve2_int_un_pred_arit<0b10, opc{2}, opc{1-0}, asm, ZPR32>,
3967+
def _S : sve2_int_un_pred_arit<0b10, opc, asm, ZPR32>,
39473968
SVEPseudo2Instr<NAME # _S, 1>;
3948-
def _D : sve2_int_un_pred_arit<0b11, opc{2}, opc{1-0}, asm, ZPR64>,
3969+
def _D : sve2_int_un_pred_arit<0b11, opc, asm, ZPR64>,
39493970
SVEPseudo2Instr<NAME # _D, 1>;
39503971

39513972
def : SVE_3_Op_Pat<nxv16i8, op, nxv16i8, nxv16i1, nxv16i8, !cast<Instruction>(NAME # _B)>;
@@ -3964,6 +3985,13 @@ multiclass sve2_int_un_pred_arit<bits<3> opc, string asm, SDPatternOperator op>
39643985
defm : SVE_3_Op_Undef_Pat<nxv2i64, op, nxv2i64, nxv2i1, nxv2i64, !cast<Pseudo>(NAME # _D_UNDEF)>;
39653986
}
39663987

3988+
multiclass sve2_int_un_pred_arit_z<bits<2> opc, string asm> {
3989+
def _B : sve2_int_un_pred_arit_z<0b00, opc, asm, ZPR8>;
3990+
def _H : sve2_int_un_pred_arit_z<0b01, opc, asm, ZPR16>;
3991+
def _S : sve2_int_un_pred_arit_z<0b10, opc, asm, ZPR32>;
3992+
def _D : sve2_int_un_pred_arit_z<0b11, opc, asm, ZPR64>;
3993+
}
3994+
39673995
//===----------------------------------------------------------------------===//
39683996
// SVE2 Widening Integer Arithmetic Group
39693997
//===----------------------------------------------------------------------===//

llvm/test/MC/AArch64/SVE2/sqabs-diagnostics.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Invalid predicate
55

66
sqabs z0.s, p0/z, z1.s
7-
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
7+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: instruction requires: sme2p2 or sve2p2
88
// CHECK-NEXT: sqabs z0.s, p0/z, z1.s
99
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
1010

llvm/test/MC/AArch64/SVE2/sqneg-diagnostics.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Invalid predicate
55

66
sqneg z0.s, p0/z, z1.s
7-
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
7+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: instruction requires: sme2p2 or sve2p2
88
// CHECK-NEXT: sqneg z0.s, p0/z, z1.s
99
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
1010

llvm/test/MC/AArch64/SVE2/urecpe-diagnostics.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Invalid predicate
55

66
urecpe z0.s, p0/z, z1.s
7-
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
7+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: instruction requires: sme2p2 or sve2p2
88
// CHECK-NEXT: urecpe z0.s, p0/z, z1.s
99
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
1010

llvm/test/MC/AArch64/SVE2/ursqrte-diagnostics.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Invalid predicate
55

66
ursqrte z0.s, p0/z, z1.s
7-
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
7+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: instruction requires: sme2p2 or sve2p2
88
// CHECK-NEXT: ursqrte z0.s, p0/z, z1.s
99
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
1010

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: not llvm-mc -triple=aarch64 -show-encoding -mattr=+sve2p2 2>&1 < %s| FileCheck %s
2+
3+
// ------------------------------------------------------------------------- //
4+
// Invalid element width
5+
6+
sqabs z31.b, p7/z, z31.h
7+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid element width
8+
// CHECK-NEXT: sqabs z31.b, p7/z, z31.h
9+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
10+
11+
sqabs z31.d, p7/z, z31.s
12+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid element width
13+
// CHECK-NEXT: sqabs z31.d, p7/z, z31.s
14+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
15+
16+
// ------------------------------------------------------------------------- //
17+
// Invalid predicate
18+
19+
sqabs z31.b, p8/z, z31.b
20+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid restricted predicate register, expected p0..p7 (without element suffix)
21+
// CHECK-NEXT: sqabs z31.b, p8/z, z31.b
22+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
23+
24+
// --------------------------------------------------------------------------//
25+
// Negative tests for instructions that are incompatible with movprfx
26+
27+
movprfx z0.h, p0/z, z7.h
28+
sqabs z0.h, p0/z, z3.h
29+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: instruction is unpredictable when following a movprfx, suggest replacing movprfx with mov
30+
// CHECK-NEXT: sqabs z0.h, p0/z, z3.h
31+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
32+
33+
movprfx z0, z7
34+
sqabs z0.h, p0/z, z3.h
35+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: instruction is unpredictable when following a movprfx, suggest replacing movprfx with mov
36+
// CHECK-NEXT: sqabs z0.h, p0/z, z3.h
37+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve2p2 < %s \
2+
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
3+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme2p2 < %s \
4+
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
5+
// RUN: not llvm-mc -triple=aarch64 -show-encoding < %s 2>&1 \
6+
// RUN: | FileCheck %s --check-prefix=CHECK-ERROR
7+
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve2p2 < %s \
8+
// RUN: | llvm-objdump -d --mattr=+sve2p2 - | FileCheck %s --check-prefix=CHECK-INST
9+
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve2p2 < %s \
10+
// RUN: | llvm-objdump -d --mattr=-sme2 - | FileCheck %s --check-prefix=CHECK-UNKNOWN
11+
// Disassemble encoding and check the re-encoding (-show-encoding) matches.
12+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve2p2 < %s \
13+
// RUN: | sed '/.text/d' | sed 's/.*encoding: //g' \
14+
// RUN: | llvm-mc -triple=aarch64 -mattr=+sve2p2 -disassemble -show-encoding \
15+
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
16+
17+
sqabs z0.b, p0/z, z0.b // 01000100-00001010-10100000-00000000
18+
// CHECK-INST: sqabs z0.b, p0/z, z0.b
19+
// CHECK-ENCODING: [0x00,0xa0,0x0a,0x44]
20+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
21+
// CHECK-UNKNOWN: 440aa000 <unknown>
22+
23+
sqabs z21.h, p5/z, z10.h // 01000100-01001010-10110101-01010101
24+
// CHECK-INST: sqabs z21.h, p5/z, z10.h
25+
// CHECK-ENCODING: [0x55,0xb5,0x4a,0x44]
26+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
27+
// CHECK-UNKNOWN: 444ab555 <unknown>
28+
29+
sqabs z23.s, p3/z, z13.s // 01000100-10001010-10101101-10110111
30+
// CHECK-INST: sqabs z23.s, p3/z, z13.s
31+
// CHECK-ENCODING: [0xb7,0xad,0x8a,0x44]
32+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
33+
// CHECK-UNKNOWN: 448aadb7 <unknown>
34+
35+
sqabs z31.d, p7/z, z31.d // 01000100-11001010-10111111-11111111
36+
// CHECK-INST: sqabs z31.d, p7/z, z31.d
37+
// CHECK-ENCODING: [0xff,0xbf,0xca,0x44]
38+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
39+
// CHECK-UNKNOWN: 44cabfff <unknown>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: not llvm-mc -triple=aarch64 -show-encoding -mattr=+sve2p2 2>&1 < %s| FileCheck %s
2+
3+
// ------------------------------------------------------------------------- //
4+
// Invalid element width
5+
6+
sqneg z31.b, p7/z, z31.h
7+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid element width
8+
// CHECK-NEXT: sqneg z31.b, p7/z, z31.h
9+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
10+
11+
sqneg z31.d, p7/z, z31.s
12+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid element width
13+
// CHECK-NEXT: sqneg z31.d, p7/z, z31.s
14+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
15+
16+
// ------------------------------------------------------------------------- //
17+
// Invalid predicate
18+
19+
sqneg z31.b, p8/z, z31.b
20+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid restricted predicate register, expected p0..p7 (without element suffix)
21+
// CHECK-NEXT: sqneg z31.b, p8/z, z31.b
22+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
23+
24+
// --------------------------------------------------------------------------//
25+
// Negative tests for instructions that are incompatible with movprfx
26+
27+
movprfx z0.h, p0/z, z7.h
28+
sqneg z0.h, p0/z, z3.h
29+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: instruction is unpredictable when following a movprfx, suggest replacing movprfx with mov
30+
// CHECK-NEXT: sqneg z0.h, p0/z, z3.h
31+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
32+
33+
movprfx z0, z7
34+
sqneg z0.h, p0/z, z3.h
35+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: instruction is unpredictable when following a movprfx, suggest replacing movprfx with mov
36+
// CHECK-NEXT: sqneg z0.h, p0/z, z3.h
37+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve2p2 < %s \
2+
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
3+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme2p2 < %s \
4+
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
5+
// RUN: not llvm-mc -triple=aarch64 -show-encoding < %s 2>&1 \
6+
// RUN: | FileCheck %s --check-prefix=CHECK-ERROR
7+
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve2p2 < %s \
8+
// RUN: | llvm-objdump -d --mattr=+sve2p2 - | FileCheck %s --check-prefix=CHECK-INST
9+
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve2p2 < %s \
10+
// RUN: | llvm-objdump -d --mattr=-sme2 - | FileCheck %s --check-prefix=CHECK-UNKNOWN
11+
// Disassemble encoding and check the re-encoding (-show-encoding) matches.
12+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve2p2 < %s \
13+
// RUN: | sed '/.text/d' | sed 's/.*encoding: //g' \
14+
// RUN: | llvm-mc -triple=aarch64 -mattr=+sve2p2 -disassemble -show-encoding \
15+
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
16+
17+
sqneg z0.b, p0/z, z0.b // 01000100-00001011-10100000-00000000
18+
// CHECK-INST: sqneg z0.b, p0/z, z0.b
19+
// CHECK-ENCODING: [0x00,0xa0,0x0b,0x44]
20+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
21+
// CHECK-UNKNOWN: 440ba000 <unknown>
22+
23+
sqneg z23.h, p3/z, z13.h // 01000100-01001011-10101101-10110111
24+
// CHECK-INST: sqneg z23.h, p3/z, z13.h
25+
// CHECK-ENCODING: [0xb7,0xad,0x4b,0x44]
26+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
27+
// CHECK-UNKNOWN: 444badb7 <unknown>
28+
29+
sqneg z21.s, p5/z, z10.s // 01000100-10001011-10110101-01010101
30+
// CHECK-INST: sqneg z21.s, p5/z, z10.s
31+
// CHECK-ENCODING: [0x55,0xb5,0x8b,0x44]
32+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
33+
// CHECK-UNKNOWN: 448bb555 <unknown>
34+
35+
sqneg z31.d, p7/z, z31.d // 01000100-11001011-10111111-11111111
36+
// CHECK-INST: sqneg z31.d, p7/z, z31.d
37+
// CHECK-ENCODING: [0xff,0xbf,0xcb,0x44]
38+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
39+
// CHECK-UNKNOWN: 44cbbfff <unknown>

0 commit comments

Comments
 (0)