Skip to content

Commit 3c2905d

Browse files
committed
[AArch64] Mark AESD and AESE as commutative.
This come from https://discourse.llvm.org/t/combining-aes-and-xor-can-be-improved-further/77248. These instructions start out with: XOR Vd, Vn <some complicated math> The initial XOR means that they can be treated as commutative, removing some of the unnecessary mov's introduced during register allocation.
1 parent b339c88 commit 3c2905d

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8216,8 +8216,10 @@ defm ST4 : SIMDLdSt4SingleAliases<"st4">;
82168216
//----------------------------------------------------------------------------
82178217

82188218
let Predicates = [HasAES] in {
8219+
let isCommutable = 1 in {
82198220
def AESErr : AESTiedInst<0b0100, "aese", int_aarch64_crypto_aese>;
82208221
def AESDrr : AESTiedInst<0b0101, "aesd", int_aarch64_crypto_aesd>;
8222+
}
82218223
def AESMCrr : AESInst< 0b0110, "aesmc", int_aarch64_crypto_aesmc>;
82228224
def AESIMCrr : AESInst< 0b0111, "aesimc", int_aarch64_crypto_aesimc>;
82238225
}

llvm/test/CodeGen/AArch64/aes.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ define <16 x i8> @aese(<16 x i8> %a, <16 x i8> %b) {
1616
define <16 x i8> @aese_c(<16 x i8> %a, <16 x i8> %b) {
1717
; CHECK-LABEL: aese_c:
1818
; CHECK: // %bb.0:
19-
; CHECK-NEXT: aese v1.16b, v0.16b
20-
; CHECK-NEXT: mov v0.16b, v1.16b
19+
; CHECK-NEXT: aese v0.16b, v1.16b
2120
; CHECK-NEXT: ret
2221
%r = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %b, <16 x i8> %a)
2322
ret <16 x i8> %r
@@ -35,8 +34,7 @@ define <16 x i8> @aesd(<16 x i8> %a, <16 x i8> %b) {
3534
define <16 x i8> @aesd_c(<16 x i8> %a, <16 x i8> %b) {
3635
; CHECK-LABEL: aesd_c:
3736
; CHECK: // %bb.0:
38-
; CHECK-NEXT: aesd v1.16b, v0.16b
39-
; CHECK-NEXT: mov v0.16b, v1.16b
37+
; CHECK-NEXT: aesd v0.16b, v1.16b
4038
; CHECK-NEXT: ret
4139
%r = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %b, <16 x i8> %a)
4240
ret <16 x i8> %r

llvm/test/CodeGen/AArch64/misched-fusion-aes.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ entry:
206206
%aese1 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %in1, <16 x i8> %in1) #2
207207
%in2 = load <16 x i8>, ptr %p2, align 16
208208
%aesmc1= call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %aese1) #2
209-
%aese2 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %in1, <16 x i8> %in2) #2
209+
%aese2 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %aesmc1, <16 x i8> %in2) #2
210210
store <16 x i8> %aesmc1, ptr %x3, align 16
211211
%in3 = load <16 x i8>, ptr %p3, align 16
212212
%aesmc2= call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %aese2) #2

0 commit comments

Comments
 (0)