Skip to content

Commit 5d3899d

Browse files
authored
[AArch64][SVE] Mark AES instructions commutable. (#142919)
We already do this for the Neon versions of the instructions, just not for SVE.
1 parent c70c0a8 commit 5d3899d

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4064,8 +4064,10 @@ let Predicates = [HasSVE2_or_SME] in {
40644064

40654065
let Predicates = [HasSVEAES, HasNonStreamingSVE2_or_SSVE_AES] in {
40664066
// SVE2 crypto destructive binary operations
4067-
defm AESE_ZZZ_B : sve2_crypto_des_bin_op<0b00, "aese", ZPR8, int_aarch64_sve_aese, nxv16i8>;
4068-
defm AESD_ZZZ_B : sve2_crypto_des_bin_op<0b01, "aesd", ZPR8, int_aarch64_sve_aesd, nxv16i8>;
4067+
let isCommutable = 1 in {
4068+
def AESE_ZZZ_B : sve2_crypto_des_bin_op<0b00, "aese", ZPR8, int_aarch64_sve_aese, nxv16i8>;
4069+
def AESD_ZZZ_B : sve2_crypto_des_bin_op<0b01, "aesd", ZPR8, int_aarch64_sve_aesd, nxv16i8>;
4070+
}
40694071

40704072
// SVE2 crypto unary operations
40714073
defm AESMC_ZZ_B : sve2_crypto_unary_op<0b0, "aesmc", int_aarch64_sve_aesmc>;
@@ -4082,7 +4084,7 @@ let Predicates = [HasSVE2SM4] in {
40824084
// SVE2 crypto constructive binary operations
40834085
defm SM4EKEY_ZZZ_S : sve2_crypto_cons_bin_op<0b0, "sm4ekey", ZPR32, int_aarch64_sve_sm4ekey, nxv4i32>;
40844086
// SVE2 crypto destructive binary operations
4085-
defm SM4E_ZZZ_S : sve2_crypto_des_bin_op<0b10, "sm4e", ZPR32, int_aarch64_sve_sm4e, nxv4i32>;
4087+
def SM4E_ZZZ_S : sve2_crypto_des_bin_op<0b10, "sm4e", ZPR32, int_aarch64_sve_sm4e, nxv4i32>;
40864088
} // End HasSVE2SM4
40874089

40884090
let Predicates = [HasSVE2SHA3] in {

llvm/lib/Target/AArch64/SVEInstrFormats.td

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9235,11 +9235,12 @@ multiclass sve2_crypto_cons_bin_op<bit opc, string asm, ZPRRegOp zprty,
92359235
def : SVE_2_Op_Pat<vt, op, vt, vt, !cast<Instruction>(NAME)>;
92369236
}
92379237

9238-
class sve2_crypto_des_bin_op<bits<2> opc, string asm, ZPRRegOp zprty>
9238+
class sve2_crypto_des_bin_op<bits<2> opc, string asm, ZPRRegOp zprty,
9239+
SDPatternOperator op, ValueType vt>
92399240
: I<(outs zprty:$Zdn), (ins zprty:$_Zdn, zprty:$Zm),
92409241
asm, "\t$Zdn, $_Zdn, $Zm",
92419242
"",
9242-
[]>, Sched<[]> {
9243+
[(set (vt zprty:$Zdn), (op (vt zprty:$_Zdn), (vt zprty:$Zm)))]>, Sched<[]> {
92439244
bits<5> Zdn;
92449245
bits<5> Zm;
92459246
let Inst{31-17} = 0b010001010010001;
@@ -9253,12 +9254,6 @@ class sve2_crypto_des_bin_op<bits<2> opc, string asm, ZPRRegOp zprty>
92539254
let hasSideEffects = 0;
92549255
}
92559256

9256-
multiclass sve2_crypto_des_bin_op<bits<2> opc, string asm, ZPRRegOp zprty,
9257-
SDPatternOperator op, ValueType vt> {
9258-
def NAME : sve2_crypto_des_bin_op<opc, asm, zprty>;
9259-
def : SVE_2_Op_Pat<vt, op, vt, vt, !cast<Instruction>(NAME)>;
9260-
}
9261-
92629257
class sve2_crypto_unary_op<bit opc, string asm, ZPRRegOp zprty>
92639258
: I<(outs zprty:$Zdn), (ins zprty:$_Zdn),
92649259
asm, "\t$Zdn, $_Zdn",

llvm/test/CodeGen/AArch64/sve2-intrinsics-crypto.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ define <vscale x 16 x i8> @aesd_i8(<vscale x 16 x i8> %a, <vscale x 16 x i8> %b)
1616
ret <vscale x 16 x i8> %out
1717
}
1818

19+
define <vscale x 16 x i8> @aesd_i8_commuted(<vscale x 16 x i8> %a,
20+
; CHECK-LABEL: aesd_i8_commuted:
21+
; CHECK: // %bb.0:
22+
; CHECK-NEXT: aesd z0.b, z0.b, z1.b
23+
; CHECK-NEXT: ret
24+
<vscale x 16 x i8> %b) {
25+
%out = call <vscale x 16 x i8> @llvm.aarch64.sve.aesd(<vscale x 16 x i8> %b,
26+
<vscale x 16 x i8> %a)
27+
ret <vscale x 16 x i8> %out
28+
}
29+
1930
;
2031
; AESIMC
2132
;
@@ -43,6 +54,17 @@ define <vscale x 16 x i8> @aese_i8(<vscale x 16 x i8> %a, <vscale x 16 x i8> %b)
4354
ret <vscale x 16 x i8> %out
4455
}
4556

57+
define <vscale x 16 x i8> @aese_i8_commuted(<vscale x 16 x i8> %a,
58+
; CHECK-LABEL: aese_i8_commuted:
59+
; CHECK: // %bb.0:
60+
; CHECK-NEXT: aese z0.b, z0.b, z1.b
61+
; CHECK-NEXT: ret
62+
<vscale x 16 x i8> %b) {
63+
%out = call <vscale x 16 x i8> @llvm.aarch64.sve.aese(<vscale x 16 x i8> %b,
64+
<vscale x 16 x i8> %a)
65+
ret <vscale x 16 x i8> %out
66+
}
67+
4668
;
4769
; AESMC
4870
;

0 commit comments

Comments
 (0)