blob: c5e37d56d0e9d2641532ab3aaa7d698f74d4ab15 [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"
Craig Topper2fa14362018-03-29 17:21:10 +000018#include "llvm/CodeGen/ValueTypes.h"
Igor Bregerb4442f32017-02-10 07:05:56 +000019#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;
Daniel Sanders9ade5592018-01-29 17:37:29 +000024using namespace LegalizeActions;
Igor Bregerb4442f32017-02-10 07:05:56 +000025
Kristof Beylsaf9814a2017-11-07 10:34:34 +000026/// FIXME: The following static functions are SizeChangeStrategy functions
27/// that are meant to temporarily mimic the behaviour of the old legalization
28/// based on doubling/halving non-legal types as closely as possible. This is
29/// not entirly possible as only legalizing the types that are exactly a power
30/// of 2 times the size of the legal types would require specifying all those
31/// sizes explicitly.
32/// In practice, not specifying those isn't a problem, and the below functions
33/// should disappear quickly as we add support for legalizing non-power-of-2
34/// sized types further.
35static void
36addAndInterleaveWithUnsupported(LegalizerInfo::SizeAndActionsVec &result,
37 const LegalizerInfo::SizeAndActionsVec &v) {
38 for (unsigned i = 0; i < v.size(); ++i) {
39 result.push_back(v[i]);
40 if (i + 1 < v[i].first && i + 1 < v.size() &&
41 v[i + 1].first != v[i].first + 1)
Daniel Sanders9ade5592018-01-29 17:37:29 +000042 result.push_back({v[i].first + 1, Unsupported});
Kristof Beylsaf9814a2017-11-07 10:34:34 +000043 }
44}
45
46static LegalizerInfo::SizeAndActionsVec
47widen_1(const LegalizerInfo::SizeAndActionsVec &v) {
48 assert(v.size() >= 1);
49 assert(v[0].first > 1);
Daniel Sanders9ade5592018-01-29 17:37:29 +000050 LegalizerInfo::SizeAndActionsVec result = {{1, WidenScalar},
51 {2, Unsupported}};
Kristof Beylsaf9814a2017-11-07 10:34:34 +000052 addAndInterleaveWithUnsupported(result, v);
53 auto Largest = result.back().first;
Daniel Sanders9ade5592018-01-29 17:37:29 +000054 result.push_back({Largest + 1, Unsupported});
Kristof Beylsaf9814a2017-11-07 10:34:34 +000055 return result;
56}
57
Igor Breger531a2032017-03-26 08:11:12 +000058X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
59 const X86TargetMachine &TM)
60 : Subtarget(STI), TM(TM) {
Igor Bregerb4442f32017-02-10 07:05:56 +000061
62 setLegalizerInfo32bit();
63 setLegalizerInfo64bit();
Igor Breger321cf3c2017-03-03 08:06:46 +000064 setLegalizerInfoSSE1();
65 setLegalizerInfoSSE2();
Igor Breger605b9652017-05-08 09:03:37 +000066 setLegalizerInfoSSE41();
Igor Breger617be6e2017-05-23 08:23:51 +000067 setLegalizerInfoAVX();
Igor Breger605b9652017-05-08 09:03:37 +000068 setLegalizerInfoAVX2();
69 setLegalizerInfoAVX512();
70 setLegalizerInfoAVX512DQ();
71 setLegalizerInfoAVX512BW();
Igor Bregerb4442f32017-02-10 07:05:56 +000072
Kristof Beylsaf9814a2017-11-07 10:34:34 +000073 setLegalizeScalarToDifferentSizeStrategy(G_PHI, 0, widen_1);
74 for (unsigned BinOp : {G_SUB, G_MUL, G_AND, G_OR, G_XOR})
75 setLegalizeScalarToDifferentSizeStrategy(BinOp, 0, widen_1);
76 for (unsigned MemOp : {G_LOAD, G_STORE})
77 setLegalizeScalarToDifferentSizeStrategy(MemOp, 0,
78 narrowToSmallerAndWidenToSmallest);
79 setLegalizeScalarToDifferentSizeStrategy(
80 G_GEP, 1, widenToLargerTypesUnsupportedOtherwise);
81 setLegalizeScalarToDifferentSizeStrategy(
82 G_CONSTANT, 0, widenToLargerTypesAndNarrowToLargest);
83
Igor Bregerb4442f32017-02-10 07:05:56 +000084 computeTables();
85}
86
87void X86LegalizerInfo::setLegalizerInfo32bit() {
88
Matt Arsenault41e5ac42018-03-14 00:36:23 +000089 const LLT p0 = LLT::pointer(0, TM.getPointerSizeInBits(0));
Igor Breger29537882017-04-07 14:41:59 +000090 const LLT s1 = LLT::scalar(1);
Igor Bregerb4442f32017-02-10 07:05:56 +000091 const LLT s8 = LLT::scalar(8);
92 const LLT s16 = LLT::scalar(16);
93 const LLT s32 = LLT::scalar(32);
Volkan Kelesa32ff002017-12-01 08:19:10 +000094 const LLT s64 = LLT::scalar(64);
Alexander Ivchenkoda9e81c2018-02-08 22:41:47 +000095 const LLT s128 = LLT::scalar(128);
Igor Bregerb4442f32017-02-10 07:05:56 +000096
Igor Breger47be5fb2017-08-24 07:06:27 +000097 for (auto Ty : {p0, s1, s8, s16, s32})
98 setAction({G_IMPLICIT_DEF, Ty}, Legal);
99
Igor Breger2661ae42017-09-04 09:06:45 +0000100 for (auto Ty : {s8, s16, s32, p0})
101 setAction({G_PHI, Ty}, Legal);
102
Kristof Beylsaf9814a2017-11-07 10:34:34 +0000103 for (unsigned BinOp : {G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR})
Igor Bregera8ba5722017-03-23 15:25:57 +0000104 for (auto Ty : {s8, s16, s32})
105 setAction({BinOp, Ty}, Legal);
106
Igor Breger28f290f2017-05-17 12:48:08 +0000107 for (unsigned Op : {G_UADDE}) {
108 setAction({Op, s32}, Legal);
109 setAction({Op, 1, s1}, Legal);
110 }
111
Igor Bregera8ba5722017-03-23 15:25:57 +0000112 for (unsigned MemOp : {G_LOAD, G_STORE}) {
113 for (auto Ty : {s8, s16, s32, p0})
114 setAction({MemOp, Ty}, Legal);
115
116 // And everything's fine in addrspace 0.
117 setAction({MemOp, 1, p0}, Legal);
Igor Bregerf7359d82017-02-22 12:25:09 +0000118 }
Igor Breger531a2032017-03-26 08:11:12 +0000119
120 // Pointer-handling
121 setAction({G_FRAME_INDEX, p0}, Legal);
Igor Breger717bd362017-07-02 08:58:29 +0000122 setAction({G_GLOBAL_VALUE, p0}, Legal);
Igor Breger29537882017-04-07 14:41:59 +0000123
Igor Breger810c6252017-05-08 09:40:43 +0000124 setAction({G_GEP, p0}, Legal);
125 setAction({G_GEP, 1, s32}, Legal);
126
Alexander Ivchenkoc01f7502018-02-28 12:11:53 +0000127 if (!Subtarget.is64Bit()) {
Alexander Ivchenko46e07e32018-02-28 09:18:47 +0000128 getActionDefinitionsBuilder(G_PTRTOINT)
129 .legalForCartesianProduct({s1, s8, s16, s32}, {p0})
130 .maxScalar(0, s32)
131 .widenScalarToNextPow2(0, /*Min*/ 8);
Alexander Ivchenkoc01f7502018-02-28 12:11:53 +0000132 getActionDefinitionsBuilder(G_INTTOPTR).legalFor({s32, p0});
Alexander Ivchenko0bd4d8c2018-03-14 11:23:57 +0000133
Alexander Ivchenko86ef9ab2018-03-14 15:41:11 +0000134 // Shifts and SDIV
135 getActionDefinitionsBuilder({G_SHL, G_LSHR, G_ASHR, G_SDIV})
Alexander Ivchenko0bd4d8c2018-03-14 11:23:57 +0000136 .legalFor({s8, s16, s32})
137 .clampScalar(0, s8, s32);
Alexander Ivchenkoc01f7502018-02-28 12:11:53 +0000138 }
Alexander Ivchenko46e07e32018-02-28 09:18:47 +0000139
Igor Breger685889c2017-08-21 10:51:54 +0000140 // Control-flow
141 setAction({G_BRCOND, s1}, Legal);
142
Igor Breger29537882017-04-07 14:41:59 +0000143 // Constants
144 for (auto Ty : {s8, s16, s32, p0})
145 setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
146
Igor Bregerc08a7832017-05-01 06:30:16 +0000147 // Extensions
Igor Bregerd48c5e42017-07-10 09:07:34 +0000148 for (auto Ty : {s8, s16, s32}) {
149 setAction({G_ZEXT, Ty}, Legal);
150 setAction({G_SEXT, Ty}, Legal);
Igor Breger1f143642017-09-11 09:41:13 +0000151 setAction({G_ANYEXT, Ty}, Legal);
Igor Bregerd48c5e42017-07-10 09:07:34 +0000152 }
Alexander Ivchenkoda9e81c2018-02-08 22:41:47 +0000153 setAction({G_ANYEXT, s128}, Legal);
Igor Bregerc08a7832017-05-01 06:30:16 +0000154
Igor Bregerc7b59772017-05-11 07:17:40 +0000155 // Comparison
156 setAction({G_ICMP, s1}, Legal);
157
158 for (auto Ty : {s8, s16, s32, p0})
159 setAction({G_ICMP, 1, Ty}, Legal);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000160
161 // Merge/Unmerge
162 for (const auto &Ty : {s16, s32, s64}) {
163 setAction({G_MERGE_VALUES, Ty}, Legal);
164 setAction({G_UNMERGE_VALUES, 1, Ty}, Legal);
165 }
166 for (const auto &Ty : {s8, s16, s32}) {
167 setAction({G_MERGE_VALUES, 1, Ty}, Legal);
168 setAction({G_UNMERGE_VALUES, Ty}, Legal);
169 }
Igor Bregerb4442f32017-02-10 07:05:56 +0000170}
Igor Bregerb4442f32017-02-10 07:05:56 +0000171
Igor Bregerf7359d82017-02-22 12:25:09 +0000172void X86LegalizerInfo::setLegalizerInfo64bit() {
Igor Bregerb4442f32017-02-10 07:05:56 +0000173
174 if (!Subtarget.is64Bit())
175 return;
176
Matt Arsenault41e5ac42018-03-14 00:36:23 +0000177 const LLT p0 = LLT::pointer(0, TM.getPointerSizeInBits(0));
Alexander Ivchenko46e07e32018-02-28 09:18:47 +0000178 const LLT s1 = LLT::scalar(1);
179 const LLT s8 = LLT::scalar(8);
180 const LLT s16 = LLT::scalar(16);
181 const LLT s32 = LLT::scalar(32);
Igor Bregerb4442f32017-02-10 07:05:56 +0000182 const LLT s64 = LLT::scalar(64);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000183 const LLT s128 = LLT::scalar(128);
Igor Bregerb4442f32017-02-10 07:05:56 +0000184
Igor Breger42f8bfc2017-08-31 11:40:03 +0000185 setAction({G_IMPLICIT_DEF, s64}, Legal);
Alexander Ivchenkoa85c4fc2018-02-08 22:40:31 +0000186 // Need to have that, as tryFoldImplicitDef will create this pattern:
187 // s128 = EXTEND (G_IMPLICIT_DEF s32/s64) -> s128 = G_IMPLICIT_DEF
188 setAction({G_IMPLICIT_DEF, s128}, Legal);
Igor Breger47be5fb2017-08-24 07:06:27 +0000189
Igor Breger2661ae42017-09-04 09:06:45 +0000190 setAction({G_PHI, s64}, Legal);
191
Igor Bregerd5b59cf2017-06-28 11:39:04 +0000192 for (unsigned BinOp : {G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR})
Igor Breger42f8bfc2017-08-31 11:40:03 +0000193 setAction({BinOp, s64}, Legal);
Igor Bregera8ba5722017-03-23 15:25:57 +0000194
Igor Breger1f143642017-09-11 09:41:13 +0000195 for (unsigned MemOp : {G_LOAD, G_STORE})
Igor Breger42f8bfc2017-08-31 11:40:03 +0000196 setAction({MemOp, s64}, Legal);
Igor Breger531a2032017-03-26 08:11:12 +0000197
198 // Pointer-handling
Igor Breger810c6252017-05-08 09:40:43 +0000199 setAction({G_GEP, 1, s64}, Legal);
Alexander Ivchenko46e07e32018-02-28 09:18:47 +0000200 getActionDefinitionsBuilder(G_PTRTOINT)
201 .legalForCartesianProduct({s1, s8, s16, s32, s64}, {p0})
202 .maxScalar(0, s64)
203 .widenScalarToNextPow2(0, /*Min*/ 8);
Alexander Ivchenkoc01f7502018-02-28 12:11:53 +0000204 getActionDefinitionsBuilder(G_INTTOPTR).legalFor({s64, p0});
Igor Breger810c6252017-05-08 09:40:43 +0000205
Igor Breger29537882017-04-07 14:41:59 +0000206 // Constants
Igor Breger42f8bfc2017-08-31 11:40:03 +0000207 setAction({TargetOpcode::G_CONSTANT, s64}, Legal);
Igor Bregerc08a7832017-05-01 06:30:16 +0000208
209 // Extensions
Igor Breger1f143642017-09-11 09:41:13 +0000210 for (unsigned extOp : {G_ZEXT, G_SEXT, G_ANYEXT}) {
211 setAction({extOp, s64}, Legal);
Igor Breger1f143642017-09-11 09:41:13 +0000212 }
Igor Bregerc7b59772017-05-11 07:17:40 +0000213
214 // Comparison
Igor Breger42f8bfc2017-08-31 11:40:03 +0000215 setAction({G_ICMP, 1, s64}, Legal);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000216
Alexander Ivchenko86ef9ab2018-03-14 15:41:11 +0000217 // Shifts and SDIV
218 getActionDefinitionsBuilder({G_SHL, G_LSHR, G_ASHR, G_SDIV})
Alexander Ivchenko0bd4d8c2018-03-14 11:23:57 +0000219 .legalFor({s8, s16, s32, s64})
220 .clampScalar(0, s8, s64);
221
Volkan Kelesa32ff002017-12-01 08:19:10 +0000222 // Merge/Unmerge
223 setAction({G_MERGE_VALUES, s128}, Legal);
224 setAction({G_UNMERGE_VALUES, 1, s128}, Legal);
225 setAction({G_MERGE_VALUES, 1, s128}, Legal);
226 setAction({G_UNMERGE_VALUES, s128}, Legal);
Igor Breger321cf3c2017-03-03 08:06:46 +0000227}
228
229void X86LegalizerInfo::setLegalizerInfoSSE1() {
230 if (!Subtarget.hasSSE1())
231 return;
232
233 const LLT s32 = LLT::scalar(32);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000234 const LLT s64 = LLT::scalar(64);
Igor Breger321cf3c2017-03-03 08:06:46 +0000235 const LLT v4s32 = LLT::vector(4, 32);
Igor Bregera8ba5722017-03-23 15:25:57 +0000236 const LLT v2s64 = LLT::vector(2, 64);
Igor Breger321cf3c2017-03-03 08:06:46 +0000237
238 for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
239 for (auto Ty : {s32, v4s32})
240 setAction({BinOp, Ty}, Legal);
Igor Bregera8ba5722017-03-23 15:25:57 +0000241
242 for (unsigned MemOp : {G_LOAD, G_STORE})
243 for (auto Ty : {v4s32, v2s64})
244 setAction({MemOp, Ty}, Legal);
Igor Breger21200ed2017-09-17 08:08:13 +0000245
246 // Constants
247 setAction({TargetOpcode::G_FCONSTANT, s32}, Legal);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000248
249 // Merge/Unmerge
250 for (const auto &Ty : {v4s32, v2s64}) {
251 setAction({G_MERGE_VALUES, Ty}, Legal);
252 setAction({G_UNMERGE_VALUES, 1, Ty}, Legal);
253 }
254 setAction({G_MERGE_VALUES, 1, s64}, Legal);
255 setAction({G_UNMERGE_VALUES, s64}, Legal);
Igor Breger321cf3c2017-03-03 08:06:46 +0000256}
257
258void X86LegalizerInfo::setLegalizerInfoSSE2() {
259 if (!Subtarget.hasSSE2())
260 return;
261
Igor Breger5c7211992017-09-13 09:05:23 +0000262 const LLT s32 = LLT::scalar(32);
Igor Breger321cf3c2017-03-03 08:06:46 +0000263 const LLT s64 = LLT::scalar(64);
Igor Breger842b5b32017-05-18 11:10:56 +0000264 const LLT v16s8 = LLT::vector(16, 8);
Igor Breger605b9652017-05-08 09:03:37 +0000265 const LLT v8s16 = LLT::vector(8, 16);
Igor Breger321cf3c2017-03-03 08:06:46 +0000266 const LLT v4s32 = LLT::vector(4, 32);
267 const LLT v2s64 = LLT::vector(2, 64);
268
Volkan Kelesa32ff002017-12-01 08:19:10 +0000269 const LLT v32s8 = LLT::vector(32, 8);
270 const LLT v16s16 = LLT::vector(16, 16);
271 const LLT v8s32 = LLT::vector(8, 32);
272 const LLT v4s64 = LLT::vector(4, 64);
273
Igor Breger321cf3c2017-03-03 08:06:46 +0000274 for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
275 for (auto Ty : {s64, v2s64})
276 setAction({BinOp, Ty}, Legal);
277
278 for (unsigned BinOp : {G_ADD, G_SUB})
Igor Breger842b5b32017-05-18 11:10:56 +0000279 for (auto Ty : {v16s8, v8s16, v4s32, v2s64})
Igor Breger321cf3c2017-03-03 08:06:46 +0000280 setAction({BinOp, Ty}, Legal);
Igor Breger605b9652017-05-08 09:03:37 +0000281
282 setAction({G_MUL, v8s16}, Legal);
Igor Breger5c7211992017-09-13 09:05:23 +0000283
284 setAction({G_FPEXT, s64}, Legal);
285 setAction({G_FPEXT, 1, s32}, Legal);
Igor Breger21200ed2017-09-17 08:08:13 +0000286
287 // Constants
288 setAction({TargetOpcode::G_FCONSTANT, s64}, Legal);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000289
290 // Merge/Unmerge
291 for (const auto &Ty :
292 {v16s8, v32s8, v8s16, v16s16, v4s32, v8s32, v2s64, v4s64}) {
293 setAction({G_MERGE_VALUES, Ty}, Legal);
294 setAction({G_UNMERGE_VALUES, 1, Ty}, Legal);
295 }
296 for (const auto &Ty : {v16s8, v8s16, v4s32, v2s64}) {
297 setAction({G_MERGE_VALUES, 1, Ty}, Legal);
298 setAction({G_UNMERGE_VALUES, Ty}, Legal);
299 }
Igor Breger605b9652017-05-08 09:03:37 +0000300}
301
302void X86LegalizerInfo::setLegalizerInfoSSE41() {
303 if (!Subtarget.hasSSE41())
304 return;
305
306 const LLT v4s32 = LLT::vector(4, 32);
307
308 setAction({G_MUL, v4s32}, Legal);
309}
310
Igor Breger617be6e2017-05-23 08:23:51 +0000311void X86LegalizerInfo::setLegalizerInfoAVX() {
312 if (!Subtarget.hasAVX())
313 return;
314
Igor Breger1c29be72017-06-22 09:43:35 +0000315 const LLT v16s8 = LLT::vector(16, 8);
316 const LLT v8s16 = LLT::vector(8, 16);
317 const LLT v4s32 = LLT::vector(4, 32);
318 const LLT v2s64 = LLT::vector(2, 64);
319
320 const LLT v32s8 = LLT::vector(32, 8);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000321 const LLT v64s8 = LLT::vector(64, 8);
Igor Breger1c29be72017-06-22 09:43:35 +0000322 const LLT v16s16 = LLT::vector(16, 16);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000323 const LLT v32s16 = LLT::vector(32, 16);
Igor Breger617be6e2017-05-23 08:23:51 +0000324 const LLT v8s32 = LLT::vector(8, 32);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000325 const LLT v16s32 = LLT::vector(16, 32);
Igor Breger617be6e2017-05-23 08:23:51 +0000326 const LLT v4s64 = LLT::vector(4, 64);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000327 const LLT v8s64 = LLT::vector(8, 64);
Igor Breger617be6e2017-05-23 08:23:51 +0000328
329 for (unsigned MemOp : {G_LOAD, G_STORE})
330 for (auto Ty : {v8s32, v4s64})
331 setAction({MemOp, Ty}, Legal);
Igor Breger1c29be72017-06-22 09:43:35 +0000332
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000333 for (auto Ty : {v32s8, v16s16, v8s32, v4s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000334 setAction({G_INSERT, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000335 setAction({G_EXTRACT, 1, Ty}, Legal);
336 }
337 for (auto Ty : {v16s8, v8s16, v4s32, v2s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000338 setAction({G_INSERT, 1, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000339 setAction({G_EXTRACT, Ty}, Legal);
340 }
Volkan Kelesa32ff002017-12-01 08:19:10 +0000341 // Merge/Unmerge
342 for (const auto &Ty :
343 {v32s8, v64s8, v16s16, v32s16, v8s32, v16s32, v4s64, v8s64}) {
344 setAction({G_MERGE_VALUES, Ty}, Legal);
345 setAction({G_UNMERGE_VALUES, 1, Ty}, Legal);
346 }
347 for (const auto &Ty :
348 {v16s8, v32s8, v8s16, v16s16, v4s32, v8s32, v2s64, v4s64}) {
349 setAction({G_MERGE_VALUES, 1, Ty}, Legal);
350 setAction({G_UNMERGE_VALUES, Ty}, Legal);
351 }
Igor Breger617be6e2017-05-23 08:23:51 +0000352}
353
Igor Breger605b9652017-05-08 09:03:37 +0000354void X86LegalizerInfo::setLegalizerInfoAVX2() {
355 if (!Subtarget.hasAVX2())
356 return;
357
Igor Breger842b5b32017-05-18 11:10:56 +0000358 const LLT v32s8 = LLT::vector(32, 8);
Igor Breger605b9652017-05-08 09:03:37 +0000359 const LLT v16s16 = LLT::vector(16, 16);
360 const LLT v8s32 = LLT::vector(8, 32);
Igor Breger842b5b32017-05-18 11:10:56 +0000361 const LLT v4s64 = LLT::vector(4, 64);
362
Volkan Kelesa32ff002017-12-01 08:19:10 +0000363 const LLT v64s8 = LLT::vector(64, 8);
364 const LLT v32s16 = LLT::vector(32, 16);
365 const LLT v16s32 = LLT::vector(16, 32);
366 const LLT v8s64 = LLT::vector(8, 64);
367
Igor Breger842b5b32017-05-18 11:10:56 +0000368 for (unsigned BinOp : {G_ADD, G_SUB})
369 for (auto Ty : {v32s8, v16s16, v8s32, v4s64})
370 setAction({BinOp, Ty}, Legal);
Igor Breger605b9652017-05-08 09:03:37 +0000371
372 for (auto Ty : {v16s16, v8s32})
373 setAction({G_MUL, Ty}, Legal);
Volkan Kelesa32ff002017-12-01 08:19:10 +0000374
375 // Merge/Unmerge
376 for (const auto &Ty : {v64s8, v32s16, v16s32, v8s64}) {
377 setAction({G_MERGE_VALUES, Ty}, Legal);
378 setAction({G_UNMERGE_VALUES, 1, Ty}, Legal);
379 }
380 for (const auto &Ty : {v32s8, v16s16, v8s32, v4s64}) {
381 setAction({G_MERGE_VALUES, 1, Ty}, Legal);
382 setAction({G_UNMERGE_VALUES, Ty}, Legal);
383 }
Igor Breger605b9652017-05-08 09:03:37 +0000384}
385
386void X86LegalizerInfo::setLegalizerInfoAVX512() {
387 if (!Subtarget.hasAVX512())
388 return;
389
Igor Breger1c29be72017-06-22 09:43:35 +0000390 const LLT v16s8 = LLT::vector(16, 8);
391 const LLT v8s16 = LLT::vector(8, 16);
392 const LLT v4s32 = LLT::vector(4, 32);
393 const LLT v2s64 = LLT::vector(2, 64);
394
395 const LLT v32s8 = LLT::vector(32, 8);
396 const LLT v16s16 = LLT::vector(16, 16);
397 const LLT v8s32 = LLT::vector(8, 32);
398 const LLT v4s64 = LLT::vector(4, 64);
399
400 const LLT v64s8 = LLT::vector(64, 8);
401 const LLT v32s16 = LLT::vector(32, 16);
Igor Breger605b9652017-05-08 09:03:37 +0000402 const LLT v16s32 = LLT::vector(16, 32);
Igor Breger842b5b32017-05-18 11:10:56 +0000403 const LLT v8s64 = LLT::vector(8, 64);
404
405 for (unsigned BinOp : {G_ADD, G_SUB})
406 for (auto Ty : {v16s32, v8s64})
407 setAction({BinOp, Ty}, Legal);
Igor Breger605b9652017-05-08 09:03:37 +0000408
409 setAction({G_MUL, v16s32}, Legal);
410
Igor Breger617be6e2017-05-23 08:23:51 +0000411 for (unsigned MemOp : {G_LOAD, G_STORE})
412 for (auto Ty : {v16s32, v8s64})
413 setAction({MemOp, Ty}, Legal);
414
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000415 for (auto Ty : {v64s8, v32s16, v16s32, v8s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000416 setAction({G_INSERT, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000417 setAction({G_EXTRACT, 1, Ty}, Legal);
418 }
419 for (auto Ty : {v32s8, v16s16, v8s32, v4s64, v16s8, v8s16, v4s32, v2s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000420 setAction({G_INSERT, 1, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000421 setAction({G_EXTRACT, Ty}, Legal);
422 }
Igor Breger1c29be72017-06-22 09:43:35 +0000423
Igor Breger605b9652017-05-08 09:03:37 +0000424 /************ VLX *******************/
425 if (!Subtarget.hasVLX())
426 return;
427
Igor Breger605b9652017-05-08 09:03:37 +0000428 for (auto Ty : {v4s32, v8s32})
429 setAction({G_MUL, Ty}, Legal);
430}
431
432void X86LegalizerInfo::setLegalizerInfoAVX512DQ() {
433 if (!(Subtarget.hasAVX512() && Subtarget.hasDQI()))
434 return;
435
436 const LLT v8s64 = LLT::vector(8, 64);
437
438 setAction({G_MUL, v8s64}, Legal);
439
440 /************ VLX *******************/
441 if (!Subtarget.hasVLX())
442 return;
443
444 const LLT v2s64 = LLT::vector(2, 64);
445 const LLT v4s64 = LLT::vector(4, 64);
446
447 for (auto Ty : {v2s64, v4s64})
448 setAction({G_MUL, Ty}, Legal);
449}
450
451void X86LegalizerInfo::setLegalizerInfoAVX512BW() {
452 if (!(Subtarget.hasAVX512() && Subtarget.hasBWI()))
453 return;
454
Igor Breger842b5b32017-05-18 11:10:56 +0000455 const LLT v64s8 = LLT::vector(64, 8);
Igor Breger605b9652017-05-08 09:03:37 +0000456 const LLT v32s16 = LLT::vector(32, 16);
457
Igor Breger842b5b32017-05-18 11:10:56 +0000458 for (unsigned BinOp : {G_ADD, G_SUB})
459 for (auto Ty : {v64s8, v32s16})
460 setAction({BinOp, Ty}, Legal);
461
Igor Breger605b9652017-05-08 09:03:37 +0000462 setAction({G_MUL, v32s16}, Legal);
463
464 /************ VLX *******************/
465 if (!Subtarget.hasVLX())
466 return;
467
468 const LLT v8s16 = LLT::vector(8, 16);
469 const LLT v16s16 = LLT::vector(16, 16);
470
471 for (auto Ty : {v8s16, v16s16})
472 setAction({G_MUL, Ty}, Legal);
Igor Bregerb4442f32017-02-10 07:05:56 +0000473}