1 ; RUN: llc %s -o - -mtriple=aarch64-unknown -mattr=+fuse-aes,+crypto | FileCheck %s
2 ; RUN: llc %s -o - -mtriple=aarch64-unknown -mcpu=generic -mattr=+crypto | FileCheck %s
3 ; RUN: llc %s -o - -mtriple=aarch64-unknown -mcpu=cortex-a53 | FileCheck %s
4 ; RUN: llc %s -o - -mtriple=aarch64-unknown -mcpu=cortex-a57 | FileCheck %s
5 ; RUN: llc %s -o - -mtriple=aarch64-unknown -mcpu=cortex-a72 | FileCheck %s
6 ; RUN: llc %s -o - -mtriple=aarch64-unknown -mcpu=cortex-a73 | FileCheck %s
7 ; RUN: llc %s -o - -mtriple=aarch64-unknown -mcpu=exynos-m1 | FileCheck %s
8 ; RUN: llc %s -o - -mtriple=aarch64-unknown -mcpu=exynos-m2 | FileCheck %s
9 ; RUN: llc %s -o - -mtriple=aarch64-unknown -mcpu=exynos-m3 | FileCheck %s
10 ; RUN: llc %s -o - -mtriple=aarch64-unknown -mcpu=exynos-m4 | FileCheck %s
11 ; RUN: llc %s -o - -mtriple=aarch64-unknown -mcpu=exynos-m5 | FileCheck %s
13 declare <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %d, <16 x i8> %k)
14 declare <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %d)
15 declare <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %d, <16 x i8> %k)
16 declare <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %d)
18 define void @aesea(<16 x i8>* %a0, <16 x i8>* %b0, <16 x i8>* %c0, <16 x i8> %d, <16 x i8> %e) {
19 %d0 = load <16 x i8>, <16 x i8>* %a0
20 %a1 = getelementptr inbounds <16 x i8>, <16 x i8>* %a0, i64 1
21 %d1 = load <16 x i8>, <16 x i8>* %a1
22 %a2 = getelementptr inbounds <16 x i8>, <16 x i8>* %a0, i64 2
23 %d2 = load <16 x i8>, <16 x i8>* %a2
24 %a3 = getelementptr inbounds <16 x i8>, <16 x i8>* %a0, i64 3
25 %d3 = load <16 x i8>, <16 x i8>* %a3
26 %k0 = load <16 x i8>, <16 x i8>* %b0
27 %e00 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %d0, <16 x i8> %k0)
28 %f00 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e00)
29 %e01 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %d1, <16 x i8> %k0)
30 %f01 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e01)
31 %e02 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %d2, <16 x i8> %k0)
32 %f02 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e02)
33 %e03 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %d3, <16 x i8> %k0)
34 %f03 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e03)
35 %b1 = getelementptr inbounds <16 x i8>, <16 x i8>* %b0, i64 1
36 %k1 = load <16 x i8>, <16 x i8>* %b1
37 %e10 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f00, <16 x i8> %k1)
38 %f10 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e00)
39 %e11 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f01, <16 x i8> %k1)
40 %f11 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e01)
41 %e12 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f02, <16 x i8> %k1)
42 %f12 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e02)
43 %e13 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f03, <16 x i8> %k1)
44 %f13 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e03)
45 %b2 = getelementptr inbounds <16 x i8>, <16 x i8>* %b0, i64 2
46 %k2 = load <16 x i8>, <16 x i8>* %b2
47 %e20 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f10, <16 x i8> %k2)
48 %f20 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e10)
49 %e21 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f11, <16 x i8> %k2)
50 %f21 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e11)
51 %e22 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f12, <16 x i8> %k2)
52 %f22 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e12)
53 %e23 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f13, <16 x i8> %k2)
54 %f23 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e13)
55 %b3 = getelementptr inbounds <16 x i8>, <16 x i8>* %b0, i64 3
56 %k3 = load <16 x i8>, <16 x i8>* %b3
57 %e30 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f20, <16 x i8> %k3)
58 %f30 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e20)
59 %e31 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f21, <16 x i8> %k3)
60 %f31 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e21)
61 %e32 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f22, <16 x i8> %k3)
62 %f32 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e22)
63 %e33 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f23, <16 x i8> %k3)
64 %f33 = call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %e23)
65 %g0 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f30, <16 x i8> %d)
66 %h0 = xor <16 x i8> %g0, %e
67 %g1 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f31, <16 x i8> %d)
68 %h1 = xor <16 x i8> %g1, %e
69 %g2 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f32, <16 x i8> %d)
70 %h2 = xor <16 x i8> %g2, %e
71 %g3 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %f33, <16 x i8> %d)
72 %h3 = xor <16 x i8> %g3, %e
73 store <16 x i8> %h0, <16 x i8>* %c0
74 %c1 = getelementptr inbounds <16 x i8>, <16 x i8>* %c0, i64 1
75 store <16 x i8> %h1, <16 x i8>* %c1
76 %c2 = getelementptr inbounds <16 x i8>, <16 x i8>* %c0, i64 2
77 store <16 x i8> %h2, <16 x i8>* %c2
78 %c3 = getelementptr inbounds <16 x i8>, <16 x i8>* %c0, i64 3
79 store <16 x i8> %h3, <16 x i8>* %c3
83 ; CHECK: aese [[VA:v[0-7].16b]], {{v[0-7].16b}}
84 ; CHECK-NEXT: aesmc [[VA]], [[VA]]
85 ; CHECK: aese [[VB:v[0-7].16b]], {{v[0-7].16b}}
86 ; CHECK-NEXT: aesmc [[VB]], [[VB]]
87 ; CHECK: aese [[VC:v[0-7].16b]], {{v[0-7].16b}}
88 ; CHECK-NEXT: aesmc [[VC]], [[VC]]
89 ; CHECK: aese [[VD:v[0-7].16b]], {{v[0-7].16b}}
90 ; CHECK-NEXT: aesmc [[VD]], [[VD]]
91 ; CHECK: aese [[VE:v[0-7].16b]], {{v[0-7].16b}}
92 ; CHECK-NEXT: aesmc [[VE]], [[VE]]
93 ; CHECK: aese [[VF:v[0-7].16b]], {{v[0-7].16b}}
94 ; CHECK-NEXT: aesmc [[VF]], [[VF]]
95 ; CHECK: aese [[VG:v[0-7].16b]], {{v[0-7].16b}}
96 ; CHECK-NEXT: aesmc [[VG]], [[VG]]
97 ; CHECK: aese [[VH:v[0-7].16b]], {{v[0-7].16b}}
98 ; CHECK-NEXT: aesmc [[VH]], [[VH]]
102 define void @aesda(<16 x i8>* %a0, <16 x i8>* %b0, <16 x i8>* %c0, <16 x i8> %d, <16 x i8> %e) {
103 %d0 = load <16 x i8>, <16 x i8>* %a0
104 %a1 = getelementptr inbounds <16 x i8>, <16 x i8>* %a0, i64 1
105 %d1 = load <16 x i8>, <16 x i8>* %a1
106 %a2 = getelementptr inbounds <16 x i8>, <16 x i8>* %a0, i64 2
107 %d2 = load <16 x i8>, <16 x i8>* %a2
108 %a3 = getelementptr inbounds <16 x i8>, <16 x i8>* %a0, i64 3
109 %d3 = load <16 x i8>, <16 x i8>* %a3
110 %k0 = load <16 x i8>, <16 x i8>* %b0
111 %e00 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %d0, <16 x i8> %k0)
112 %f00 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e00)
113 %e01 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %d1, <16 x i8> %k0)
114 %f01 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e01)
115 %e02 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %d2, <16 x i8> %k0)
116 %f02 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e02)
117 %e03 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %d3, <16 x i8> %k0)
118 %f03 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e03)
119 %b1 = getelementptr inbounds <16 x i8>, <16 x i8>* %b0, i64 1
120 %k1 = load <16 x i8>, <16 x i8>* %b1
121 %e10 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f00, <16 x i8> %k1)
122 %f10 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e00)
123 %e11 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f01, <16 x i8> %k1)
124 %f11 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e01)
125 %e12 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f02, <16 x i8> %k1)
126 %f12 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e02)
127 %e13 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f03, <16 x i8> %k1)
128 %f13 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e03)
129 %b2 = getelementptr inbounds <16 x i8>, <16 x i8>* %b0, i64 2
130 %k2 = load <16 x i8>, <16 x i8>* %b2
131 %e20 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f10, <16 x i8> %k2)
132 %f20 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e10)
133 %e21 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f11, <16 x i8> %k2)
134 %f21 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e11)
135 %e22 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f12, <16 x i8> %k2)
136 %f22 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e12)
137 %e23 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f13, <16 x i8> %k2)
138 %f23 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e13)
139 %b3 = getelementptr inbounds <16 x i8>, <16 x i8>* %b0, i64 3
140 %k3 = load <16 x i8>, <16 x i8>* %b3
141 %e30 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f20, <16 x i8> %k3)
142 %f30 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e20)
143 %e31 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f21, <16 x i8> %k3)
144 %f31 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e21)
145 %e32 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f22, <16 x i8> %k3)
146 %f32 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e22)
147 %e33 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f23, <16 x i8> %k3)
148 %f33 = call <16 x i8> @llvm.aarch64.crypto.aesimc(<16 x i8> %e23)
149 %g0 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f30, <16 x i8> %d)
150 %h0 = xor <16 x i8> %g0, %e
151 %g1 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f31, <16 x i8> %d)
152 %h1 = xor <16 x i8> %g1, %e
153 %g2 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f32, <16 x i8> %d)
154 %h2 = xor <16 x i8> %g2, %e
155 %g3 = call <16 x i8> @llvm.aarch64.crypto.aesd(<16 x i8> %f33, <16 x i8> %d)
156 %h3 = xor <16 x i8> %g3, %e
157 store <16 x i8> %h0, <16 x i8>* %c0
158 %c1 = getelementptr inbounds <16 x i8>, <16 x i8>* %c0, i64 1
159 store <16 x i8> %h1, <16 x i8>* %c1
160 %c2 = getelementptr inbounds <16 x i8>, <16 x i8>* %c0, i64 2
161 store <16 x i8> %h2, <16 x i8>* %c2
162 %c3 = getelementptr inbounds <16 x i8>, <16 x i8>* %c0, i64 3
163 store <16 x i8> %h3, <16 x i8>* %c3
166 ; CHECK-LABEL: aesda:
167 ; CHECK: aesd [[VA:v[0-7].16b]], {{v[0-7].16b}}
168 ; CHECK-NEXT: aesimc [[VA]], [[VA]]
169 ; CHECK: aesd [[VB:v[0-7].16b]], {{v[0-7].16b}}
170 ; CHECK-NEXT: aesimc [[VB]], [[VB]]
171 ; CHECK: aesd [[VC:v[0-7].16b]], {{v[0-7].16b}}
172 ; CHECK-NEXT: aesimc [[VC]], [[VC]]
173 ; CHECK: aesd [[VD:v[0-7].16b]], {{v[0-7].16b}}
174 ; CHECK-NEXT: aesimc [[VD]], [[VD]]
175 ; CHECK: aesd [[VE:v[0-7].16b]], {{v[0-7].16b}}
176 ; CHECK-NEXT: aesimc [[VE]], [[VE]]
177 ; CHECK: aesd [[VF:v[0-7].16b]], {{v[0-7].16b}}
178 ; CHECK-NEXT: aesimc [[VF]], [[VF]]
179 ; CHECK: aesd [[VG:v[0-7].16b]], {{v[0-7].16b}}
180 ; CHECK-NEXT: aesimc [[VG]], [[VG]]
181 ; CHECK: aesd [[VH:v[0-7].16b]], {{v[0-7].16b}}
182 ; CHECK-NEXT: aesimc [[VH]], [[VH]]
186 define void @aes_load_store(<16 x i8> *%p1, <16 x i8> *%p2 , <16 x i8> *%p3) {
188 %x1 = alloca <16 x i8>, align 16
189 %x2 = alloca <16 x i8>, align 16
190 %x3 = alloca <16 x i8>, align 16
191 %x4 = alloca <16 x i8>, align 16
192 %x5 = alloca <16 x i8>, align 16
193 %in1 = load <16 x i8>, <16 x i8>* %p1, align 16
194 store <16 x i8> %in1, <16 x i8>* %x1, align 16
195 %aese1 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %in1, <16 x i8> %in1) #2
196 %in2 = load <16 x i8>, <16 x i8>* %p2, align 16
197 %aesmc1= call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %aese1) #2
198 %aese2 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %in1, <16 x i8> %in2) #2
199 store <16 x i8> %aesmc1, <16 x i8>* %x3, align 16
200 %in3 = load <16 x i8>, <16 x i8>* %p3, align 16
201 %aesmc2= call <16 x i8> @llvm.aarch64.crypto.aesmc(<16 x i8> %aese2) #2
202 %aese3 = call <16 x i8> @llvm.aarch64.crypto.aese(<16 x i8> %aesmc2, <16 x i8> %in3) #2
203 store <16 x i8> %aese3, <16 x i8>* %x5, align 16
206 ; CHECK-LABEL: aes_load_store:
207 ; CHECK: aese [[VA:v[0-7].16b]], {{v[0-7].16b}}
208 ; aese and aesmc are described to share a unit, hence won't be scheduled on the
209 ; same cycle and the scheduler can find another instruction to place inbetween
210 ; CHECK: aesmc [[VA]], [[VA]]
211 ; CHECK: aese [[VB:v[0-7].16b]], {{v[0-7].16b}}
212 ; CHECK-NEXT: aesmc [[VB]], [[VB]]