blob: 62dd088c2fd84e3597251e150652887c24b45c22 [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 Bregerd5b59cf2017-06-28 11:39:04 +000059 for (unsigned BinOp : {G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR})
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 Breger717bd362017-07-02 08:58:29 +000078 setAction({G_GLOBAL_VALUE, p0}, Legal);
Igor Breger29537882017-04-07 14:41:59 +000079
Igor Breger810c6252017-05-08 09:40:43 +000080 setAction({G_GEP, p0}, Legal);
81 setAction({G_GEP, 1, s32}, Legal);
82
83 for (auto Ty : {s1, s8, s16})
84 setAction({G_GEP, 1, Ty}, WidenScalar);
85
Igor Breger29537882017-04-07 14:41:59 +000086 // Constants
87 for (auto Ty : {s8, s16, s32, p0})
88 setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
89
90 setAction({TargetOpcode::G_CONSTANT, s1}, WidenScalar);
91 setAction({TargetOpcode::G_CONSTANT, s64}, NarrowScalar);
Igor Bregerc08a7832017-05-01 06:30:16 +000092
93 // Extensions
94 setAction({G_ZEXT, s32}, Legal);
95 setAction({G_SEXT, s32}, Legal);
96
Igor Bregerfda31e62017-05-10 06:52:58 +000097 for (auto Ty : {s1, s8, s16}) {
Igor Bregerc08a7832017-05-01 06:30:16 +000098 setAction({G_ZEXT, 1, Ty}, Legal);
99 setAction({G_SEXT, 1, Ty}, Legal);
100 }
Igor Bregerc7b59772017-05-11 07:17:40 +0000101
102 // Comparison
103 setAction({G_ICMP, s1}, Legal);
104
105 for (auto Ty : {s8, s16, s32, p0})
106 setAction({G_ICMP, 1, Ty}, Legal);
Igor Bregerb4442f32017-02-10 07:05:56 +0000107}
Igor Bregerb4442f32017-02-10 07:05:56 +0000108
Igor Bregerf7359d82017-02-22 12:25:09 +0000109void X86LegalizerInfo::setLegalizerInfo64bit() {
Igor Bregerb4442f32017-02-10 07:05:56 +0000110
111 if (!Subtarget.is64Bit())
112 return;
113
Igor Breger531a2032017-03-26 08:11:12 +0000114 const LLT p0 = LLT::pointer(0, TM.getPointerSize() * 8);
Igor Breger29537882017-04-07 14:41:59 +0000115 const LLT s1 = LLT::scalar(1);
Igor Bregera8ba5722017-03-23 15:25:57 +0000116 const LLT s8 = LLT::scalar(8);
117 const LLT s16 = LLT::scalar(16);
118 const LLT s32 = LLT::scalar(32);
Igor Bregerb4442f32017-02-10 07:05:56 +0000119 const LLT s64 = LLT::scalar(64);
120
Igor Bregerd5b59cf2017-06-28 11:39:04 +0000121 for (unsigned BinOp : {G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR})
Igor Bregera8ba5722017-03-23 15:25:57 +0000122 for (auto Ty : {s8, s16, s32, s64})
123 setAction({BinOp, Ty}, Legal);
124
125 for (unsigned MemOp : {G_LOAD, G_STORE}) {
126 for (auto Ty : {s8, s16, s32, s64, p0})
127 setAction({MemOp, Ty}, Legal);
128
129 // And everything's fine in addrspace 0.
130 setAction({MemOp, 1, p0}, Legal);
131 }
Igor Breger531a2032017-03-26 08:11:12 +0000132
133 // Pointer-handling
134 setAction({G_FRAME_INDEX, p0}, Legal);
Igor Breger717bd362017-07-02 08:58:29 +0000135 setAction({G_GLOBAL_VALUE, p0}, Legal);
Igor Breger29537882017-04-07 14:41:59 +0000136
Igor Breger810c6252017-05-08 09:40:43 +0000137 setAction({G_GEP, p0}, Legal);
138 setAction({G_GEP, 1, s32}, Legal);
139 setAction({G_GEP, 1, s64}, Legal);
140
141 for (auto Ty : {s1, s8, s16})
142 setAction({G_GEP, 1, Ty}, WidenScalar);
143
Igor Breger29537882017-04-07 14:41:59 +0000144 // Constants
145 for (auto Ty : {s8, s16, s32, s64, p0})
146 setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
147
148 setAction({TargetOpcode::G_CONSTANT, s1}, WidenScalar);
Igor Bregerc08a7832017-05-01 06:30:16 +0000149
150 // Extensions
151 for (auto Ty : {s32, s64}) {
152 setAction({G_ZEXT, Ty}, Legal);
153 setAction({G_SEXT, Ty}, Legal);
154 }
155
Igor Bregerfda31e62017-05-10 06:52:58 +0000156 for (auto Ty : {s1, s8, s16, s32}) {
Igor Bregerc08a7832017-05-01 06:30:16 +0000157 setAction({G_ZEXT, 1, Ty}, Legal);
158 setAction({G_SEXT, 1, Ty}, Legal);
159 }
Igor Bregerc7b59772017-05-11 07:17:40 +0000160
161 // Comparison
162 setAction({G_ICMP, s1}, Legal);
163
164 for (auto Ty : {s8, s16, s32, s64, p0})
165 setAction({G_ICMP, 1, Ty}, Legal);
Igor Breger321cf3c2017-03-03 08:06:46 +0000166}
167
168void X86LegalizerInfo::setLegalizerInfoSSE1() {
169 if (!Subtarget.hasSSE1())
170 return;
171
172 const LLT s32 = LLT::scalar(32);
173 const LLT v4s32 = LLT::vector(4, 32);
Igor Bregera8ba5722017-03-23 15:25:57 +0000174 const LLT v2s64 = LLT::vector(2, 64);
Igor Breger321cf3c2017-03-03 08:06:46 +0000175
176 for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
177 for (auto Ty : {s32, v4s32})
178 setAction({BinOp, Ty}, Legal);
Igor Bregera8ba5722017-03-23 15:25:57 +0000179
180 for (unsigned MemOp : {G_LOAD, G_STORE})
181 for (auto Ty : {v4s32, v2s64})
182 setAction({MemOp, Ty}, Legal);
Igor Breger321cf3c2017-03-03 08:06:46 +0000183}
184
185void X86LegalizerInfo::setLegalizerInfoSSE2() {
186 if (!Subtarget.hasSSE2())
187 return;
188
189 const LLT s64 = LLT::scalar(64);
Igor Breger842b5b32017-05-18 11:10:56 +0000190 const LLT v16s8 = LLT::vector(16, 8);
Igor Breger605b9652017-05-08 09:03:37 +0000191 const LLT v8s16 = LLT::vector(8, 16);
Igor Breger321cf3c2017-03-03 08:06:46 +0000192 const LLT v4s32 = LLT::vector(4, 32);
193 const LLT v2s64 = LLT::vector(2, 64);
194
195 for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
196 for (auto Ty : {s64, v2s64})
197 setAction({BinOp, Ty}, Legal);
198
199 for (unsigned BinOp : {G_ADD, G_SUB})
Igor Breger842b5b32017-05-18 11:10:56 +0000200 for (auto Ty : {v16s8, v8s16, v4s32, v2s64})
Igor Breger321cf3c2017-03-03 08:06:46 +0000201 setAction({BinOp, Ty}, Legal);
Igor Breger605b9652017-05-08 09:03:37 +0000202
203 setAction({G_MUL, v8s16}, Legal);
204}
205
206void X86LegalizerInfo::setLegalizerInfoSSE41() {
207 if (!Subtarget.hasSSE41())
208 return;
209
210 const LLT v4s32 = LLT::vector(4, 32);
211
212 setAction({G_MUL, v4s32}, Legal);
213}
214
Igor Breger617be6e2017-05-23 08:23:51 +0000215void X86LegalizerInfo::setLegalizerInfoAVX() {
216 if (!Subtarget.hasAVX())
217 return;
218
Igor Breger1c29be72017-06-22 09:43:35 +0000219 const LLT v16s8 = LLT::vector(16, 8);
220 const LLT v8s16 = LLT::vector(8, 16);
221 const LLT v4s32 = LLT::vector(4, 32);
222 const LLT v2s64 = LLT::vector(2, 64);
223
224 const LLT v32s8 = LLT::vector(32, 8);
225 const LLT v16s16 = LLT::vector(16, 16);
Igor Breger617be6e2017-05-23 08:23:51 +0000226 const LLT v8s32 = LLT::vector(8, 32);
227 const LLT v4s64 = LLT::vector(4, 64);
228
229 for (unsigned MemOp : {G_LOAD, G_STORE})
230 for (auto Ty : {v8s32, v4s64})
231 setAction({MemOp, Ty}, Legal);
Igor Breger1c29be72017-06-22 09:43:35 +0000232
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000233 for (auto Ty : {v32s8, v16s16, v8s32, v4s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000234 setAction({G_INSERT, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000235 setAction({G_EXTRACT, 1, Ty}, Legal);
236 }
237 for (auto Ty : {v16s8, v8s16, v4s32, v2s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000238 setAction({G_INSERT, 1, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000239 setAction({G_EXTRACT, Ty}, Legal);
240 }
Igor Breger617be6e2017-05-23 08:23:51 +0000241}
242
Igor Breger605b9652017-05-08 09:03:37 +0000243void X86LegalizerInfo::setLegalizerInfoAVX2() {
244 if (!Subtarget.hasAVX2())
245 return;
246
Igor Breger842b5b32017-05-18 11:10:56 +0000247 const LLT v32s8 = LLT::vector(32, 8);
Igor Breger605b9652017-05-08 09:03:37 +0000248 const LLT v16s16 = LLT::vector(16, 16);
249 const LLT v8s32 = LLT::vector(8, 32);
Igor Breger842b5b32017-05-18 11:10:56 +0000250 const LLT v4s64 = LLT::vector(4, 64);
251
252 for (unsigned BinOp : {G_ADD, G_SUB})
253 for (auto Ty : {v32s8, v16s16, v8s32, v4s64})
254 setAction({BinOp, Ty}, Legal);
Igor Breger605b9652017-05-08 09:03:37 +0000255
256 for (auto Ty : {v16s16, v8s32})
257 setAction({G_MUL, Ty}, Legal);
258}
259
260void X86LegalizerInfo::setLegalizerInfoAVX512() {
261 if (!Subtarget.hasAVX512())
262 return;
263
Igor Breger1c29be72017-06-22 09:43:35 +0000264 const LLT v16s8 = LLT::vector(16, 8);
265 const LLT v8s16 = LLT::vector(8, 16);
266 const LLT v4s32 = LLT::vector(4, 32);
267 const LLT v2s64 = LLT::vector(2, 64);
268
269 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
274 const LLT v64s8 = LLT::vector(64, 8);
275 const LLT v32s16 = LLT::vector(32, 16);
Igor Breger605b9652017-05-08 09:03:37 +0000276 const LLT v16s32 = LLT::vector(16, 32);
Igor Breger842b5b32017-05-18 11:10:56 +0000277 const LLT v8s64 = LLT::vector(8, 64);
278
279 for (unsigned BinOp : {G_ADD, G_SUB})
280 for (auto Ty : {v16s32, v8s64})
281 setAction({BinOp, Ty}, Legal);
Igor Breger605b9652017-05-08 09:03:37 +0000282
283 setAction({G_MUL, v16s32}, Legal);
284
Igor Breger617be6e2017-05-23 08:23:51 +0000285 for (unsigned MemOp : {G_LOAD, G_STORE})
286 for (auto Ty : {v16s32, v8s64})
287 setAction({MemOp, Ty}, Legal);
288
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000289 for (auto Ty : {v64s8, v32s16, v16s32, v8s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000290 setAction({G_INSERT, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000291 setAction({G_EXTRACT, 1, Ty}, Legal);
292 }
293 for (auto Ty : {v32s8, v16s16, v8s32, v4s64, v16s8, v8s16, v4s32, v2s64}) {
Igor Breger1c29be72017-06-22 09:43:35 +0000294 setAction({G_INSERT, 1, Ty}, Legal);
Tim Northoverc2d5e6d2017-06-26 20:34:13 +0000295 setAction({G_EXTRACT, Ty}, Legal);
296 }
Igor Breger1c29be72017-06-22 09:43:35 +0000297
Igor Breger605b9652017-05-08 09:03:37 +0000298 /************ VLX *******************/
299 if (!Subtarget.hasVLX())
300 return;
301
Igor Breger605b9652017-05-08 09:03:37 +0000302 for (auto Ty : {v4s32, v8s32})
303 setAction({G_MUL, Ty}, Legal);
304}
305
306void X86LegalizerInfo::setLegalizerInfoAVX512DQ() {
307 if (!(Subtarget.hasAVX512() && Subtarget.hasDQI()))
308 return;
309
310 const LLT v8s64 = LLT::vector(8, 64);
311
312 setAction({G_MUL, v8s64}, Legal);
313
314 /************ VLX *******************/
315 if (!Subtarget.hasVLX())
316 return;
317
318 const LLT v2s64 = LLT::vector(2, 64);
319 const LLT v4s64 = LLT::vector(4, 64);
320
321 for (auto Ty : {v2s64, v4s64})
322 setAction({G_MUL, Ty}, Legal);
323}
324
325void X86LegalizerInfo::setLegalizerInfoAVX512BW() {
326 if (!(Subtarget.hasAVX512() && Subtarget.hasBWI()))
327 return;
328
Igor Breger842b5b32017-05-18 11:10:56 +0000329 const LLT v64s8 = LLT::vector(64, 8);
Igor Breger605b9652017-05-08 09:03:37 +0000330 const LLT v32s16 = LLT::vector(32, 16);
331
Igor Breger842b5b32017-05-18 11:10:56 +0000332 for (unsigned BinOp : {G_ADD, G_SUB})
333 for (auto Ty : {v64s8, v32s16})
334 setAction({BinOp, Ty}, Legal);
335
Igor Breger605b9652017-05-08 09:03:37 +0000336 setAction({G_MUL, v32s16}, Legal);
337
338 /************ VLX *******************/
339 if (!Subtarget.hasVLX())
340 return;
341
342 const LLT v8s16 = LLT::vector(8, 16);
343 const LLT v16s16 = LLT::vector(16, 16);
344
345 for (auto Ty : {v8s16, v16s16})
346 setAction({G_MUL, Ty}, Legal);
Igor Bregerb4442f32017-02-10 07:05:56 +0000347}