blob: 53215296ce654b62acff17e93a61310e25cd5a79 [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"
Igor Bregerb4442f32017-02-10 07:05:56 +000017#include "llvm/CodeGen/ValueTypes.h"
18#include "llvm/IR/DerivedTypes.h"
19#include "llvm/IR/Type.h"
20#include "llvm/Target/TargetOpcodes.h"
21
22using namespace llvm;
Igor Breger321cf3c2017-03-03 08:06:46 +000023using namespace TargetOpcode;
Igor Bregerb4442f32017-02-10 07:05:56 +000024
25#ifndef LLVM_BUILD_GLOBAL_ISEL
26#error "You shouldn't build this"
27#endif
28
Igor Breger531a2032017-03-26 08:11:12 +000029X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
30 const X86TargetMachine &TM)
31 : Subtarget(STI), TM(TM) {
Igor Bregerb4442f32017-02-10 07:05:56 +000032
33 setLegalizerInfo32bit();
34 setLegalizerInfo64bit();
Igor Breger321cf3c2017-03-03 08:06:46 +000035 setLegalizerInfoSSE1();
36 setLegalizerInfoSSE2();
Igor Breger605b9652017-05-08 09:03:37 +000037 setLegalizerInfoSSE41();
Igor Breger617be6e2017-05-23 08:23:51 +000038 setLegalizerInfoAVX();
Igor Breger605b9652017-05-08 09:03:37 +000039 setLegalizerInfoAVX2();
40 setLegalizerInfoAVX512();
41 setLegalizerInfoAVX512DQ();
42 setLegalizerInfoAVX512BW();
Igor Bregerb4442f32017-02-10 07:05:56 +000043
44 computeTables();
45}
46
47void X86LegalizerInfo::setLegalizerInfo32bit() {
48
Igor Bregera8ba5722017-03-23 15:25:57 +000049 if (Subtarget.is64Bit())
50 return;
51
52 const LLT p0 = LLT::pointer(0, 32);
Igor Breger29537882017-04-07 14:41:59 +000053 const LLT s1 = LLT::scalar(1);
Igor Bregerb4442f32017-02-10 07:05:56 +000054 const LLT s8 = LLT::scalar(8);
55 const LLT s16 = LLT::scalar(16);
56 const LLT s32 = LLT::scalar(32);
Igor Breger29537882017-04-07 14:41:59 +000057 const LLT s64 = LLT::scalar(64);
Igor Bregerb4442f32017-02-10 07:05:56 +000058
Igor Breger605b9652017-05-08 09:03:37 +000059 for (unsigned BinOp : {G_ADD, G_SUB, G_MUL})
Igor Bregera8ba5722017-03-23 15:25:57 +000060 for (auto Ty : {s8, s16, s32})
61 setAction({BinOp, Ty}, Legal);
62
Igor Breger28f290f2017-05-17 12:48:08 +000063 for (unsigned Op : {G_UADDE}) {
64 setAction({Op, s32}, Legal);
65 setAction({Op, 1, s1}, Legal);
66 }
67
Igor Bregera8ba5722017-03-23 15:25:57 +000068 for (unsigned MemOp : {G_LOAD, G_STORE}) {
69 for (auto Ty : {s8, s16, s32, p0})
70 setAction({MemOp, Ty}, Legal);
71
72 // And everything's fine in addrspace 0.
73 setAction({MemOp, 1, p0}, Legal);
Igor Bregerf7359d82017-02-22 12:25:09 +000074 }
Igor Breger531a2032017-03-26 08:11:12 +000075
76 // Pointer-handling
77 setAction({G_FRAME_INDEX, p0}, Legal);
Igor Breger29537882017-04-07 14:41:59 +000078
Igor Breger810c6252017-05-08 09:40:43 +000079 setAction({G_GEP, p0}, Legal);
80 setAction({G_GEP, 1, s32}, Legal);
81
82 for (auto Ty : {s1, s8, s16})
83 setAction({G_GEP, 1, Ty}, WidenScalar);
84
Igor Breger29537882017-04-07 14:41:59 +000085 // Constants
86 for (auto Ty : {s8, s16, s32, p0})
87 setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
88
89 setAction({TargetOpcode::G_CONSTANT, s1}, WidenScalar);
90 setAction({TargetOpcode::G_CONSTANT, s64}, NarrowScalar);
Igor Bregerc08a7832017-05-01 06:30:16 +000091
92 // Extensions
93 setAction({G_ZEXT, s32}, Legal);
94 setAction({G_SEXT, s32}, Legal);
95
Igor Bregerfda31e62017-05-10 06:52:58 +000096 for (auto Ty : {s1, s8, s16}) {
Igor Bregerc08a7832017-05-01 06:30:16 +000097 setAction({G_ZEXT, 1, Ty}, Legal);
98 setAction({G_SEXT, 1, Ty}, Legal);
99 }
Igor Bregerc7b59772017-05-11 07:17:40 +0000100
101 // Comparison
102 setAction({G_ICMP, s1}, Legal);
103
104 for (auto Ty : {s8, s16, s32, p0})
105 setAction({G_ICMP, 1, Ty}, Legal);
Igor Bregerb4442f32017-02-10 07:05:56 +0000106}
Igor Bregerb4442f32017-02-10 07:05:56 +0000107
Igor Bregerf7359d82017-02-22 12:25:09 +0000108void X86LegalizerInfo::setLegalizerInfo64bit() {
Igor Bregerb4442f32017-02-10 07:05:56 +0000109
110 if (!Subtarget.is64Bit())
111 return;
112
Igor Breger531a2032017-03-26 08:11:12 +0000113 const LLT p0 = LLT::pointer(0, TM.getPointerSize() * 8);
Igor Breger29537882017-04-07 14:41:59 +0000114 const LLT s1 = LLT::scalar(1);
Igor Bregera8ba5722017-03-23 15:25:57 +0000115 const LLT s8 = LLT::scalar(8);
116 const LLT s16 = LLT::scalar(16);
117 const LLT s32 = LLT::scalar(32);
Igor Bregerb4442f32017-02-10 07:05:56 +0000118 const LLT s64 = LLT::scalar(64);
119
Igor Breger605b9652017-05-08 09:03:37 +0000120 for (unsigned BinOp : {G_ADD, G_SUB, G_MUL})
Igor Bregera8ba5722017-03-23 15:25:57 +0000121 for (auto Ty : {s8, s16, s32, s64})
122 setAction({BinOp, Ty}, Legal);
123
124 for (unsigned MemOp : {G_LOAD, G_STORE}) {
125 for (auto Ty : {s8, s16, s32, s64, p0})
126 setAction({MemOp, Ty}, Legal);
127
128 // And everything's fine in addrspace 0.
129 setAction({MemOp, 1, p0}, Legal);
130 }
Igor Breger531a2032017-03-26 08:11:12 +0000131
132 // Pointer-handling
133 setAction({G_FRAME_INDEX, p0}, Legal);
Igor Breger29537882017-04-07 14:41:59 +0000134
Igor Breger810c6252017-05-08 09:40:43 +0000135 setAction({G_GEP, p0}, Legal);
136 setAction({G_GEP, 1, s32}, Legal);
137 setAction({G_GEP, 1, s64}, Legal);
138
139 for (auto Ty : {s1, s8, s16})
140 setAction({G_GEP, 1, Ty}, WidenScalar);
141
Igor Breger29537882017-04-07 14:41:59 +0000142 // Constants
143 for (auto Ty : {s8, s16, s32, s64, p0})
144 setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
145
146 setAction({TargetOpcode::G_CONSTANT, s1}, WidenScalar);
Igor Bregerc08a7832017-05-01 06:30:16 +0000147
148 // Extensions
149 for (auto Ty : {s32, s64}) {
150 setAction({G_ZEXT, Ty}, Legal);
151 setAction({G_SEXT, Ty}, Legal);
152 }
153
Igor Bregerfda31e62017-05-10 06:52:58 +0000154 for (auto Ty : {s1, s8, s16, s32}) {
Igor Bregerc08a7832017-05-01 06:30:16 +0000155 setAction({G_ZEXT, 1, Ty}, Legal);
156 setAction({G_SEXT, 1, Ty}, Legal);
157 }
Igor Bregerc7b59772017-05-11 07:17:40 +0000158
159 // Comparison
160 setAction({G_ICMP, s1}, Legal);
161
162 for (auto Ty : {s8, s16, s32, s64, p0})
163 setAction({G_ICMP, 1, Ty}, Legal);
Igor Breger321cf3c2017-03-03 08:06:46 +0000164}
165
166void X86LegalizerInfo::setLegalizerInfoSSE1() {
167 if (!Subtarget.hasSSE1())
168 return;
169
170 const LLT s32 = LLT::scalar(32);
171 const LLT v4s32 = LLT::vector(4, 32);
Igor Bregera8ba5722017-03-23 15:25:57 +0000172 const LLT v2s64 = LLT::vector(2, 64);
Igor Breger321cf3c2017-03-03 08:06:46 +0000173
174 for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
175 for (auto Ty : {s32, v4s32})
176 setAction({BinOp, Ty}, Legal);
Igor Bregera8ba5722017-03-23 15:25:57 +0000177
178 for (unsigned MemOp : {G_LOAD, G_STORE})
179 for (auto Ty : {v4s32, v2s64})
180 setAction({MemOp, Ty}, Legal);
Igor Breger321cf3c2017-03-03 08:06:46 +0000181}
182
183void X86LegalizerInfo::setLegalizerInfoSSE2() {
184 if (!Subtarget.hasSSE2())
185 return;
186
187 const LLT s64 = LLT::scalar(64);
Igor Breger842b5b32017-05-18 11:10:56 +0000188 const LLT v16s8 = LLT::vector(16, 8);
Igor Breger605b9652017-05-08 09:03:37 +0000189 const LLT v8s16 = LLT::vector(8, 16);
Igor Breger321cf3c2017-03-03 08:06:46 +0000190 const LLT v4s32 = LLT::vector(4, 32);
191 const LLT v2s64 = LLT::vector(2, 64);
192
193 for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
194 for (auto Ty : {s64, v2s64})
195 setAction({BinOp, Ty}, Legal);
196
197 for (unsigned BinOp : {G_ADD, G_SUB})
Igor Breger842b5b32017-05-18 11:10:56 +0000198 for (auto Ty : {v16s8, v8s16, v4s32, v2s64})
Igor Breger321cf3c2017-03-03 08:06:46 +0000199 setAction({BinOp, Ty}, Legal);
Igor Breger605b9652017-05-08 09:03:37 +0000200
201 setAction({G_MUL, v8s16}, Legal);
202}
203
204void X86LegalizerInfo::setLegalizerInfoSSE41() {
205 if (!Subtarget.hasSSE41())
206 return;
207
208 const LLT v4s32 = LLT::vector(4, 32);
209
210 setAction({G_MUL, v4s32}, Legal);
211}
212
Igor Breger617be6e2017-05-23 08:23:51 +0000213void X86LegalizerInfo::setLegalizerInfoAVX() {
214 if (!Subtarget.hasAVX())
215 return;
216
Igor Breger1c29be72017-06-22 09:43:35 +0000217 const LLT v16s8 = LLT::vector(16, 8);
218 const LLT v8s16 = LLT::vector(8, 16);
219 const LLT v4s32 = LLT::vector(4, 32);
220 const LLT v2s64 = LLT::vector(2, 64);
221
222 const LLT v32s8 = LLT::vector(32, 8);
223 const LLT v16s16 = LLT::vector(16, 16);
Igor Breger617be6e2017-05-23 08:23:51 +0000224 const LLT v8s32 = LLT::vector(8, 32);
225 const LLT v4s64 = LLT::vector(4, 64);
226
227 for (unsigned MemOp : {G_LOAD, G_STORE})
228 for (auto Ty : {v8s32, v4s64})
229 setAction({MemOp, Ty}, Legal);
Igor Breger1c29be72017-06-22 09:43:35 +0000230
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000231 for (auto Ty : {v32s8, v16s16, v8s32, v4s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000232 setAction({G_INSERT, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000233 setAction({G_EXTRACT, 1, Ty}, Legal);
234 }
235 for (auto Ty : {v16s8, v8s16, v4s32, v2s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000236 setAction({G_INSERT, 1, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000237 setAction({G_EXTRACT, Ty}, Legal);
238 }
Igor Breger617be6e2017-05-23 08:23:51 +0000239}
240
Igor Breger605b9652017-05-08 09:03:37 +0000241void X86LegalizerInfo::setLegalizerInfoAVX2() {
242 if (!Subtarget.hasAVX2())
243 return;
244
Igor Breger842b5b32017-05-18 11:10:56 +0000245 const LLT v32s8 = LLT::vector(32, 8);
Igor Breger605b9652017-05-08 09:03:37 +0000246 const LLT v16s16 = LLT::vector(16, 16);
247 const LLT v8s32 = LLT::vector(8, 32);
Igor Breger842b5b32017-05-18 11:10:56 +0000248 const LLT v4s64 = LLT::vector(4, 64);
249
250 for (unsigned BinOp : {G_ADD, G_SUB})
251 for (auto Ty : {v32s8, v16s16, v8s32, v4s64})
252 setAction({BinOp, Ty}, Legal);
Igor Breger605b9652017-05-08 09:03:37 +0000253
254 for (auto Ty : {v16s16, v8s32})
255 setAction({G_MUL, Ty}, Legal);
256}
257
258void X86LegalizerInfo::setLegalizerInfoAVX512() {
259 if (!Subtarget.hasAVX512())
260 return;
261
Igor Breger1c29be72017-06-22 09:43:35 +0000262 const LLT v16s8 = LLT::vector(16, 8);
263 const LLT v8s16 = LLT::vector(8, 16);
264 const LLT v4s32 = LLT::vector(4, 32);
265 const LLT v2s64 = LLT::vector(2, 64);
266
267 const LLT v32s8 = LLT::vector(32, 8);
268 const LLT v16s16 = LLT::vector(16, 16);
269 const LLT v8s32 = LLT::vector(8, 32);
270 const LLT v4s64 = LLT::vector(4, 64);
271
272 const LLT v64s8 = LLT::vector(64, 8);
273 const LLT v32s16 = LLT::vector(32, 16);
Igor Breger605b9652017-05-08 09:03:37 +0000274 const LLT v16s32 = LLT::vector(16, 32);
Igor Breger842b5b32017-05-18 11:10:56 +0000275 const LLT v8s64 = LLT::vector(8, 64);
276
277 for (unsigned BinOp : {G_ADD, G_SUB})
278 for (auto Ty : {v16s32, v8s64})
279 setAction({BinOp, Ty}, Legal);
Igor Breger605b9652017-05-08 09:03:37 +0000280
281 setAction({G_MUL, v16s32}, Legal);
282
Igor Breger617be6e2017-05-23 08:23:51 +0000283 for (unsigned MemOp : {G_LOAD, G_STORE})
284 for (auto Ty : {v16s32, v8s64})
285 setAction({MemOp, Ty}, Legal);
286
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000287 for (auto Ty : {v64s8, v32s16, v16s32, v8s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000288 setAction({G_INSERT, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000289 setAction({G_EXTRACT, 1, Ty}, Legal);
290 }
291 for (auto Ty : {v32s8, v16s16, v8s32, v4s64, v16s8, v8s16, v4s32, v2s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000292 setAction({G_INSERT, 1, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000293 setAction({G_EXTRACT, Ty}, Legal);
294 }
Igor Breger1c29be72017-06-22 09:43:35 +0000295
Igor Breger605b9652017-05-08 09:03:37 +0000296 /************ VLX *******************/
297 if (!Subtarget.hasVLX())
298 return;
299
Igor Breger605b9652017-05-08 09:03:37 +0000300 for (auto Ty : {v4s32, v8s32})
301 setAction({G_MUL, Ty}, Legal);
302}
303
304void X86LegalizerInfo::setLegalizerInfoAVX512DQ() {
305 if (!(Subtarget.hasAVX512() && Subtarget.hasDQI()))
306 return;
307
308 const LLT v8s64 = LLT::vector(8, 64);
309
310 setAction({G_MUL, v8s64}, Legal);
311
312 /************ VLX *******************/
313 if (!Subtarget.hasVLX())
314 return;
315
316 const LLT v2s64 = LLT::vector(2, 64);
317 const LLT v4s64 = LLT::vector(4, 64);
318
319 for (auto Ty : {v2s64, v4s64})
320 setAction({G_MUL, Ty}, Legal);
321}
322
323void X86LegalizerInfo::setLegalizerInfoAVX512BW() {
324 if (!(Subtarget.hasAVX512() && Subtarget.hasBWI()))
325 return;
326
Igor Breger842b5b32017-05-18 11:10:56 +0000327 const LLT v64s8 = LLT::vector(64, 8);
Igor Breger605b9652017-05-08 09:03:37 +0000328 const LLT v32s16 = LLT::vector(32, 16);
329
Igor Breger842b5b32017-05-18 11:10:56 +0000330 for (unsigned BinOp : {G_ADD, G_SUB})
331 for (auto Ty : {v64s8, v32s16})
332 setAction({BinOp, Ty}, Legal);
333
Igor Breger605b9652017-05-08 09:03:37 +0000334 setAction({G_MUL, v32s16}, Legal);
335
336 /************ VLX *******************/
337 if (!Subtarget.hasVLX())
338 return;
339
340 const LLT v8s16 = LLT::vector(8, 16);
341 const LLT v16s16 = LLT::vector(16, 16);
342
343 for (auto Ty : {v8s16, v16s16})
344 setAction({G_MUL, Ty}, Legal);
Igor Bregerb4442f32017-02-10 07:05:56 +0000345}