blob: da724f5d898934ffcef76fc431a3f8e247e41d9b [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();
38 setLegalizerInfoAVX2();
39 setLegalizerInfoAVX512();
40 setLegalizerInfoAVX512DQ();
41 setLegalizerInfoAVX512BW();
Igor Bregerb4442f32017-02-10 07:05:56 +000042
43 computeTables();
44}
45
46void X86LegalizerInfo::setLegalizerInfo32bit() {
47
Igor Bregera8ba5722017-03-23 15:25:57 +000048 if (Subtarget.is64Bit())
49 return;
50
51 const LLT p0 = LLT::pointer(0, 32);
Igor Breger29537882017-04-07 14:41:59 +000052 const LLT s1 = LLT::scalar(1);
Igor Bregerb4442f32017-02-10 07:05:56 +000053 const LLT s8 = LLT::scalar(8);
54 const LLT s16 = LLT::scalar(16);
55 const LLT s32 = LLT::scalar(32);
Igor Breger29537882017-04-07 14:41:59 +000056 const LLT s64 = LLT::scalar(64);
Igor Bregerb4442f32017-02-10 07:05:56 +000057
Igor Breger605b9652017-05-08 09:03:37 +000058 for (unsigned BinOp : {G_ADD, G_SUB, G_MUL})
Igor Bregera8ba5722017-03-23 15:25:57 +000059 for (auto Ty : {s8, s16, s32})
60 setAction({BinOp, Ty}, Legal);
61
Igor Breger28f290f2017-05-17 12:48:08 +000062 for (unsigned Op : {G_UADDE}) {
63 setAction({Op, s32}, Legal);
64 setAction({Op, 1, s1}, Legal);
65 }
66
Igor Bregera8ba5722017-03-23 15:25:57 +000067 for (unsigned MemOp : {G_LOAD, G_STORE}) {
68 for (auto Ty : {s8, s16, s32, p0})
69 setAction({MemOp, Ty}, Legal);
70
71 // And everything's fine in addrspace 0.
72 setAction({MemOp, 1, p0}, Legal);
Igor Bregerf7359d82017-02-22 12:25:09 +000073 }
Igor Breger531a2032017-03-26 08:11:12 +000074
75 // Pointer-handling
76 setAction({G_FRAME_INDEX, p0}, Legal);
Igor Breger29537882017-04-07 14:41:59 +000077
Igor Breger810c6252017-05-08 09:40:43 +000078 setAction({G_GEP, p0}, Legal);
79 setAction({G_GEP, 1, s32}, Legal);
80
81 for (auto Ty : {s1, s8, s16})
82 setAction({G_GEP, 1, Ty}, WidenScalar);
83
Igor Breger29537882017-04-07 14:41:59 +000084 // Constants
85 for (auto Ty : {s8, s16, s32, p0})
86 setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
87
88 setAction({TargetOpcode::G_CONSTANT, s1}, WidenScalar);
89 setAction({TargetOpcode::G_CONSTANT, s64}, NarrowScalar);
Igor Bregerc08a7832017-05-01 06:30:16 +000090
91 // Extensions
92 setAction({G_ZEXT, s32}, Legal);
93 setAction({G_SEXT, s32}, Legal);
94
Igor Bregerfda31e62017-05-10 06:52:58 +000095 for (auto Ty : {s1, s8, s16}) {
Igor Bregerc08a7832017-05-01 06:30:16 +000096 setAction({G_ZEXT, 1, Ty}, Legal);
97 setAction({G_SEXT, 1, Ty}, Legal);
98 }
Igor Bregerc7b59772017-05-11 07:17:40 +000099
100 // Comparison
101 setAction({G_ICMP, s1}, Legal);
102
103 for (auto Ty : {s8, s16, s32, p0})
104 setAction({G_ICMP, 1, Ty}, Legal);
Igor Bregerb4442f32017-02-10 07:05:56 +0000105}
Igor Bregerb4442f32017-02-10 07:05:56 +0000106
Igor Bregerf7359d82017-02-22 12:25:09 +0000107void X86LegalizerInfo::setLegalizerInfo64bit() {
Igor Bregerb4442f32017-02-10 07:05:56 +0000108
109 if (!Subtarget.is64Bit())
110 return;
111
Igor Breger531a2032017-03-26 08:11:12 +0000112 const LLT p0 = LLT::pointer(0, TM.getPointerSize() * 8);
Igor Breger29537882017-04-07 14:41:59 +0000113 const LLT s1 = LLT::scalar(1);
Igor Bregera8ba5722017-03-23 15:25:57 +0000114 const LLT s8 = LLT::scalar(8);
115 const LLT s16 = LLT::scalar(16);
116 const LLT s32 = LLT::scalar(32);
Igor Bregerb4442f32017-02-10 07:05:56 +0000117 const LLT s64 = LLT::scalar(64);
118
Igor Breger605b9652017-05-08 09:03:37 +0000119 for (unsigned BinOp : {G_ADD, G_SUB, G_MUL})
Igor Bregera8ba5722017-03-23 15:25:57 +0000120 for (auto Ty : {s8, s16, s32, s64})
121 setAction({BinOp, Ty}, Legal);
122
123 for (unsigned MemOp : {G_LOAD, G_STORE}) {
124 for (auto Ty : {s8, s16, s32, s64, p0})
125 setAction({MemOp, Ty}, Legal);
126
127 // And everything's fine in addrspace 0.
128 setAction({MemOp, 1, p0}, Legal);
129 }
Igor Breger531a2032017-03-26 08:11:12 +0000130
131 // Pointer-handling
132 setAction({G_FRAME_INDEX, p0}, Legal);
Igor Breger29537882017-04-07 14:41:59 +0000133
Igor Breger810c6252017-05-08 09:40:43 +0000134 setAction({G_GEP, p0}, Legal);
135 setAction({G_GEP, 1, s32}, Legal);
136 setAction({G_GEP, 1, s64}, Legal);
137
138 for (auto Ty : {s1, s8, s16})
139 setAction({G_GEP, 1, Ty}, WidenScalar);
140
Igor Breger29537882017-04-07 14:41:59 +0000141 // Constants
142 for (auto Ty : {s8, s16, s32, s64, p0})
143 setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
144
145 setAction({TargetOpcode::G_CONSTANT, s1}, WidenScalar);
Igor Bregerc08a7832017-05-01 06:30:16 +0000146
147 // Extensions
148 for (auto Ty : {s32, s64}) {
149 setAction({G_ZEXT, Ty}, Legal);
150 setAction({G_SEXT, Ty}, Legal);
151 }
152
Igor Bregerfda31e62017-05-10 06:52:58 +0000153 for (auto Ty : {s1, s8, s16, s32}) {
Igor Bregerc08a7832017-05-01 06:30:16 +0000154 setAction({G_ZEXT, 1, Ty}, Legal);
155 setAction({G_SEXT, 1, Ty}, Legal);
156 }
Igor Bregerc7b59772017-05-11 07:17:40 +0000157
158 // Comparison
159 setAction({G_ICMP, s1}, Legal);
160
161 for (auto Ty : {s8, s16, s32, s64, p0})
162 setAction({G_ICMP, 1, Ty}, Legal);
Igor Breger321cf3c2017-03-03 08:06:46 +0000163}
164
165void X86LegalizerInfo::setLegalizerInfoSSE1() {
166 if (!Subtarget.hasSSE1())
167 return;
168
169 const LLT s32 = LLT::scalar(32);
170 const LLT v4s32 = LLT::vector(4, 32);
Igor Bregera8ba5722017-03-23 15:25:57 +0000171 const LLT v2s64 = LLT::vector(2, 64);
Igor Breger321cf3c2017-03-03 08:06:46 +0000172
173 for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
174 for (auto Ty : {s32, v4s32})
175 setAction({BinOp, Ty}, Legal);
Igor Bregera8ba5722017-03-23 15:25:57 +0000176
177 for (unsigned MemOp : {G_LOAD, G_STORE})
178 for (auto Ty : {v4s32, v2s64})
179 setAction({MemOp, Ty}, Legal);
Igor Breger321cf3c2017-03-03 08:06:46 +0000180}
181
182void X86LegalizerInfo::setLegalizerInfoSSE2() {
183 if (!Subtarget.hasSSE2())
184 return;
185
186 const LLT s64 = LLT::scalar(64);
Igor Breger842b5b32017-05-18 11:10:56 +0000187 const LLT v16s8 = LLT::vector(16, 8);
Igor Breger605b9652017-05-08 09:03:37 +0000188 const LLT v8s16 = LLT::vector(8, 16);
Igor Breger321cf3c2017-03-03 08:06:46 +0000189 const LLT v4s32 = LLT::vector(4, 32);
190 const LLT v2s64 = LLT::vector(2, 64);
191
192 for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
193 for (auto Ty : {s64, v2s64})
194 setAction({BinOp, Ty}, Legal);
195
196 for (unsigned BinOp : {G_ADD, G_SUB})
Igor Breger842b5b32017-05-18 11:10:56 +0000197 for (auto Ty : {v16s8, v8s16, v4s32, v2s64})
Igor Breger321cf3c2017-03-03 08:06:46 +0000198 setAction({BinOp, Ty}, Legal);
Igor Breger605b9652017-05-08 09:03:37 +0000199
200 setAction({G_MUL, v8s16}, Legal);
201}
202
203void X86LegalizerInfo::setLegalizerInfoSSE41() {
204 if (!Subtarget.hasSSE41())
205 return;
206
207 const LLT v4s32 = LLT::vector(4, 32);
208
209 setAction({G_MUL, v4s32}, Legal);
210}
211
212void X86LegalizerInfo::setLegalizerInfoAVX2() {
213 if (!Subtarget.hasAVX2())
214 return;
215
Igor Breger842b5b32017-05-18 11:10:56 +0000216 const LLT v32s8 = LLT::vector(32, 8);
Igor Breger605b9652017-05-08 09:03:37 +0000217 const LLT v16s16 = LLT::vector(16, 16);
218 const LLT v8s32 = LLT::vector(8, 32);
Igor Breger842b5b32017-05-18 11:10:56 +0000219 const LLT v4s64 = LLT::vector(4, 64);
220
221 for (unsigned BinOp : {G_ADD, G_SUB})
222 for (auto Ty : {v32s8, v16s16, v8s32, v4s64})
223 setAction({BinOp, Ty}, Legal);
Igor Breger605b9652017-05-08 09:03:37 +0000224
225 for (auto Ty : {v16s16, v8s32})
226 setAction({G_MUL, Ty}, Legal);
227}
228
229void X86LegalizerInfo::setLegalizerInfoAVX512() {
230 if (!Subtarget.hasAVX512())
231 return;
232
233 const LLT v16s32 = LLT::vector(16, 32);
Igor Breger842b5b32017-05-18 11:10:56 +0000234 const LLT v8s64 = LLT::vector(8, 64);
235
236 for (unsigned BinOp : {G_ADD, G_SUB})
237 for (auto Ty : {v16s32, v8s64})
238 setAction({BinOp, Ty}, Legal);
Igor Breger605b9652017-05-08 09:03:37 +0000239
240 setAction({G_MUL, v16s32}, Legal);
241
242 /************ VLX *******************/
243 if (!Subtarget.hasVLX())
244 return;
245
246 const LLT v4s32 = LLT::vector(4, 32);
247 const LLT v8s32 = LLT::vector(8, 32);
248
249 for (auto Ty : {v4s32, v8s32})
250 setAction({G_MUL, Ty}, Legal);
251}
252
253void X86LegalizerInfo::setLegalizerInfoAVX512DQ() {
254 if (!(Subtarget.hasAVX512() && Subtarget.hasDQI()))
255 return;
256
257 const LLT v8s64 = LLT::vector(8, 64);
258
259 setAction({G_MUL, v8s64}, Legal);
260
261 /************ VLX *******************/
262 if (!Subtarget.hasVLX())
263 return;
264
265 const LLT v2s64 = LLT::vector(2, 64);
266 const LLT v4s64 = LLT::vector(4, 64);
267
268 for (auto Ty : {v2s64, v4s64})
269 setAction({G_MUL, Ty}, Legal);
270}
271
272void X86LegalizerInfo::setLegalizerInfoAVX512BW() {
273 if (!(Subtarget.hasAVX512() && Subtarget.hasBWI()))
274 return;
275
Igor Breger842b5b32017-05-18 11:10:56 +0000276 const LLT v64s8 = LLT::vector(64, 8);
Igor Breger605b9652017-05-08 09:03:37 +0000277 const LLT v32s16 = LLT::vector(32, 16);
278
Igor Breger842b5b32017-05-18 11:10:56 +0000279 for (unsigned BinOp : {G_ADD, G_SUB})
280 for (auto Ty : {v64s8, v32s16})
281 setAction({BinOp, Ty}, Legal);
282
Igor Breger605b9652017-05-08 09:03:37 +0000283 setAction({G_MUL, v32s16}, Legal);
284
285 /************ VLX *******************/
286 if (!Subtarget.hasVLX())
287 return;
288
289 const LLT v8s16 = LLT::vector(8, 16);
290 const LLT v16s16 = LLT::vector(16, 16);
291
292 for (auto Ty : {v8s16, v16s16})
293 setAction({G_MUL, Ty}, Legal);
Igor Bregerb4442f32017-02-10 07:05:56 +0000294}