1 //===- X86InstrVecCompiler.td - Vector Compiler Patterns ---*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the various vector pseudo instructions used by the
11 // compiler, as well as Pat patterns used during instruction selection.
13 //===----------------------------------------------------------------------===//
15 //===----------------------------------------------------------------------===//
17 //===----------------------------------------------------------------------===//
19 // Bitcasts between 128-bit vector types. Return the original type since
20 // no instruction is needed for the conversion
21 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
22 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
23 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
24 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
25 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
26 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
27 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
28 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
29 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
30 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
31 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
32 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
33 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
34 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
35 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
36 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
37 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
38 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
39 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
40 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
41 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
42 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
43 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
44 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
45 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
46 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
47 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
48 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
49 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
50 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
51 def : Pat<(f128 (bitconvert (i128 FR128:$src))), (f128 FR128:$src)>;
52 def : Pat<(i128 (bitconvert (f128 FR128:$src))), (i128 FR128:$src)>;
54 // Bitcasts between 256-bit vector types. Return the original type since
55 // no instruction is needed for the conversion
56 def : Pat<(v4i64 (bitconvert (v8i32 VR256:$src))), (v4i64 VR256:$src)>;
57 def : Pat<(v4i64 (bitconvert (v16i16 VR256:$src))), (v4i64 VR256:$src)>;
58 def : Pat<(v4i64 (bitconvert (v32i8 VR256:$src))), (v4i64 VR256:$src)>;
59 def : Pat<(v4i64 (bitconvert (v8f32 VR256:$src))), (v4i64 VR256:$src)>;
60 def : Pat<(v4i64 (bitconvert (v4f64 VR256:$src))), (v4i64 VR256:$src)>;
61 def : Pat<(v8i32 (bitconvert (v4i64 VR256:$src))), (v8i32 VR256:$src)>;
62 def : Pat<(v8i32 (bitconvert (v16i16 VR256:$src))), (v8i32 VR256:$src)>;
63 def : Pat<(v8i32 (bitconvert (v32i8 VR256:$src))), (v8i32 VR256:$src)>;
64 def : Pat<(v8i32 (bitconvert (v4f64 VR256:$src))), (v8i32 VR256:$src)>;
65 def : Pat<(v8i32 (bitconvert (v8f32 VR256:$src))), (v8i32 VR256:$src)>;
66 def : Pat<(v16i16 (bitconvert (v4i64 VR256:$src))), (v16i16 VR256:$src)>;
67 def : Pat<(v16i16 (bitconvert (v8i32 VR256:$src))), (v16i16 VR256:$src)>;
68 def : Pat<(v16i16 (bitconvert (v32i8 VR256:$src))), (v16i16 VR256:$src)>;
69 def : Pat<(v16i16 (bitconvert (v4f64 VR256:$src))), (v16i16 VR256:$src)>;
70 def : Pat<(v16i16 (bitconvert (v8f32 VR256:$src))), (v16i16 VR256:$src)>;
71 def : Pat<(v32i8 (bitconvert (v4i64 VR256:$src))), (v32i8 VR256:$src)>;
72 def : Pat<(v32i8 (bitconvert (v8i32 VR256:$src))), (v32i8 VR256:$src)>;
73 def : Pat<(v32i8 (bitconvert (v16i16 VR256:$src))), (v32i8 VR256:$src)>;
74 def : Pat<(v32i8 (bitconvert (v4f64 VR256:$src))), (v32i8 VR256:$src)>;
75 def : Pat<(v32i8 (bitconvert (v8f32 VR256:$src))), (v32i8 VR256:$src)>;
76 def : Pat<(v8f32 (bitconvert (v4i64 VR256:$src))), (v8f32 VR256:$src)>;
77 def : Pat<(v8f32 (bitconvert (v8i32 VR256:$src))), (v8f32 VR256:$src)>;
78 def : Pat<(v8f32 (bitconvert (v16i16 VR256:$src))), (v8f32 VR256:$src)>;
79 def : Pat<(v8f32 (bitconvert (v32i8 VR256:$src))), (v8f32 VR256:$src)>;
80 def : Pat<(v8f32 (bitconvert (v4f64 VR256:$src))), (v8f32 VR256:$src)>;
81 def : Pat<(v4f64 (bitconvert (v4i64 VR256:$src))), (v4f64 VR256:$src)>;
82 def : Pat<(v4f64 (bitconvert (v8i32 VR256:$src))), (v4f64 VR256:$src)>;
83 def : Pat<(v4f64 (bitconvert (v16i16 VR256:$src))), (v4f64 VR256:$src)>;
84 def : Pat<(v4f64 (bitconvert (v32i8 VR256:$src))), (v4f64 VR256:$src)>;
85 def : Pat<(v4f64 (bitconvert (v8f32 VR256:$src))), (v4f64 VR256:$src)>;
87 // Bitcasts between 512-bit vector types. Return the original type since
88 // no instruction is needed for the conversion.
89 def : Pat<(v8f64 (bitconvert (v8i64 VR512:$src))), (v8f64 VR512:$src)>;
90 def : Pat<(v8f64 (bitconvert (v16i32 VR512:$src))), (v8f64 VR512:$src)>;
91 def : Pat<(v8f64 (bitconvert (v32i16 VR512:$src))), (v8f64 VR512:$src)>;
92 def : Pat<(v8f64 (bitconvert (v64i8 VR512:$src))), (v8f64 VR512:$src)>;
93 def : Pat<(v8f64 (bitconvert (v16f32 VR512:$src))), (v8f64 VR512:$src)>;
94 def : Pat<(v16f32 (bitconvert (v8i64 VR512:$src))), (v16f32 VR512:$src)>;
95 def : Pat<(v16f32 (bitconvert (v16i32 VR512:$src))), (v16f32 VR512:$src)>;
96 def : Pat<(v16f32 (bitconvert (v32i16 VR512:$src))), (v16f32 VR512:$src)>;
97 def : Pat<(v16f32 (bitconvert (v64i8 VR512:$src))), (v16f32 VR512:$src)>;
98 def : Pat<(v16f32 (bitconvert (v8f64 VR512:$src))), (v16f32 VR512:$src)>;
99 def : Pat<(v8i64 (bitconvert (v16i32 VR512:$src))), (v8i64 VR512:$src)>;
100 def : Pat<(v8i64 (bitconvert (v32i16 VR512:$src))), (v8i64 VR512:$src)>;
101 def : Pat<(v8i64 (bitconvert (v64i8 VR512:$src))), (v8i64 VR512:$src)>;
102 def : Pat<(v8i64 (bitconvert (v8f64 VR512:$src))), (v8i64 VR512:$src)>;
103 def : Pat<(v8i64 (bitconvert (v16f32 VR512:$src))), (v8i64 VR512:$src)>;
104 def : Pat<(v16i32 (bitconvert (v8i64 VR512:$src))), (v16i32 VR512:$src)>;
105 def : Pat<(v16i32 (bitconvert (v16f32 VR512:$src))), (v16i32 VR512:$src)>;
106 def : Pat<(v16i32 (bitconvert (v32i16 VR512:$src))), (v16i32 VR512:$src)>;
107 def : Pat<(v16i32 (bitconvert (v64i8 VR512:$src))), (v16i32 VR512:$src)>;
108 def : Pat<(v16i32 (bitconvert (v8f64 VR512:$src))), (v16i32 VR512:$src)>;
109 def : Pat<(v32i16 (bitconvert (v8i64 VR512:$src))), (v32i16 VR512:$src)>;
110 def : Pat<(v32i16 (bitconvert (v16i32 VR512:$src))), (v32i16 VR512:$src)>;
111 def : Pat<(v32i16 (bitconvert (v64i8 VR512:$src))), (v32i16 VR512:$src)>;
112 def : Pat<(v32i16 (bitconvert (v8f64 VR512:$src))), (v32i16 VR512:$src)>;
113 def : Pat<(v32i16 (bitconvert (v16f32 VR512:$src))), (v32i16 VR512:$src)>;
114 def : Pat<(v32i16 (bitconvert (v16f32 VR512:$src))), (v32i16 VR512:$src)>;
115 def : Pat<(v64i8 (bitconvert (v8i64 VR512:$src))), (v64i8 VR512:$src)>;
116 def : Pat<(v64i8 (bitconvert (v16i32 VR512:$src))), (v64i8 VR512:$src)>;
117 def : Pat<(v64i8 (bitconvert (v32i16 VR512:$src))), (v64i8 VR512:$src)>;
118 def : Pat<(v64i8 (bitconvert (v8f64 VR512:$src))), (v64i8 VR512:$src)>;
119 def : Pat<(v64i8 (bitconvert (v16f32 VR512:$src))), (v64i8 VR512:$src)>;
122 //===----------------------------------------------------------------------===//
123 // Non-instruction patterns
124 //===----------------------------------------------------------------------===//
126 // A vector extract of the first f32/f64 position is a subregister copy
127 def : Pat<(f32 (extractelt (v4f32 VR128:$src), (iPTR 0))),
128 (COPY_TO_REGCLASS (v4f32 VR128:$src), FR32)>;
129 def : Pat<(f64 (extractelt (v2f64 VR128:$src), (iPTR 0))),
130 (COPY_TO_REGCLASS (v2f64 VR128:$src), FR64)>;
132 // Implicitly promote a 32-bit scalar to a vector.
133 def : Pat<(v4f32 (scalar_to_vector FR32:$src)),
134 (COPY_TO_REGCLASS FR32:$src, VR128)>;
135 // Implicitly promote a 64-bit scalar to a vector.
136 def : Pat<(v2f64 (scalar_to_vector FR64:$src)),
137 (COPY_TO_REGCLASS FR64:$src, VR128)>;
140 //===----------------------------------------------------------------------===//
142 //===----------------------------------------------------------------------===//
144 // Patterns for insert_subvector/extract_subvector to/from index=0
145 multiclass subvector_subreg_lowering<RegisterClass subRC, ValueType subVT,
146 RegisterClass RC, ValueType VT,
147 SubRegIndex subIdx> {
148 def : Pat<(subVT (extract_subvector (VT RC:$src), (iPTR 0))),
149 (subVT (EXTRACT_SUBREG RC:$src, subIdx))>;
151 let AddedComplexity = 25 in // to give priority over vinsertf128rm
152 def : Pat<(VT (insert_subvector undef, subRC:$src, (iPTR 0))),
153 (VT (INSERT_SUBREG (IMPLICIT_DEF), subRC:$src, subIdx))>;
156 // A 128-bit subvector extract from the first 256-bit vector position is a
157 // subregister copy that needs no instruction. Likewise, a 128-bit subvector
158 // insert to the first 256-bit vector position is a subregister copy that needs
160 defm : subvector_subreg_lowering<VR128, v4i32, VR256, v8i32, sub_xmm>;
161 defm : subvector_subreg_lowering<VR128, v4f32, VR256, v8f32, sub_xmm>;
162 defm : subvector_subreg_lowering<VR128, v2i64, VR256, v4i64, sub_xmm>;
163 defm : subvector_subreg_lowering<VR128, v2f64, VR256, v4f64, sub_xmm>;
164 defm : subvector_subreg_lowering<VR128, v8i16, VR256, v16i16, sub_xmm>;
165 defm : subvector_subreg_lowering<VR128, v16i8, VR256, v32i8, sub_xmm>;
167 // A 128-bit subvector extract from the first 512-bit vector position is a
168 // subregister copy that needs no instruction. Likewise, a 128-bit subvector
169 // insert to the first 512-bit vector position is a subregister copy that needs
171 defm : subvector_subreg_lowering<VR128, v4i32, VR512, v16i32, sub_xmm>;
172 defm : subvector_subreg_lowering<VR128, v4f32, VR512, v16f32, sub_xmm>;
173 defm : subvector_subreg_lowering<VR128, v2i64, VR512, v8i64, sub_xmm>;
174 defm : subvector_subreg_lowering<VR128, v2f64, VR512, v8f64, sub_xmm>;
175 defm : subvector_subreg_lowering<VR128, v8i16, VR512, v32i16, sub_xmm>;
176 defm : subvector_subreg_lowering<VR128, v16i8, VR512, v64i8, sub_xmm>;
178 // A 128-bit subvector extract from the first 512-bit vector position is a
179 // subregister copy that needs no instruction. Likewise, a 128-bit subvector
180 // insert to the first 512-bit vector position is a subregister copy that needs
182 defm : subvector_subreg_lowering<VR256, v8i32, VR512, v16i32, sub_ymm>;
183 defm : subvector_subreg_lowering<VR256, v8f32, VR512, v16f32, sub_ymm>;
184 defm : subvector_subreg_lowering<VR256, v4i64, VR512, v8i64, sub_ymm>;
185 defm : subvector_subreg_lowering<VR256, v4f64, VR512, v8f64, sub_ymm>;
186 defm : subvector_subreg_lowering<VR256, v16i16, VR512, v32i16, sub_ymm>;
187 defm : subvector_subreg_lowering<VR256, v32i8, VR512, v64i8, sub_ymm>;
190 multiclass subvector_store_lowering<string AlignedStr, string UnalignedStr,
191 RegisterClass RC, ValueType DstTy,
192 ValueType SrcTy, SubRegIndex SubIdx> {
193 def : Pat<(alignedstore (DstTy (extract_subvector
194 (SrcTy RC:$src), (iPTR 0))), addr:$dst),
195 (!cast<Instruction>("VMOV"#AlignedStr#"mr") addr:$dst,
196 (DstTy (EXTRACT_SUBREG RC:$src, SubIdx)))>;
198 def : Pat<(store (DstTy (extract_subvector
199 (SrcTy RC:$src), (iPTR 0))), addr:$dst),
200 (!cast<Instruction>("VMOV"#UnalignedStr#"mr") addr:$dst,
201 (DstTy (EXTRACT_SUBREG RC:$src, SubIdx)))>;
204 let Predicates = [HasAVX, NoVLX] in {
205 defm : subvector_store_lowering<"APD", "UPD", VR256X, v2f64, v4f64, sub_xmm>;
206 defm : subvector_store_lowering<"APS", "UPS", VR256X, v4f32, v8f32, sub_xmm>;
207 defm : subvector_store_lowering<"DQA", "DQU", VR256X, v2i64, v4i64, sub_xmm>;
208 defm : subvector_store_lowering<"DQA", "DQU", VR256X, v4i32, v8i32, sub_xmm>;
209 defm : subvector_store_lowering<"DQA", "DQU", VR256X, v8i16, v16i16, sub_xmm>;
210 defm : subvector_store_lowering<"DQA", "DQU", VR256X, v16i8, v32i8, sub_xmm>;
213 let Predicates = [HasVLX] in {
214 // Special patterns for storing subvector extracts of lower 128-bits
215 // Its cheaper to just use VMOVAPS/VMOVUPS instead of VEXTRACTF128mr
216 defm : subvector_store_lowering<"APDZ128", "UPDZ128", VR256X, v2f64, v4f64,
218 defm : subvector_store_lowering<"APSZ128", "UPSZ128", VR256X, v4f32, v8f32,
220 defm : subvector_store_lowering<"DQA32Z128", "DQU32Z128", VR256X, v2i64,
222 defm : subvector_store_lowering<"DQA32Z128", "DQU32Z128", VR256X, v4i32,
224 defm : subvector_store_lowering<"DQA32Z128", "DQU32Z128", VR256X, v8i16,
226 defm : subvector_store_lowering<"DQA32Z128", "DQU32Z128", VR256X, v16i8,
229 // Special patterns for storing subvector extracts of lower 128-bits of 512.
230 // Its cheaper to just use VMOVAPS/VMOVUPS instead of VEXTRACTF128mr
231 defm : subvector_store_lowering<"APDZ128", "UPDZ128", VR512, v2f64, v8f64,
233 defm : subvector_store_lowering<"APSZ128", "UPSZ128", VR512, v4f32, v16f32,
235 defm : subvector_store_lowering<"DQA32Z128", "DQU32Z128", VR512, v2i64,
237 defm : subvector_store_lowering<"DQA32Z128", "DQU32Z128", VR512, v4i32,
239 defm : subvector_store_lowering<"DQA32Z128", "DQU32Z128", VR512, v8i16,
241 defm : subvector_store_lowering<"DQA32Z128", "DQU32Z128", VR512, v16i8,
244 // Special patterns for storing subvector extracts of lower 256-bits of 512.
245 // Its cheaper to just use VMOVAPS/VMOVUPS instead of VEXTRACTF128mr
246 defm : subvector_store_lowering<"APDZ256", "UPDZ256", VR512, v4f64, v8f64,
248 defm : subvector_store_lowering<"APSZ256", "UPSZ256", VR512, v8f32, v16f32,
250 defm : subvector_store_lowering<"DQA32Z256", "DQU32Z256", VR512, v4i64,
252 defm : subvector_store_lowering<"DQA32Z256", "DQU32Z256", VR512, v8i32,
254 defm : subvector_store_lowering<"DQA32Z256", "DQU32Z256", VR512, v16i16,
256 defm : subvector_store_lowering<"DQA32Z256", "DQU32Z256", VR512, v32i8,
260 // If we're inserting into an all zeros vector, just use a plain move which
261 // will zero the upper bits.
262 // TODO: Is there a safe way to detect whether the producing instruction
263 // already zeroed the upper bits?
264 multiclass subvector_zero_lowering<string MoveStr, RegisterClass RC,
265 ValueType DstTy, ValueType SrcTy,
266 ValueType ZeroTy, PatFrag memop,
267 SubRegIndex SubIdx> {
268 def : Pat<(DstTy (insert_subvector (bitconvert (ZeroTy immAllZerosV)),
269 (SrcTy RC:$src), (iPTR 0))),
270 (SUBREG_TO_REG (i64 0),
271 (!cast<Instruction>("VMOV"#MoveStr#"rr") RC:$src), SubIdx)>;
273 def : Pat<(DstTy (insert_subvector (bitconvert (ZeroTy immAllZerosV)),
274 (SrcTy (bitconvert (memop addr:$src))),
276 (SUBREG_TO_REG (i64 0),
277 (!cast<Instruction>("VMOV"#MoveStr#"rm") addr:$src), SubIdx)>;
280 let Predicates = [HasAVX, NoVLX] in {
281 defm : subvector_zero_lowering<"APD", VR128, v4f64, v2f64, v8i32, loadv2f64,
283 defm : subvector_zero_lowering<"APS", VR128, v8f32, v4f32, v8i32, loadv4f32,
285 defm : subvector_zero_lowering<"DQA", VR128, v4i64, v2i64, v8i32, loadv2i64,
287 defm : subvector_zero_lowering<"DQA", VR128, v8i32, v4i32, v8i32, loadv2i64,
289 defm : subvector_zero_lowering<"DQA", VR128, v16i16, v8i16, v8i32, loadv2i64,
291 defm : subvector_zero_lowering<"DQA", VR128, v32i8, v16i8, v8i32, loadv2i64,
295 let Predicates = [HasVLX] in {
296 defm : subvector_zero_lowering<"APDZ128", VR128X, v4f64, v2f64, v8i32,
298 defm : subvector_zero_lowering<"APSZ128", VR128X, v8f32, v4f32, v8i32,
300 defm : subvector_zero_lowering<"DQA64Z128", VR128X, v4i64, v2i64, v8i32,
302 defm : subvector_zero_lowering<"DQA64Z128", VR128X, v8i32, v4i32, v8i32,
304 defm : subvector_zero_lowering<"DQA64Z128", VR128X, v16i16, v8i16, v8i32,
306 defm : subvector_zero_lowering<"DQA64Z128", VR128X, v32i8, v16i8, v8i32,
309 defm : subvector_zero_lowering<"APDZ128", VR128X, v8f64, v2f64, v16i32,
311 defm : subvector_zero_lowering<"APSZ128", VR128X, v16f32, v4f32, v16i32,
313 defm : subvector_zero_lowering<"DQA64Z128", VR128X, v8i64, v2i64, v16i32,
315 defm : subvector_zero_lowering<"DQA64Z128", VR128X, v16i32, v4i32, v16i32,
317 defm : subvector_zero_lowering<"DQA64Z128", VR128X, v32i16, v8i16, v16i32,
319 defm : subvector_zero_lowering<"DQA64Z128", VR128X, v64i8, v16i8, v16i32,
322 defm : subvector_zero_lowering<"APDZ256", VR256X, v8f64, v4f64, v16i32,
324 defm : subvector_zero_lowering<"APSZ256", VR256X, v16f32, v8f32, v16i32,
326 defm : subvector_zero_lowering<"DQA64Z256", VR256X, v8i64, v4i64, v16i32,
328 defm : subvector_zero_lowering<"DQA64Z256", VR256X, v16i32, v8i32, v16i32,
330 defm : subvector_zero_lowering<"DQA64Z256", VR256X, v32i16, v16i16, v16i32,
332 defm : subvector_zero_lowering<"DQA64Z256", VR256X, v64i8, v32i8, v16i32,
336 let Predicates = [HasAVX512, NoVLX] in {
337 defm : subvector_zero_lowering<"APD", VR128, v8f64, v2f64, v16i32, loadv2f64,
339 defm : subvector_zero_lowering<"APS", VR128, v16f32, v4f32, v16i32, loadv4f32,
341 defm : subvector_zero_lowering<"DQA", VR128, v8i64, v2i64, v16i32, loadv2i64,
343 defm : subvector_zero_lowering<"DQA", VR128, v16i32, v4i32, v16i32, loadv2i64,
345 defm : subvector_zero_lowering<"DQA", VR128, v32i16, v8i16, v16i32, loadv2i64,
347 defm : subvector_zero_lowering<"DQA", VR128, v64i8, v16i8, v16i32, loadv2i64,
350 defm : subvector_zero_lowering<"APDY", VR256, v8f64, v4f64, v16i32,
352 defm : subvector_zero_lowering<"APSY", VR256, v16f32, v8f32, v16i32,
354 defm : subvector_zero_lowering<"DQAY", VR256, v8i64, v4i64, v16i32,
356 defm : subvector_zero_lowering<"DQAY", VR256, v16i32, v8i32, v16i32,
358 defm : subvector_zero_lowering<"DQAY", VR256, v32i16, v16i16, v16i32,
360 defm : subvector_zero_lowering<"DQAY", VR256, v64i8, v32i8, v16i32,
364 // List of opcodes that guaranteed to zero the upper elements of vector regs.
365 // TODO: Ideally this would be a blacklist instead of a whitelist. But SHA
366 // intrinsics and some MMX->XMM move instructions that aren't VEX encoded make
367 // this difficult. So starting with a couple opcodes used by reduction loops
368 // where we explicitly insert zeros.
369 class veczeroupper<ValueType vt, RegisterClass RC> :
370 PatLeaf<(vt RC:$src), [{
371 return N->getOpcode() == X86ISD::VPMADDWD ||
372 N->getOpcode() == X86ISD::PSADBW;
375 def zeroupperv2f64 : veczeroupper<v2f64, VR128>;
376 def zeroupperv4f32 : veczeroupper<v4f32, VR128>;
377 def zeroupperv2i64 : veczeroupper<v2i64, VR128>;
378 def zeroupperv4i32 : veczeroupper<v4i32, VR128>;
379 def zeroupperv8i16 : veczeroupper<v8i16, VR128>;
380 def zeroupperv16i8 : veczeroupper<v16i8, VR128>;
382 def zeroupperv4f64 : veczeroupper<v4f64, VR256>;
383 def zeroupperv8f32 : veczeroupper<v8f32, VR256>;
384 def zeroupperv4i64 : veczeroupper<v4i64, VR256>;
385 def zeroupperv8i32 : veczeroupper<v8i32, VR256>;
386 def zeroupperv16i16 : veczeroupper<v16i16, VR256>;
387 def zeroupperv32i8 : veczeroupper<v32i8, VR256>;
390 // If we can guarantee the upper elements have already been zeroed we can elide
391 // an explicit zeroing.
392 multiclass subvector_zero_ellision<RegisterClass RC, ValueType DstTy,
393 ValueType SrcTy, ValueType ZeroTy,
394 SubRegIndex SubIdx, PatLeaf Zeroupper> {
395 def : Pat<(DstTy (insert_subvector (bitconvert (ZeroTy immAllZerosV)),
396 Zeroupper:$src, (iPTR 0))),
397 (SUBREG_TO_REG (i64 0), RC:$src, SubIdx)>;
401 defm: subvector_zero_ellision<VR128, v4f64, v2f64, v8i32, sub_xmm, zeroupperv2f64>;
402 defm: subvector_zero_ellision<VR128, v8f32, v4f32, v8i32, sub_xmm, zeroupperv4f32>;
403 defm: subvector_zero_ellision<VR128, v4i64, v2i64, v8i32, sub_xmm, zeroupperv2i64>;
404 defm: subvector_zero_ellision<VR128, v8i32, v4i32, v8i32, sub_xmm, zeroupperv4i32>;
405 defm: subvector_zero_ellision<VR128, v16i16, v8i16, v8i32, sub_xmm, zeroupperv8i16>;
406 defm: subvector_zero_ellision<VR128, v32i8, v16i8, v8i32, sub_xmm, zeroupperv16i8>;
409 defm: subvector_zero_ellision<VR128, v8f64, v2f64, v16i32, sub_xmm, zeroupperv2f64>;
410 defm: subvector_zero_ellision<VR128, v16f32, v4f32, v16i32, sub_xmm, zeroupperv4f32>;
411 defm: subvector_zero_ellision<VR128, v8i64, v2i64, v16i32, sub_xmm, zeroupperv2i64>;
412 defm: subvector_zero_ellision<VR128, v16i32, v4i32, v16i32, sub_xmm, zeroupperv4i32>;
413 defm: subvector_zero_ellision<VR128, v32i16, v8i16, v16i32, sub_xmm, zeroupperv8i16>;
414 defm: subvector_zero_ellision<VR128, v64i8, v16i8, v16i32, sub_xmm, zeroupperv16i8>;
417 defm: subvector_zero_ellision<VR256, v8f64, v4f64, v16i32, sub_ymm, zeroupperv4f64>;
418 defm: subvector_zero_ellision<VR256, v16f32, v8f32, v16i32, sub_ymm, zeroupperv8f32>;
419 defm: subvector_zero_ellision<VR256, v8i64, v4i64, v16i32, sub_ymm, zeroupperv4i64>;
420 defm: subvector_zero_ellision<VR256, v16i32, v8i32, v16i32, sub_ymm, zeroupperv8i32>;
421 defm: subvector_zero_ellision<VR256, v32i16, v16i16, v16i32, sub_ymm, zeroupperv16i16>;
422 defm: subvector_zero_ellision<VR256, v64i8, v32i8, v16i32, sub_ymm, zeroupperv32i8>;
425 class maskzeroupper<ValueType vt, RegisterClass RC> :
426 PatLeaf<(vt RC:$src), [{
427 return isMaskZeroExtended(N);
430 def maskzeroupperv2i1 : maskzeroupper<v2i1, VK2>;
431 def maskzeroupperv4i1 : maskzeroupper<v4i1, VK4>;
432 def maskzeroupperv8i1 : maskzeroupper<v8i1, VK8>;
433 def maskzeroupperv16i1 : maskzeroupper<v16i1, VK16>;
434 def maskzeroupperv32i1 : maskzeroupper<v32i1, VK32>;
436 // The patterns determine if we can depend on the upper bits of a mask register
437 // being zeroed by the previous operation so that we can skip explicit
439 let Predicates = [HasBWI] in {
440 def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
441 maskzeroupperv8i1:$src, (iPTR 0))),
442 (COPY_TO_REGCLASS VK8:$src, VK32)>;
443 def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
444 maskzeroupperv16i1:$src, (iPTR 0))),
445 (COPY_TO_REGCLASS VK16:$src, VK32)>;
446 def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
447 maskzeroupperv8i1:$src, (iPTR 0))),
448 (COPY_TO_REGCLASS VK8:$src, VK64)>;
449 def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
450 maskzeroupperv16i1:$src, (iPTR 0))),
451 (COPY_TO_REGCLASS VK16:$src, VK64)>;
452 def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
453 maskzeroupperv32i1:$src, (iPTR 0))),
454 (COPY_TO_REGCLASS VK32:$src, VK64)>;
457 let Predicates = [HasAVX512] in {
458 def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
459 maskzeroupperv8i1:$src, (iPTR 0))),
460 (COPY_TO_REGCLASS VK8:$src, VK16)>;
463 let Predicates = [HasVLX, HasDQI] in {
464 def : Pat<(v8i1 (insert_subvector (v8i1 immAllZerosV),
465 maskzeroupperv2i1:$src, (iPTR 0))),
466 (COPY_TO_REGCLASS VK2:$src, VK8)>;
467 def : Pat<(v8i1 (insert_subvector (v8i1 immAllZerosV),
468 maskzeroupperv4i1:$src, (iPTR 0))),
469 (COPY_TO_REGCLASS VK4:$src, VK8)>;
472 let Predicates = [HasVLX] in {
473 def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
474 maskzeroupperv2i1:$src, (iPTR 0))),
475 (COPY_TO_REGCLASS VK2:$src, VK16)>;
476 def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
477 maskzeroupperv4i1:$src, (iPTR 0))),
478 (COPY_TO_REGCLASS VK4:$src, VK16)>;
481 let Predicates = [HasBWI, HasVLX] in {
482 def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
483 maskzeroupperv2i1:$src, (iPTR 0))),
484 (COPY_TO_REGCLASS VK2:$src, VK32)>;
485 def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
486 maskzeroupperv4i1:$src, (iPTR 0))),
487 (COPY_TO_REGCLASS VK4:$src, VK32)>;
488 def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
489 maskzeroupperv2i1:$src, (iPTR 0))),
490 (COPY_TO_REGCLASS VK2:$src, VK64)>;
491 def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
492 maskzeroupperv4i1:$src, (iPTR 0))),
493 (COPY_TO_REGCLASS VK4:$src, VK64)>;
496 // If the bits are not zero we have to fall back to explicitly zeroing by
498 let Predicates = [HasAVX512, NoDQI] in {
499 def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
500 (v8i1 VK8:$mask), (iPTR 0))),
501 (KSHIFTRWri (KSHIFTLWri (COPY_TO_REGCLASS VK8:$mask, VK16),
505 let Predicates = [HasDQI] in {
506 def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
507 (v8i1 VK8:$mask), (iPTR 0))),
508 (COPY_TO_REGCLASS (KMOVBkk VK8:$mask), VK16)>;
511 let Predicates = [HasVLX, HasDQI] in {
512 def : Pat<(v8i1 (insert_subvector (v8i1 immAllZerosV),
513 (v2i1 VK2:$mask), (iPTR 0))),
514 (KSHIFTRBri (KSHIFTLBri (COPY_TO_REGCLASS VK2:$mask, VK8),
516 def : Pat<(v8i1 (insert_subvector (v8i1 immAllZerosV),
517 (v4i1 VK4:$mask), (iPTR 0))),
518 (KSHIFTRBri (KSHIFTLBri (COPY_TO_REGCLASS VK4:$mask, VK8),
522 let Predicates = [HasVLX] in {
523 def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
524 (v2i1 VK2:$mask), (iPTR 0))),
525 (KSHIFTRWri (KSHIFTLWri (COPY_TO_REGCLASS VK2:$mask, VK16),
527 def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
528 (v4i1 VK4:$mask), (iPTR 0))),
529 (KSHIFTRWri (KSHIFTLWri (COPY_TO_REGCLASS VK4:$mask, VK16),
533 let Predicates = [HasBWI] in {
534 def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
535 (v16i1 VK16:$mask), (iPTR 0))),
536 (COPY_TO_REGCLASS (KMOVWkk VK16:$mask), VK32)>;
538 def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
539 (v16i1 VK16:$mask), (iPTR 0))),
540 (COPY_TO_REGCLASS (KMOVWkk VK16:$mask), VK64)>;
541 def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
542 (v32i1 VK32:$mask), (iPTR 0))),
543 (COPY_TO_REGCLASS (KMOVDkk VK32:$mask), VK64)>;
546 let Predicates = [HasBWI, NoDQI] in {
547 def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
548 (v8i1 VK8:$mask), (iPTR 0))),
549 (KSHIFTRDri (KSHIFTLDri (COPY_TO_REGCLASS VK8:$mask, VK32),
552 def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
553 (v8i1 VK8:$mask), (iPTR 0))),
554 (KSHIFTRQri (KSHIFTLQri (COPY_TO_REGCLASS VK8:$mask, VK64),
558 let Predicates = [HasBWI, HasDQI] in {
559 def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
560 (v8i1 VK8:$mask), (iPTR 0))),
561 (COPY_TO_REGCLASS (KMOVBkk VK8:$mask), VK32)>;
563 def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
564 (v8i1 VK8:$mask), (iPTR 0))),
565 (COPY_TO_REGCLASS (KMOVBkk VK8:$mask), VK64)>;
568 let Predicates = [HasBWI, HasVLX] in {
569 def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
570 (v2i1 VK2:$mask), (iPTR 0))),
571 (KSHIFTRDri (KSHIFTLDri (COPY_TO_REGCLASS VK2:$mask, VK32),
573 def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
574 (v4i1 VK4:$mask), (iPTR 0))),
575 (KSHIFTRDri (KSHIFTLDri (COPY_TO_REGCLASS VK4:$mask, VK32),
578 def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
579 (v2i1 VK2:$mask), (iPTR 0))),
580 (KSHIFTRQri (KSHIFTLQri (COPY_TO_REGCLASS VK2:$mask, VK64),
582 def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
583 (v4i1 VK4:$mask), (iPTR 0))),
584 (KSHIFTRQri (KSHIFTLQri (COPY_TO_REGCLASS VK4:$mask, VK64),