[InstCombine] Remove insertRangeTest code that handles the equality case.
[llvm-complete.git] / lib / CodeGen / ValueTypes.cpp
bloba911cdcbec9db3d8d461b8db510e7359201e5ee6
1 //===----------- ValueTypes.cpp - Implementation of EVT methods -----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/CodeGen/ValueTypes.h"
10 #include "llvm/ADT/StringExtras.h"
11 #include "llvm/IR/DerivedTypes.h"
12 #include "llvm/IR/Type.h"
13 #include "llvm/Support/ErrorHandling.h"
14 using namespace llvm;
16 EVT EVT::changeExtendedTypeToInteger() const {
17 LLVMContext &Context = LLVMTy->getContext();
18 return getIntegerVT(Context, getSizeInBits());
21 EVT EVT::changeExtendedVectorElementTypeToInteger() const {
22 LLVMContext &Context = LLVMTy->getContext();
23 EVT IntTy = getIntegerVT(Context, getScalarSizeInBits());
24 return getVectorVT(Context, IntTy, getVectorNumElements());
27 EVT EVT::getExtendedIntegerVT(LLVMContext &Context, unsigned BitWidth) {
28 EVT VT;
29 VT.LLVMTy = IntegerType::get(Context, BitWidth);
30 assert(VT.isExtended() && "Type is not extended!");
31 return VT;
34 EVT EVT::getExtendedVectorVT(LLVMContext &Context, EVT VT,
35 unsigned NumElements) {
36 EVT ResultVT;
37 ResultVT.LLVMTy = VectorType::get(VT.getTypeForEVT(Context), NumElements);
38 assert(ResultVT.isExtended() && "Type is not extended!");
39 return ResultVT;
42 bool EVT::isExtendedFloatingPoint() const {
43 assert(isExtended() && "Type is not extended!");
44 return LLVMTy->isFPOrFPVectorTy();
47 bool EVT::isExtendedInteger() const {
48 assert(isExtended() && "Type is not extended!");
49 return LLVMTy->isIntOrIntVectorTy();
52 bool EVT::isExtendedScalarInteger() const {
53 assert(isExtended() && "Type is not extended!");
54 return LLVMTy->isIntegerTy();
57 bool EVT::isExtendedVector() const {
58 assert(isExtended() && "Type is not extended!");
59 return LLVMTy->isVectorTy();
62 bool EVT::isExtended16BitVector() const {
63 return isExtendedVector() && getExtendedSizeInBits() == 16;
66 bool EVT::isExtended32BitVector() const {
67 return isExtendedVector() && getExtendedSizeInBits() == 32;
70 bool EVT::isExtended64BitVector() const {
71 return isExtendedVector() && getExtendedSizeInBits() == 64;
74 bool EVT::isExtended128BitVector() const {
75 return isExtendedVector() && getExtendedSizeInBits() == 128;
78 bool EVT::isExtended256BitVector() const {
79 return isExtendedVector() && getExtendedSizeInBits() == 256;
82 bool EVT::isExtended512BitVector() const {
83 return isExtendedVector() && getExtendedSizeInBits() == 512;
86 bool EVT::isExtended1024BitVector() const {
87 return isExtendedVector() && getExtendedSizeInBits() == 1024;
90 bool EVT::isExtended2048BitVector() const {
91 return isExtendedVector() && getExtendedSizeInBits() == 2048;
94 EVT EVT::getExtendedVectorElementType() const {
95 assert(isExtended() && "Type is not extended!");
96 return EVT::getEVT(cast<VectorType>(LLVMTy)->getElementType());
99 unsigned EVT::getExtendedVectorNumElements() const {
100 assert(isExtended() && "Type is not extended!");
101 return cast<VectorType>(LLVMTy)->getNumElements();
104 unsigned EVT::getExtendedSizeInBits() const {
105 assert(isExtended() && "Type is not extended!");
106 if (IntegerType *ITy = dyn_cast<IntegerType>(LLVMTy))
107 return ITy->getBitWidth();
108 if (VectorType *VTy = dyn_cast<VectorType>(LLVMTy))
109 return VTy->getBitWidth();
110 llvm_unreachable("Unrecognized extended type!");
113 /// getEVTString - This function returns value type as a string, e.g. "i32".
114 std::string EVT::getEVTString() const {
115 switch (V.SimpleTy) {
116 default:
117 if (isVector())
118 return "v" + utostr(getVectorNumElements()) +
119 getVectorElementType().getEVTString();
120 if (isInteger())
121 return "i" + utostr(getSizeInBits());
122 llvm_unreachable("Invalid EVT!");
123 case MVT::i1: return "i1";
124 case MVT::i8: return "i8";
125 case MVT::i16: return "i16";
126 case MVT::i32: return "i32";
127 case MVT::i64: return "i64";
128 case MVT::i128: return "i128";
129 case MVT::f16: return "f16";
130 case MVT::f32: return "f32";
131 case MVT::f64: return "f64";
132 case MVT::f80: return "f80";
133 case MVT::f128: return "f128";
134 case MVT::ppcf128: return "ppcf128";
135 case MVT::isVoid: return "isVoid";
136 case MVT::Other: return "ch";
137 case MVT::Glue: return "glue";
138 case MVT::x86mmx: return "x86mmx";
139 case MVT::v1i1: return "v1i1";
140 case MVT::v2i1: return "v2i1";
141 case MVT::v4i1: return "v4i1";
142 case MVT::v8i1: return "v8i1";
143 case MVT::v16i1: return "v16i1";
144 case MVT::v32i1: return "v32i1";
145 case MVT::v64i1: return "v64i1";
146 case MVT::v128i1: return "v128i1";
147 case MVT::v512i1: return "v512i1";
148 case MVT::v1024i1: return "v1024i1";
149 case MVT::v1i8: return "v1i8";
150 case MVT::v2i8: return "v2i8";
151 case MVT::v4i8: return "v4i8";
152 case MVT::v8i8: return "v8i8";
153 case MVT::v16i8: return "v16i8";
154 case MVT::v32i8: return "v32i8";
155 case MVT::v64i8: return "v64i8";
156 case MVT::v128i8: return "v128i8";
157 case MVT::v256i8: return "v256i8";
158 case MVT::v1i16: return "v1i16";
159 case MVT::v2i16: return "v2i16";
160 case MVT::v4i16: return "v4i16";
161 case MVT::v8i16: return "v8i16";
162 case MVT::v16i16: return "v16i16";
163 case MVT::v32i16: return "v32i16";
164 case MVT::v64i16: return "v64i16";
165 case MVT::v128i16: return "v128i16";
166 case MVT::v1i32: return "v1i32";
167 case MVT::v2i32: return "v2i32";
168 case MVT::v3i32: return "v3i32";
169 case MVT::v4i32: return "v4i32";
170 case MVT::v5i32: return "v5i32";
171 case MVT::v8i32: return "v8i32";
172 case MVT::v16i32: return "v16i32";
173 case MVT::v32i32: return "v32i32";
174 case MVT::v64i32: return "v64i32";
175 case MVT::v128i32: return "v128i32";
176 case MVT::v256i32: return "v256i32";
177 case MVT::v512i32: return "v512i32";
178 case MVT::v1024i32:return "v1024i32";
179 case MVT::v2048i32:return "v2048i32";
180 case MVT::v1i64: return "v1i64";
181 case MVT::v2i64: return "v2i64";
182 case MVT::v4i64: return "v4i64";
183 case MVT::v8i64: return "v8i64";
184 case MVT::v16i64: return "v16i64";
185 case MVT::v32i64: return "v32i64";
186 case MVT::v1i128: return "v1i128";
187 case MVT::v1f32: return "v1f32";
188 case MVT::v2f32: return "v2f32";
189 case MVT::v2f16: return "v2f16";
190 case MVT::v4f16: return "v4f16";
191 case MVT::v8f16: return "v8f16";
192 case MVT::v3f32: return "v3f32";
193 case MVT::v4f32: return "v4f32";
194 case MVT::v5f32: return "v5f32";
195 case MVT::v8f32: return "v8f32";
196 case MVT::v16f32: return "v16f32";
197 case MVT::v32f32: return "v32f32";
198 case MVT::v64f32: return "v64f32";
199 case MVT::v128f32: return "v128f32";
200 case MVT::v256f32: return "v256f32";
201 case MVT::v512f32: return "v512f32";
202 case MVT::v1024f32:return "v1024f32";
203 case MVT::v2048f32:return "v2048f32";
204 case MVT::v1f64: return "v1f64";
205 case MVT::v2f64: return "v2f64";
206 case MVT::v4f64: return "v4f64";
207 case MVT::v8f64: return "v8f64";
208 case MVT::Metadata:return "Metadata";
209 case MVT::Untyped: return "Untyped";
210 case MVT::exnref : return "exnref";
214 /// getTypeForEVT - This method returns an LLVM type corresponding to the
215 /// specified EVT. For integer types, this returns an unsigned type. Note
216 /// that this will abort for types that cannot be represented.
217 Type *EVT::getTypeForEVT(LLVMContext &Context) const {
218 switch (V.SimpleTy) {
219 default:
220 assert(isExtended() && "Type is not extended!");
221 return LLVMTy;
222 case MVT::isVoid: return Type::getVoidTy(Context);
223 case MVT::i1: return Type::getInt1Ty(Context);
224 case MVT::i8: return Type::getInt8Ty(Context);
225 case MVT::i16: return Type::getInt16Ty(Context);
226 case MVT::i32: return Type::getInt32Ty(Context);
227 case MVT::i64: return Type::getInt64Ty(Context);
228 case MVT::i128: return IntegerType::get(Context, 128);
229 case MVT::f16: return Type::getHalfTy(Context);
230 case MVT::f32: return Type::getFloatTy(Context);
231 case MVT::f64: return Type::getDoubleTy(Context);
232 case MVT::f80: return Type::getX86_FP80Ty(Context);
233 case MVT::f128: return Type::getFP128Ty(Context);
234 case MVT::ppcf128: return Type::getPPC_FP128Ty(Context);
235 case MVT::x86mmx: return Type::getX86_MMXTy(Context);
236 case MVT::v1i1: return VectorType::get(Type::getInt1Ty(Context), 1);
237 case MVT::v2i1: return VectorType::get(Type::getInt1Ty(Context), 2);
238 case MVT::v4i1: return VectorType::get(Type::getInt1Ty(Context), 4);
239 case MVT::v8i1: return VectorType::get(Type::getInt1Ty(Context), 8);
240 case MVT::v16i1: return VectorType::get(Type::getInt1Ty(Context), 16);
241 case MVT::v32i1: return VectorType::get(Type::getInt1Ty(Context), 32);
242 case MVT::v64i1: return VectorType::get(Type::getInt1Ty(Context), 64);
243 case MVT::v128i1: return VectorType::get(Type::getInt1Ty(Context), 128);
244 case MVT::v512i1: return VectorType::get(Type::getInt1Ty(Context), 512);
245 case MVT::v1024i1: return VectorType::get(Type::getInt1Ty(Context), 1024);
246 case MVT::v1i8: return VectorType::get(Type::getInt8Ty(Context), 1);
247 case MVT::v2i8: return VectorType::get(Type::getInt8Ty(Context), 2);
248 case MVT::v4i8: return VectorType::get(Type::getInt8Ty(Context), 4);
249 case MVT::v8i8: return VectorType::get(Type::getInt8Ty(Context), 8);
250 case MVT::v16i8: return VectorType::get(Type::getInt8Ty(Context), 16);
251 case MVT::v32i8: return VectorType::get(Type::getInt8Ty(Context), 32);
252 case MVT::v64i8: return VectorType::get(Type::getInt8Ty(Context), 64);
253 case MVT::v128i8: return VectorType::get(Type::getInt8Ty(Context), 128);
254 case MVT::v256i8: return VectorType::get(Type::getInt8Ty(Context), 256);
255 case MVT::v1i16: return VectorType::get(Type::getInt16Ty(Context), 1);
256 case MVT::v2i16: return VectorType::get(Type::getInt16Ty(Context), 2);
257 case MVT::v4i16: return VectorType::get(Type::getInt16Ty(Context), 4);
258 case MVT::v8i16: return VectorType::get(Type::getInt16Ty(Context), 8);
259 case MVT::v16i16: return VectorType::get(Type::getInt16Ty(Context), 16);
260 case MVT::v32i16: return VectorType::get(Type::getInt16Ty(Context), 32);
261 case MVT::v64i16: return VectorType::get(Type::getInt16Ty(Context), 64);
262 case MVT::v128i16: return VectorType::get(Type::getInt16Ty(Context), 128);
263 case MVT::v1i32: return VectorType::get(Type::getInt32Ty(Context), 1);
264 case MVT::v2i32: return VectorType::get(Type::getInt32Ty(Context), 2);
265 case MVT::v3i32: return VectorType::get(Type::getInt32Ty(Context), 3);
266 case MVT::v4i32: return VectorType::get(Type::getInt32Ty(Context), 4);
267 case MVT::v5i32: return VectorType::get(Type::getInt32Ty(Context), 5);
268 case MVT::v8i32: return VectorType::get(Type::getInt32Ty(Context), 8);
269 case MVT::v16i32: return VectorType::get(Type::getInt32Ty(Context), 16);
270 case MVT::v32i32: return VectorType::get(Type::getInt32Ty(Context), 32);
271 case MVT::v64i32: return VectorType::get(Type::getInt32Ty(Context), 64);
272 case MVT::v128i32: return VectorType::get(Type::getInt32Ty(Context), 128);
273 case MVT::v256i32: return VectorType::get(Type::getInt32Ty(Context), 256);
274 case MVT::v512i32: return VectorType::get(Type::getInt32Ty(Context), 512);
275 case MVT::v1024i32:return VectorType::get(Type::getInt32Ty(Context), 1024);
276 case MVT::v2048i32:return VectorType::get(Type::getInt32Ty(Context), 2048);
277 case MVT::v1i64: return VectorType::get(Type::getInt64Ty(Context), 1);
278 case MVT::v2i64: return VectorType::get(Type::getInt64Ty(Context), 2);
279 case MVT::v4i64: return VectorType::get(Type::getInt64Ty(Context), 4);
280 case MVT::v8i64: return VectorType::get(Type::getInt64Ty(Context), 8);
281 case MVT::v16i64: return VectorType::get(Type::getInt64Ty(Context), 16);
282 case MVT::v32i64: return VectorType::get(Type::getInt64Ty(Context), 32);
283 case MVT::v1i128: return VectorType::get(Type::getInt128Ty(Context), 1);
284 case MVT::v2f16: return VectorType::get(Type::getHalfTy(Context), 2);
285 case MVT::v4f16: return VectorType::get(Type::getHalfTy(Context), 4);
286 case MVT::v8f16: return VectorType::get(Type::getHalfTy(Context), 8);
287 case MVT::v1f32: return VectorType::get(Type::getFloatTy(Context), 1);
288 case MVT::v2f32: return VectorType::get(Type::getFloatTy(Context), 2);
289 case MVT::v3f32: return VectorType::get(Type::getFloatTy(Context), 3);
290 case MVT::v4f32: return VectorType::get(Type::getFloatTy(Context), 4);
291 case MVT::v5f32: return VectorType::get(Type::getFloatTy(Context), 5);
292 case MVT::v8f32: return VectorType::get(Type::getFloatTy(Context), 8);
293 case MVT::v16f32: return VectorType::get(Type::getFloatTy(Context), 16);
294 case MVT::v32f32: return VectorType::get(Type::getFloatTy(Context), 32);
295 case MVT::v64f32: return VectorType::get(Type::getFloatTy(Context), 64);
296 case MVT::v128f32: return VectorType::get(Type::getFloatTy(Context), 128);
297 case MVT::v256f32: return VectorType::get(Type::getFloatTy(Context), 256);
298 case MVT::v512f32: return VectorType::get(Type::getFloatTy(Context), 512);
299 case MVT::v1024f32:return VectorType::get(Type::getFloatTy(Context), 1024);
300 case MVT::v2048f32:return VectorType::get(Type::getFloatTy(Context), 2048);
301 case MVT::v1f64: return VectorType::get(Type::getDoubleTy(Context), 1);
302 case MVT::v2f64: return VectorType::get(Type::getDoubleTy(Context), 2);
303 case MVT::v4f64: return VectorType::get(Type::getDoubleTy(Context), 4);
304 case MVT::v8f64: return VectorType::get(Type::getDoubleTy(Context), 8);
305 case MVT::Metadata: return Type::getMetadataTy(Context);
309 /// Return the value type corresponding to the specified type. This returns all
310 /// pointers as MVT::iPTR. If HandleUnknown is true, unknown types are returned
311 /// as Other, otherwise they are invalid.
312 MVT MVT::getVT(Type *Ty, bool HandleUnknown){
313 switch (Ty->getTypeID()) {
314 default:
315 if (HandleUnknown) return MVT(MVT::Other);
316 llvm_unreachable("Unknown type!");
317 case Type::VoidTyID:
318 return MVT::isVoid;
319 case Type::IntegerTyID:
320 return getIntegerVT(cast<IntegerType>(Ty)->getBitWidth());
321 case Type::HalfTyID: return MVT(MVT::f16);
322 case Type::FloatTyID: return MVT(MVT::f32);
323 case Type::DoubleTyID: return MVT(MVT::f64);
324 case Type::X86_FP80TyID: return MVT(MVT::f80);
325 case Type::X86_MMXTyID: return MVT(MVT::x86mmx);
326 case Type::FP128TyID: return MVT(MVT::f128);
327 case Type::PPC_FP128TyID: return MVT(MVT::ppcf128);
328 case Type::PointerTyID: return MVT(MVT::iPTR);
329 case Type::VectorTyID: {
330 VectorType *VTy = cast<VectorType>(Ty);
331 return getVectorVT(
332 getVT(VTy->getElementType(), false), VTy->getNumElements());
337 /// getEVT - Return the value type corresponding to the specified type. This
338 /// returns all pointers as MVT::iPTR. If HandleUnknown is true, unknown types
339 /// are returned as Other, otherwise they are invalid.
340 EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
341 switch (Ty->getTypeID()) {
342 default:
343 return MVT::getVT(Ty, HandleUnknown);
344 case Type::IntegerTyID:
345 return getIntegerVT(Ty->getContext(), cast<IntegerType>(Ty)->getBitWidth());
346 case Type::VectorTyID: {
347 VectorType *VTy = cast<VectorType>(Ty);
348 return getVectorVT(Ty->getContext(), getEVT(VTy->getElementType(), false),
349 VTy->getNumElements());