blob: 4108a58fa7a508279b28de76c2bec7841d77c063 [file] [log] [blame]
Igor Bregerb4442f32017-02-10 07:05:56 +00001//===- X86LegalizerInfo.cpp --------------------------------------*- C++ -*-==//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9/// \file
10/// This file implements the targeting of the Machinelegalizer class for X86.
11/// \todo This should be generated by TableGen.
12//===----------------------------------------------------------------------===//
13
14#include "X86LegalizerInfo.h"
15#include "X86Subtarget.h"
Igor Breger531a2032017-03-26 08:11:12 +000016#include "X86TargetMachine.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000017#include "llvm/CodeGen/TargetOpcodes.h"
Igor Bregerb4442f32017-02-10 07:05:56 +000018#include "llvm/CodeGen/ValueTypes.h"
19#include "llvm/IR/DerivedTypes.h"
20#include "llvm/IR/Type.h"
Igor Bregerb4442f32017-02-10 07:05:56 +000021
22using namespace llvm;
Igor Breger321cf3c2017-03-03 08:06:46 +000023using namespace TargetOpcode;
Igor Bregerb4442f32017-02-10 07:05:56 +000024
Kristof Beylsaf9814a2017-11-07 10:34:34 +000025/// FIXME: The following static functions are SizeChangeStrategy functions
26/// that are meant to temporarily mimic the behaviour of the old legalization
27/// based on doubling/halving non-legal types as closely as possible. This is
28/// not entirly possible as only legalizing the types that are exactly a power
29/// of 2 times the size of the legal types would require specifying all those
30/// sizes explicitly.
31/// In practice, not specifying those isn't a problem, and the below functions
32/// should disappear quickly as we add support for legalizing non-power-of-2
33/// sized types further.
34static void
35addAndInterleaveWithUnsupported(LegalizerInfo::SizeAndActionsVec &result,
36 const LegalizerInfo::SizeAndActionsVec &v) {
37 for (unsigned i = 0; i < v.size(); ++i) {
38 result.push_back(v[i]);
39 if (i + 1 < v[i].first && i + 1 < v.size() &&
40 v[i + 1].first != v[i].first + 1)
41 result.push_back({v[i].first + 1, LegalizerInfo::Unsupported});
42 }
43}
44
45static LegalizerInfo::SizeAndActionsVec
46widen_1(const LegalizerInfo::SizeAndActionsVec &v) {
47 assert(v.size() >= 1);
48 assert(v[0].first > 1);
49 LegalizerInfo::SizeAndActionsVec result = {{1, LegalizerInfo::WidenScalar},
50 {2, LegalizerInfo::Unsupported}};
51 addAndInterleaveWithUnsupported(result, v);
52 auto Largest = result.back().first;
53 result.push_back({Largest + 1, LegalizerInfo::Unsupported});
54 return result;
55}
56
Igor Breger531a2032017-03-26 08:11:12 +000057X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
58 const X86TargetMachine &TM)
59 : Subtarget(STI), TM(TM) {
Igor Bregerb4442f32017-02-10 07:05:56 +000060
61 setLegalizerInfo32bit();
62 setLegalizerInfo64bit();
Igor Breger321cf3c2017-03-03 08:06:46 +000063 setLegalizerInfoSSE1();
64 setLegalizerInfoSSE2();
Igor Breger605b9652017-05-08 09:03:37 +000065 setLegalizerInfoSSE41();
Igor Breger617be6e2017-05-23 08:23:51 +000066 setLegalizerInfoAVX();
Igor Breger605b9652017-05-08 09:03:37 +000067 setLegalizerInfoAVX2();
68 setLegalizerInfoAVX512();
69 setLegalizerInfoAVX512DQ();
70 setLegalizerInfoAVX512BW();
Igor Bregerb4442f32017-02-10 07:05:56 +000071
Kristof Beylsaf9814a2017-11-07 10:34:34 +000072 setLegalizeScalarToDifferentSizeStrategy(G_PHI, 0, widen_1);
73 for (unsigned BinOp : {G_SUB, G_MUL, G_AND, G_OR, G_XOR})
74 setLegalizeScalarToDifferentSizeStrategy(BinOp, 0, widen_1);
75 for (unsigned MemOp : {G_LOAD, G_STORE})
76 setLegalizeScalarToDifferentSizeStrategy(MemOp, 0,
77 narrowToSmallerAndWidenToSmallest);
78 setLegalizeScalarToDifferentSizeStrategy(
79 G_GEP, 1, widenToLargerTypesUnsupportedOtherwise);
80 setLegalizeScalarToDifferentSizeStrategy(
81 G_CONSTANT, 0, widenToLargerTypesAndNarrowToLargest);
82
Igor Bregerb4442f32017-02-10 07:05:56 +000083 computeTables();
84}
85
86void X86LegalizerInfo::setLegalizerInfo32bit() {
87
Igor Breger42f8bfc2017-08-31 11:40:03 +000088 const LLT p0 = LLT::pointer(0, TM.getPointerSize() * 8);
Igor Breger29537882017-04-07 14:41:59 +000089 const LLT s1 = LLT::scalar(1);
Igor Bregerb4442f32017-02-10 07:05:56 +000090 const LLT s8 = LLT::scalar(8);
91 const LLT s16 = LLT::scalar(16);
92 const LLT s32 = LLT::scalar(32);
Volkan Kelesa32ff002017-12-01 08:19:10 +000093 const LLT s64 = LLT::scalar(64);
Igor Bregerb4442f32017-02-10 07:05:56 +000094
Igor Breger47be5fb2017-08-24 07:06:27 +000095 for (auto Ty : {p0, s1, s8, s16, s32})
96 setAction({G_IMPLICIT_DEF, Ty}, Legal);
97
Igor Breger2661ae42017-09-04 09:06:45 +000098 for (auto Ty : {s8, s16, s32, p0})
99 setAction({G_PHI, Ty}, Legal);
100
Kristof Beylsaf9814a2017-11-07 10:34:34 +0000101 for (unsigned BinOp : {G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR})
Igor Bregera8ba5722017-03-23 15:25:57 +0000102 for (auto Ty : {s8, s16, s32})
103 setAction({BinOp, Ty}, Legal);
104
Igor Breger28f290f2017-05-17 12:48:08 +0000105 for (unsigned Op : {G_UADDE}) {
106 setAction({Op, s32}, Legal);
107 setAction({Op, 1, s1}, Legal);
108 }
109
Igor Bregera8ba5722017-03-23 15:25:57 +0000110 for (unsigned MemOp : {G_LOAD, G_STORE}) {
111 for (auto Ty : {s8, s16, s32, p0})
112 setAction({MemOp, Ty}, Legal);
113
114 // And everything's fine in addrspace 0.
115 setAction({MemOp, 1, p0}, Legal);
Igor Bregerf7359d82017-02-22 12:25:09 +0000116 }
Igor Breger531a2032017-03-26 08:11:12 +0000117
118 // Pointer-handling
119 setAction({G_FRAME_INDEX, p0}, Legal);
Igor Breger717bd362017-07-02 08:58:29 +0000120 setAction({G_GLOBAL_VALUE, p0}, Legal);
Igor Breger29537882017-04-07 14:41:59 +0000121
Igor Breger810c6252017-05-08 09:40:43 +0000122 setAction({G_GEP, p0}, Legal);
123 setAction({G_GEP, 1, s32}, Legal);
124
Igor Breger685889c2017-08-21 10:51:54 +0000125 // Control-flow
126 setAction({G_BRCOND, s1}, Legal);
127
Igor Breger29537882017-04-07 14:41:59 +0000128 // Constants
129 for (auto Ty : {s8, s16, s32, p0})
130 setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
131
Igor Bregerc08a7832017-05-01 06:30:16 +0000132 // Extensions
Igor Bregerd48c5e42017-07-10 09:07:34 +0000133 for (auto Ty : {s8, s16, s32}) {
134 setAction({G_ZEXT, Ty}, Legal);
135 setAction({G_SEXT, Ty}, Legal);
Igor Breger1f143642017-09-11 09:41:13 +0000136 setAction({G_ANYEXT, Ty}, Legal);
Igor Bregerd48c5e42017-07-10 09:07:34 +0000137 }
Igor Bregerc08a7832017-05-01 06:30:16 +0000138
Igor Bregerc7b59772017-05-11 07:17:40 +0000139 // Comparison
140 setAction({G_ICMP, s1}, Legal);
141
142 for (auto Ty : {s8, s16, s32, p0})
143 setAction({G_ICMP, 1, Ty}, Legal);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000144
145 // Merge/Unmerge
146 for (const auto &Ty : {s16, s32, s64}) {
147 setAction({G_MERGE_VALUES, Ty}, Legal);
148 setAction({G_UNMERGE_VALUES, 1, Ty}, Legal);
149 }
150 for (const auto &Ty : {s8, s16, s32}) {
151 setAction({G_MERGE_VALUES, 1, Ty}, Legal);
152 setAction({G_UNMERGE_VALUES, Ty}, Legal);
153 }
Igor Bregerb4442f32017-02-10 07:05:56 +0000154}
Igor Bregerb4442f32017-02-10 07:05:56 +0000155
Igor Bregerf7359d82017-02-22 12:25:09 +0000156void X86LegalizerInfo::setLegalizerInfo64bit() {
Igor Bregerb4442f32017-02-10 07:05:56 +0000157
158 if (!Subtarget.is64Bit())
159 return;
160
161 const LLT s64 = LLT::scalar(64);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000162 const LLT s128 = LLT::scalar(128);
Igor Bregerb4442f32017-02-10 07:05:56 +0000163
Igor Breger42f8bfc2017-08-31 11:40:03 +0000164 setAction({G_IMPLICIT_DEF, s64}, Legal);
Igor Breger47be5fb2017-08-24 07:06:27 +0000165
Igor Breger2661ae42017-09-04 09:06:45 +0000166 setAction({G_PHI, s64}, Legal);
167
Igor Bregerd5b59cf2017-06-28 11:39:04 +0000168 for (unsigned BinOp : {G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR})
Igor Breger42f8bfc2017-08-31 11:40:03 +0000169 setAction({BinOp, s64}, Legal);
Igor Bregera8ba5722017-03-23 15:25:57 +0000170
Igor Breger1f143642017-09-11 09:41:13 +0000171 for (unsigned MemOp : {G_LOAD, G_STORE})
Igor Breger42f8bfc2017-08-31 11:40:03 +0000172 setAction({MemOp, s64}, Legal);
Igor Breger531a2032017-03-26 08:11:12 +0000173
174 // Pointer-handling
Igor Breger810c6252017-05-08 09:40:43 +0000175 setAction({G_GEP, 1, s64}, Legal);
176
Igor Breger29537882017-04-07 14:41:59 +0000177 // Constants
Igor Breger42f8bfc2017-08-31 11:40:03 +0000178 setAction({TargetOpcode::G_CONSTANT, s64}, Legal);
Igor Bregerc08a7832017-05-01 06:30:16 +0000179
180 // Extensions
Igor Breger1f143642017-09-11 09:41:13 +0000181 for (unsigned extOp : {G_ZEXT, G_SEXT, G_ANYEXT}) {
182 setAction({extOp, s64}, Legal);
Igor Breger1f143642017-09-11 09:41:13 +0000183 }
Igor Bregerc7b59772017-05-11 07:17:40 +0000184
185 // Comparison
Igor Breger42f8bfc2017-08-31 11:40:03 +0000186 setAction({G_ICMP, 1, s64}, Legal);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000187
188 // Merge/Unmerge
189 setAction({G_MERGE_VALUES, s128}, Legal);
190 setAction({G_UNMERGE_VALUES, 1, s128}, Legal);
191 setAction({G_MERGE_VALUES, 1, s128}, Legal);
192 setAction({G_UNMERGE_VALUES, s128}, Legal);
Igor Breger321cf3c2017-03-03 08:06:46 +0000193}
194
195void X86LegalizerInfo::setLegalizerInfoSSE1() {
196 if (!Subtarget.hasSSE1())
197 return;
198
199 const LLT s32 = LLT::scalar(32);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000200 const LLT s64 = LLT::scalar(64);
Igor Breger321cf3c2017-03-03 08:06:46 +0000201 const LLT v4s32 = LLT::vector(4, 32);
Igor Bregera8ba5722017-03-23 15:25:57 +0000202 const LLT v2s64 = LLT::vector(2, 64);
Igor Breger321cf3c2017-03-03 08:06:46 +0000203
204 for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
205 for (auto Ty : {s32, v4s32})
206 setAction({BinOp, Ty}, Legal);
Igor Bregera8ba5722017-03-23 15:25:57 +0000207
208 for (unsigned MemOp : {G_LOAD, G_STORE})
209 for (auto Ty : {v4s32, v2s64})
210 setAction({MemOp, Ty}, Legal);
Igor Breger21200ed2017-09-17 08:08:13 +0000211
212 // Constants
213 setAction({TargetOpcode::G_FCONSTANT, s32}, Legal);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000214
215 // Merge/Unmerge
216 for (const auto &Ty : {v4s32, v2s64}) {
217 setAction({G_MERGE_VALUES, Ty}, Legal);
218 setAction({G_UNMERGE_VALUES, 1, Ty}, Legal);
219 }
220 setAction({G_MERGE_VALUES, 1, s64}, Legal);
221 setAction({G_UNMERGE_VALUES, s64}, Legal);
Igor Breger321cf3c2017-03-03 08:06:46 +0000222}
223
224void X86LegalizerInfo::setLegalizerInfoSSE2() {
225 if (!Subtarget.hasSSE2())
226 return;
227
Igor Breger5c7211992017-09-13 09:05:23 +0000228 const LLT s32 = LLT::scalar(32);
Igor Breger321cf3c2017-03-03 08:06:46 +0000229 const LLT s64 = LLT::scalar(64);
Igor Breger842b5b32017-05-18 11:10:56 +0000230 const LLT v16s8 = LLT::vector(16, 8);
Igor Breger605b9652017-05-08 09:03:37 +0000231 const LLT v8s16 = LLT::vector(8, 16);
Igor Breger321cf3c2017-03-03 08:06:46 +0000232 const LLT v4s32 = LLT::vector(4, 32);
233 const LLT v2s64 = LLT::vector(2, 64);
234
Volkan Kelesa32ff002017-12-01 08:19:10 +0000235 const LLT v32s8 = LLT::vector(32, 8);
236 const LLT v16s16 = LLT::vector(16, 16);
237 const LLT v8s32 = LLT::vector(8, 32);
238 const LLT v4s64 = LLT::vector(4, 64);
239
Igor Breger321cf3c2017-03-03 08:06:46 +0000240 for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
241 for (auto Ty : {s64, v2s64})
242 setAction({BinOp, Ty}, Legal);
243
244 for (unsigned BinOp : {G_ADD, G_SUB})
Igor Breger842b5b32017-05-18 11:10:56 +0000245 for (auto Ty : {v16s8, v8s16, v4s32, v2s64})
Igor Breger321cf3c2017-03-03 08:06:46 +0000246 setAction({BinOp, Ty}, Legal);
Igor Breger605b9652017-05-08 09:03:37 +0000247
248 setAction({G_MUL, v8s16}, Legal);
Igor Breger5c7211992017-09-13 09:05:23 +0000249
250 setAction({G_FPEXT, s64}, Legal);
251 setAction({G_FPEXT, 1, s32}, Legal);
Igor Breger21200ed2017-09-17 08:08:13 +0000252
253 // Constants
254 setAction({TargetOpcode::G_FCONSTANT, s64}, Legal);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000255
256 // Merge/Unmerge
257 for (const auto &Ty :
258 {v16s8, v32s8, v8s16, v16s16, v4s32, v8s32, v2s64, v4s64}) {
259 setAction({G_MERGE_VALUES, Ty}, Legal);
260 setAction({G_UNMERGE_VALUES, 1, Ty}, Legal);
261 }
262 for (const auto &Ty : {v16s8, v8s16, v4s32, v2s64}) {
263 setAction({G_MERGE_VALUES, 1, Ty}, Legal);
264 setAction({G_UNMERGE_VALUES, Ty}, Legal);
265 }
Igor Breger605b9652017-05-08 09:03:37 +0000266}
267
268void X86LegalizerInfo::setLegalizerInfoSSE41() {
269 if (!Subtarget.hasSSE41())
270 return;
271
272 const LLT v4s32 = LLT::vector(4, 32);
273
274 setAction({G_MUL, v4s32}, Legal);
275}
276
Igor Breger617be6e2017-05-23 08:23:51 +0000277void X86LegalizerInfo::setLegalizerInfoAVX() {
278 if (!Subtarget.hasAVX())
279 return;
280
Igor Breger1c29be72017-06-22 09:43:35 +0000281 const LLT v16s8 = LLT::vector(16, 8);
282 const LLT v8s16 = LLT::vector(8, 16);
283 const LLT v4s32 = LLT::vector(4, 32);
284 const LLT v2s64 = LLT::vector(2, 64);
285
286 const LLT v32s8 = LLT::vector(32, 8);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000287 const LLT v64s8 = LLT::vector(64, 8);
Igor Breger1c29be72017-06-22 09:43:35 +0000288 const LLT v16s16 = LLT::vector(16, 16);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000289 const LLT v32s16 = LLT::vector(32, 16);
Igor Breger617be6e2017-05-23 08:23:51 +0000290 const LLT v8s32 = LLT::vector(8, 32);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000291 const LLT v16s32 = LLT::vector(16, 32);
Igor Breger617be6e2017-05-23 08:23:51 +0000292 const LLT v4s64 = LLT::vector(4, 64);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000293 const LLT v8s64 = LLT::vector(8, 64);
Igor Breger617be6e2017-05-23 08:23:51 +0000294
295 for (unsigned MemOp : {G_LOAD, G_STORE})
296 for (auto Ty : {v8s32, v4s64})
297 setAction({MemOp, Ty}, Legal);
Igor Breger1c29be72017-06-22 09:43:35 +0000298
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000299 for (auto Ty : {v32s8, v16s16, v8s32, v4s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000300 setAction({G_INSERT, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000301 setAction({G_EXTRACT, 1, Ty}, Legal);
302 }
303 for (auto Ty : {v16s8, v8s16, v4s32, v2s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000304 setAction({G_INSERT, 1, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000305 setAction({G_EXTRACT, Ty}, Legal);
306 }
Volkan Kelesa32ff002017-12-01 08:19:10 +0000307 // Merge/Unmerge
308 for (const auto &Ty :
309 {v32s8, v64s8, v16s16, v32s16, v8s32, v16s32, v4s64, v8s64}) {
310 setAction({G_MERGE_VALUES, Ty}, Legal);
311 setAction({G_UNMERGE_VALUES, 1, Ty}, Legal);
312 }
313 for (const auto &Ty :
314 {v16s8, v32s8, v8s16, v16s16, v4s32, v8s32, v2s64, v4s64}) {
315 setAction({G_MERGE_VALUES, 1, Ty}, Legal);
316 setAction({G_UNMERGE_VALUES, Ty}, Legal);
317 }
Igor Breger617be6e2017-05-23 08:23:51 +0000318}
319
Igor Breger605b9652017-05-08 09:03:37 +0000320void X86LegalizerInfo::setLegalizerInfoAVX2() {
321 if (!Subtarget.hasAVX2())
322 return;
323
Igor Breger842b5b32017-05-18 11:10:56 +0000324 const LLT v32s8 = LLT::vector(32, 8);
Igor Breger605b9652017-05-08 09:03:37 +0000325 const LLT v16s16 = LLT::vector(16, 16);
326 const LLT v8s32 = LLT::vector(8, 32);
Igor Breger842b5b32017-05-18 11:10:56 +0000327 const LLT v4s64 = LLT::vector(4, 64);
328
Volkan Kelesa32ff002017-12-01 08:19:10 +0000329 const LLT v64s8 = LLT::vector(64, 8);
330 const LLT v32s16 = LLT::vector(32, 16);
331 const LLT v16s32 = LLT::vector(16, 32);
332 const LLT v8s64 = LLT::vector(8, 64);
333
Igor Breger842b5b32017-05-18 11:10:56 +0000334 for (unsigned BinOp : {G_ADD, G_SUB})
335 for (auto Ty : {v32s8, v16s16, v8s32, v4s64})
336 setAction({BinOp, Ty}, Legal);
Igor Breger605b9652017-05-08 09:03:37 +0000337
338 for (auto Ty : {v16s16, v8s32})
339 setAction({G_MUL, Ty}, Legal);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000340
341 // Merge/Unmerge
342 for (const auto &Ty : {v64s8, v32s16, v16s32, v8s64}) {
343 setAction({G_MERGE_VALUES, Ty}, Legal);
344 setAction({G_UNMERGE_VALUES, 1, Ty}, Legal);
345 }
346 for (const auto &Ty : {v32s8, v16s16, v8s32, v4s64}) {
347 setAction({G_MERGE_VALUES, 1, Ty}, Legal);
348 setAction({G_UNMERGE_VALUES, Ty}, Legal);
349 }
Igor Breger605b9652017-05-08 09:03:37 +0000350}
351
352void X86LegalizerInfo::setLegalizerInfoAVX512() {
353 if (!Subtarget.hasAVX512())
354 return;
355
Igor Breger1c29be72017-06-22 09:43:35 +0000356 const LLT v16s8 = LLT::vector(16, 8);
357 const LLT v8s16 = LLT::vector(8, 16);
358 const LLT v4s32 = LLT::vector(4, 32);
359 const LLT v2s64 = LLT::vector(2, 64);
360
361 const LLT v32s8 = LLT::vector(32, 8);
362 const LLT v16s16 = LLT::vector(16, 16);
363 const LLT v8s32 = LLT::vector(8, 32);
364 const LLT v4s64 = LLT::vector(4, 64);
365
366 const LLT v64s8 = LLT::vector(64, 8);
367 const LLT v32s16 = LLT::vector(32, 16);
Igor Breger605b9652017-05-08 09:03:37 +0000368 const LLT v16s32 = LLT::vector(16, 32);
Igor Breger842b5b32017-05-18 11:10:56 +0000369 const LLT v8s64 = LLT::vector(8, 64);
370
371 for (unsigned BinOp : {G_ADD, G_SUB})
372 for (auto Ty : {v16s32, v8s64})
373 setAction({BinOp, Ty}, Legal);
Igor Breger605b9652017-05-08 09:03:37 +0000374
375 setAction({G_MUL, v16s32}, Legal);
376
Igor Breger617be6e2017-05-23 08:23:51 +0000377 for (unsigned MemOp : {G_LOAD, G_STORE})
378 for (auto Ty : {v16s32, v8s64})
379 setAction({MemOp, Ty}, Legal);
380
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000381 for (auto Ty : {v64s8, v32s16, v16s32, v8s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000382 setAction({G_INSERT, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000383 setAction({G_EXTRACT, 1, Ty}, Legal);
384 }
385 for (auto Ty : {v32s8, v16s16, v8s32, v4s64, v16s8, v8s16, v4s32, v2s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000386 setAction({G_INSERT, 1, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000387 setAction({G_EXTRACT, Ty}, Legal);
388 }
Igor Breger1c29be72017-06-22 09:43:35 +0000389
Igor Breger605b9652017-05-08 09:03:37 +0000390 /************ VLX *******************/
391 if (!Subtarget.hasVLX())
392 return;
393
Igor Breger605b9652017-05-08 09:03:37 +0000394 for (auto Ty : {v4s32, v8s32})
395 setAction({G_MUL, Ty}, Legal);
396}
397
398void X86LegalizerInfo::setLegalizerInfoAVX512DQ() {
399 if (!(Subtarget.hasAVX512() && Subtarget.hasDQI()))
400 return;
401
402 const LLT v8s64 = LLT::vector(8, 64);
403
404 setAction({G_MUL, v8s64}, Legal);
405
406 /************ VLX *******************/
407 if (!Subtarget.hasVLX())
408 return;
409
410 const LLT v2s64 = LLT::vector(2, 64);
411 const LLT v4s64 = LLT::vector(4, 64);
412
413 for (auto Ty : {v2s64, v4s64})
414 setAction({G_MUL, Ty}, Legal);
415}
416
417void X86LegalizerInfo::setLegalizerInfoAVX512BW() {
418 if (!(Subtarget.hasAVX512() && Subtarget.hasBWI()))
419 return;
420
Igor Breger842b5b32017-05-18 11:10:56 +0000421 const LLT v64s8 = LLT::vector(64, 8);
Igor Breger605b9652017-05-08 09:03:37 +0000422 const LLT v32s16 = LLT::vector(32, 16);
423
Igor Breger842b5b32017-05-18 11:10:56 +0000424 for (unsigned BinOp : {G_ADD, G_SUB})
425 for (auto Ty : {v64s8, v32s16})
426 setAction({BinOp, Ty}, Legal);
427
Igor Breger605b9652017-05-08 09:03:37 +0000428 setAction({G_MUL, v32s16}, Legal);
429
430 /************ VLX *******************/
431 if (!Subtarget.hasVLX())
432 return;
433
434 const LLT v8s16 = LLT::vector(8, 16);
435 const LLT v16s16 = LLT::vector(16, 16);
436
437 for (auto Ty : {v8s16, v16s16})
438 setAction({G_MUL, Ty}, Legal);
Igor Bregerb4442f32017-02-10 07:05:56 +0000439}