clang 23.0.0git
CIRGenBuiltinX86.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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//===----------------------------------------------------------------------===//
8//
9// This contains code to emit x86/x86_64 Builtin calls as CIR or a function
10// call to be later resolved.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CIRGenBuilder.h"
15#include "CIRGenFunction.h"
16#include "CIRGenModule.h"
17#include "mlir/IR/Attributes.h"
18#include "mlir/IR/BuiltinAttributes.h"
19#include "mlir/IR/Location.h"
20#include "mlir/IR/Types.h"
21#include "mlir/IR/ValueRange.h"
27#include "llvm/ADT/Sequence.h"
28#include "llvm/Support/ErrorHandling.h"
29#include <string>
30
31using namespace clang;
32using namespace clang::CIRGen;
33
34// OG has unordered comparison as a form of optimization in addition to
35// ordered comparison, while CIR doesn't.
36//
37// This means that we can't encode the comparison code of UGT (unordered
38// greater than), at least not at the CIR level.
39//
40// The boolean shouldInvert compensates for this.
41// For example: to get to the comparison code UGT, we pass in
42// emitVectorFCmp (OLE, shouldInvert = true) since OLE is the inverse of UGT.
43
44// There are several ways to support this otherwise:
45// - register extra CmpOpKind for unordered comparison types and build the
46// translation code for
47// to go from CIR -> LLVM dialect. Notice we get this naturally with
48// shouldInvert, benefiting from existing infrastructure, albeit having to
49// generate an extra `not` at CIR).
50// - Just add extra comparison code to a new VecCmpOpKind instead of
51// cluttering CmpOpKind.
52// - Add a boolean in VecCmpOp to indicate if it's doing unordered or ordered
53// comparison
54// - Just emit the intrinsics call instead of calling this helper, see how the
55// LLVM lowering handles this.
56static mlir::Value emitVectorFCmp(CIRGenFunction &cgf, const CallExpr &expr,
58 cir::CmpOpKind pred, bool shouldInvert) {
60 // TODO(cir): Add isSignaling boolean once emitConstrainedFPCall implemented
63 mlir::Value cmp = builder.createVecCompare(cgf.getLoc(expr.getExprLoc()),
64 pred, ops[0], ops[1]);
65 mlir::Value bitCast = builder.createBitcast(
66 shouldInvert ? builder.createNot(cmp) : cmp, ops[0].getType());
67 return bitCast;
68}
69
70static mlir::Value getMaskVecValue(CIRGenBuilderTy &builder, mlir::Location loc,
71 mlir::Value mask, unsigned numElems) {
72 auto maskTy = cir::VectorType::get(
73 builder.getSIntNTy(1), cast<cir::IntType>(mask.getType()).getWidth());
74 mlir::Value maskVec = builder.createBitcast(mask, maskTy);
75
76 // If we have less than 8 elements, then the starting mask was an i8 and
77 // we need to extract down to the right number of elements.
78 if (numElems < 8) {
80 mlir::Type i32Ty = builder.getSInt32Ty();
81 for (auto i : llvm::seq<unsigned>(0, numElems))
82 indices.push_back(cir::IntAttr::get(i32Ty, i));
83
84 maskVec = builder.createVecShuffle(loc, maskVec, maskVec, indices);
85 }
86 return maskVec;
87}
88
89static mlir::Value emitX86CompressStore(CIRGenBuilderTy &builder,
90 mlir::Location loc,
92 auto resultTy = cast<cir::VectorType>(ops[1].getType());
93 mlir::Value maskValue =
94 getMaskVecValue(builder, loc, ops[2], resultTy.getSize());
95
96 return builder.emitIntrinsicCallOp(
97 loc, "masked.compressstore", cir::VoidType::get(builder.getContext()),
98 mlir::ValueRange{ops[1], ops[0], maskValue});
99}
100
101// Builds the VecShuffleOp for pshuflw and pshufhw x86 builtins.
102//
103// The vector is split into lanes of 8 word elements (16 bits). The lower or
104// upper half of each lane, controlled by `isLow`, is shuffled in the following
105// way: The immediate is truncated to 8 bits, separated into 4 2-bit fields. The
106// i-th field's value represents the resulting index of the i-th element in the
107// half lane after shuffling. The other half of the lane remains unchanged.
108static cir::VecShuffleOp emitPshufWord(CIRGenBuilderTy &builder,
109 const mlir::Value vec,
110 const mlir::Value immediate,
111 const mlir::Location loc,
112 const bool isLow) {
113 uint32_t imm = CIRGenFunction::getZExtIntValueFromConstOp(immediate);
114
115 auto vecTy = cast<cir::VectorType>(vec.getType());
116 unsigned numElts = vecTy.getSize();
117
118 unsigned firstHalfStart = isLow ? 0 : 4;
119 unsigned secondHalfStart = 4 - firstHalfStart;
120
121 // Splat the 8-bits of immediate 4 times to help the loop wrap around.
122 imm = (imm & 0xff) * 0x01010101;
123
124 int64_t indices[32];
125 for (unsigned l = 0; l != numElts; l += 8) {
126 for (unsigned i = firstHalfStart; i != firstHalfStart + 4; ++i) {
127 indices[l + i] = l + (imm & 3) + firstHalfStart;
128 imm >>= 2;
129 }
130 for (unsigned i = secondHalfStart; i != secondHalfStart + 4; ++i)
131 indices[l + i] = l + i;
132 }
133
134 return builder.createVecShuffle(loc, vec, ArrayRef(indices, numElts));
135}
136
137// Builds the shuffle mask for pshufd and shufpd/shufps x86 builtins.
138// The shuffle mask is written to outIndices.
139static void
140computeFullLaneShuffleMask(CIRGenFunction &cgf, const mlir::Value vec,
141 uint32_t imm, const bool isShufP,
142 llvm::SmallVectorImpl<int64_t> &outIndices) {
143 auto vecTy = cast<cir::VectorType>(vec.getType());
144 unsigned numElts = vecTy.getSize();
145 unsigned numLanes = cgf.cgm.getDataLayout().getTypeSizeInBits(vecTy) / 128;
146 unsigned numLaneElts = numElts / numLanes;
147
148 // Splat the 8-bits of immediate 4 times to help the loop wrap around.
149 imm = (imm & 0xff) * 0x01010101;
150
151 for (unsigned l = 0; l != numElts; l += numLaneElts) {
152 for (unsigned i = 0; i != numLaneElts; ++i) {
153 uint32_t idx = imm % numLaneElts;
154 imm /= numLaneElts;
155 if (isShufP && i >= (numLaneElts / 2))
156 idx += numElts;
157 outIndices[l + i] = l + idx;
158 }
159 }
160
161 outIndices.resize(numElts);
162}
163
164static mlir::Value emitPrefetch(CIRGenFunction &cgf, unsigned builtinID,
165 const CallExpr *e,
166 const SmallVector<mlir::Value> &ops) {
167 CIRGenBuilderTy &builder = cgf.getBuilder();
168 mlir::Location location = cgf.getLoc(e->getExprLoc());
169 mlir::Type voidTy = builder.getVoidTy();
170 mlir::Value address = builder.createPtrBitcast(ops[0], voidTy);
171 bool isWrite{};
172 int locality{};
173
174 assert(builtinID == X86::BI_mm_prefetch || builtinID == X86::BI_m_prefetchw ||
175 builtinID == X86::BI_m_prefetch && "Expected prefetch builtin");
176
177 if (builtinID == X86::BI_mm_prefetch) {
178 int hint = cgf.getSExtIntValueFromConstOp(ops[1]);
179 isWrite = (hint >> 2) & 0x1;
180 locality = hint & 0x3;
181 } else {
182 isWrite = (builtinID == X86::BI_m_prefetchw);
183 locality = 0x3;
184 }
185
186 cir::PrefetchOp::create(builder, location, address, locality, isWrite);
187 return {};
188}
189
190static mlir::Value emitX86CompressExpand(CIRGenBuilderTy &builder,
191 mlir::Location loc, mlir::Value source,
192 mlir::Value mask,
193 mlir::Value inputVector,
194 const std::string &id) {
195 auto resultTy = cast<cir::VectorType>(mask.getType());
196 mlir::Value maskValue = getMaskVecValue(
197 builder, loc, inputVector, cast<cir::VectorType>(resultTy).getSize());
198 return builder.emitIntrinsicCallOp(loc, id, resultTy,
199 mlir::ValueRange{source, mask, maskValue});
200}
201
202static mlir::Value
203emitEncodeKey(mlir::MLIRContext *context, CIRGenBuilderTy &builder,
204 const mlir::Location &location, mlir::ValueRange inputOperands,
205 mlir::Value outputOperand, std::uint8_t vecOutputCount,
206 const std::string &intrinsicName, std::uint8_t numResults) {
207 cir::VectorType resVector = cir::VectorType::get(builder.getUInt64Ty(), 2);
209 llvm::append_range(members,
210 llvm::SmallVector<mlir::Type>(vecOutputCount, resVector));
211 cir::RecordType resRecord = cir::RecordType::get(
212 context, members, false, false, cir::RecordType::RecordKind::Struct);
213
214 mlir::Value outputPtr =
215 builder.createBitcast(outputOperand, cir::PointerType::get(resVector));
216 mlir::Value call = builder.emitIntrinsicCallOp(location, intrinsicName,
217 resRecord, inputOperands);
218 for (std::uint8_t i = 0; i < numResults; ++i) {
219 mlir::Value vecValue =
220 cir::ExtractMemberOp::create(builder, location, call, i + 1);
221 mlir::Value index = builder.getSInt32(i, location);
222 mlir::Value ptr = builder.createPtrStride(location, outputPtr, index);
223 builder.createStore(location, vecValue, Address{ptr, CharUnits::One()});
224 }
225 return cir::ExtractMemberOp::create(builder, location, call, 0);
226}
227
228static mlir::Value emitX86Select(CIRGenBuilderTy &builder, mlir::Location loc,
229 mlir::Value mask, mlir::Value op0,
230 mlir::Value op1) {
231 auto constOp = mlir::dyn_cast_or_null<cir::ConstantOp>(mask.getDefiningOp());
232 // If the mask is all ones just return first argument.
233 if (constOp && constOp.isAllOnesValue())
234 return op0;
235
236 mask = getMaskVecValue(builder, loc, mask,
237 cast<cir::VectorType>(op0.getType()).getSize());
238
239 return cir::VecTernaryOp::create(builder, loc, mask, op0, op1);
240}
241
242// Helper function to extract zero-bit from a mask as a boolean
243static mlir::Value getMaskZeroBitAsBool(CIRGenBuilderTy &builder,
244 mlir::Location loc, mlir::Value mask) {
245 // Get the mask as a vector of i1 and extract bit 0
246 auto intTy = mlir::dyn_cast<cir::IntType>(mask.getType());
247 assert(intTy && "mask must be an integer type");
248 unsigned width = intTy.getWidth();
249
250 auto maskVecTy = cir::VectorType::get(builder.getSIntNTy(1), width);
251 mlir::Value maskVec = builder.createBitcast(mask, maskVecTy);
252
253 // Extract bit 0 from the mask vector
254 mlir::Value bit0 = builder.createExtractElement(loc, maskVec, uint64_t(0));
255
256 // Convert i1 to bool for select
257 auto boolTy = cir::BoolType::get(builder.getContext());
258 return cir::CastOp::create(builder, loc, boolTy, cir::CastKind::int_to_bool,
259 bit0);
260}
261
262static mlir::Value emitX86ScalarSelect(CIRGenBuilderTy &builder,
263 mlir::Location loc, mlir::Value mask,
264 mlir::Value op0, mlir::Value op1) {
265
266 // If the mask is all ones just return first argument.
267 if (auto c = mlir::dyn_cast_or_null<cir::ConstantOp>(mask.getDefiningOp()))
268 if (c.isAllOnesValue())
269 return op0;
270
271 mlir::Value cond = getMaskZeroBitAsBool(builder, loc, mask);
272 return builder.createSelect(loc, cond, op0, op1);
273}
274
275static mlir::Value emitX86MaskAddLogic(CIRGenBuilderTy &builder,
276 mlir::Location loc,
277 const std::string &intrinsicName,
279
280 auto intTy = cast<cir::IntType>(ops[0].getType());
281 unsigned numElts = intTy.getWidth();
282 mlir::Value lhsVec = getMaskVecValue(builder, loc, ops[0], numElts);
283 mlir::Value rhsVec = getMaskVecValue(builder, loc, ops[1], numElts);
284 mlir::Type vecTy = lhsVec.getType();
285 mlir::Value resVec = builder.emitIntrinsicCallOp(
286 loc, intrinsicName, vecTy, mlir::ValueRange{lhsVec, rhsVec});
287 return builder.createBitcast(resVec, ops[0].getType());
288}
289
290static mlir::Value emitX86MaskUnpack(CIRGenBuilderTy &builder,
291 mlir::Location loc,
292 const std::string &intrinsicName,
294 unsigned numElems = cast<cir::IntType>(ops[0].getType()).getWidth();
295
296 // Convert both operands to mask vectors.
297 mlir::Value lhs = getMaskVecValue(builder, loc, ops[0], numElems);
298 mlir::Value rhs = getMaskVecValue(builder, loc, ops[1], numElems);
299
300 mlir::Type i32Ty = builder.getSInt32Ty();
301
302 // Create indices for extracting the first half of each vector.
304 for (auto i : llvm::seq<unsigned>(0, numElems / 2))
305 halfIndices.push_back(cir::IntAttr::get(i32Ty, i));
306
307 // Extract first half of each vector. This gives better codegen than
308 // doing it in a single shuffle.
309 mlir::Value lhsHalf = builder.createVecShuffle(loc, lhs, lhs, halfIndices);
310 mlir::Value rhsHalf = builder.createVecShuffle(loc, rhs, rhs, halfIndices);
311
312 // Create indices for concatenating the vectors.
313 // NOTE: Operands are swapped to match the intrinsic definition.
314 // After the half extraction, both vectors have numElems/2 elements.
315 // In createVecShuffle(rhsHalf, lhsHalf, indices), indices [0..numElems/2-1]
316 // select from rhsHalf, and indices [numElems/2..numElems-1] select from
317 // lhsHalf.
319 for (auto i : llvm::seq<unsigned>(0, numElems))
320 concatIndices.push_back(cir::IntAttr::get(i32Ty, i));
321
322 // Concat the vectors (RHS first, then LHS).
323 mlir::Value res =
324 builder.createVecShuffle(loc, rhsHalf, lhsHalf, concatIndices);
325 return builder.createBitcast(res, ops[0].getType());
326}
327
328template <typename BinOp>
329static mlir::Value
330emitX86MaskLogic(CIRGenBuilderTy &builder, mlir::Location loc,
331 SmallVectorImpl<mlir::Value> &ops, bool invertLHS = false) {
332 unsigned numElts = cast<cir::IntType>(ops[0].getType()).getWidth();
333 mlir::Value lhs = getMaskVecValue(builder, loc, ops[0], numElts);
334 mlir::Value rhs = getMaskVecValue(builder, loc, ops[1], numElts);
335
336 if (invertLHS)
337 lhs = builder.createNot(lhs);
338 return builder.createBitcast(BinOp::create(builder, loc, lhs, rhs),
339 ops[0].getType());
340}
341
342static mlir::Value emitX86MaskTest(CIRGenBuilderTy &builder, mlir::Location loc,
343 const std::string &intrinsicName,
345 auto intTy = cast<cir::IntType>(ops[0].getType());
346 unsigned numElts = intTy.getWidth();
347 mlir::Value lhsVec = getMaskVecValue(builder, loc, ops[0], numElts);
348 mlir::Value rhsVec = getMaskVecValue(builder, loc, ops[1], numElts);
349 mlir::Type resTy = builder.getSInt32Ty();
350 return builder.emitIntrinsicCallOp(loc, intrinsicName, resTy,
351 mlir::ValueRange{lhsVec, rhsVec});
352}
353
354static mlir::Value emitX86MaskedCompareResult(CIRGenBuilderTy &builder,
355 mlir::Value cmp, unsigned numElts,
356 mlir::Value maskIn,
357 mlir::Location loc) {
358 if (maskIn) {
359 auto c = mlir::dyn_cast_or_null<cir::ConstantOp>(maskIn.getDefiningOp());
360 if (!c || !c.isAllOnesValue())
361 cmp = builder.createAnd(loc, cmp,
362 getMaskVecValue(builder, loc, maskIn, numElts));
363 }
364 if (numElts < 8) {
366 mlir::Type i64Ty = builder.getSInt64Ty();
367
368 for (unsigned i = 0; i != numElts; ++i)
369 indices.push_back(cir::IntAttr::get(i64Ty, i));
370 for (unsigned i = numElts; i != 8; ++i)
371 indices.push_back(cir::IntAttr::get(i64Ty, i % numElts + numElts));
372
373 // This should shuffle between cmp (first vector) and null (second vector)
374 mlir::Value nullVec = builder.getNullValue(cmp.getType(), loc);
375 cmp = builder.createVecShuffle(loc, cmp, nullVec, indices);
376 }
377 return builder.createBitcast(cmp, builder.getUIntNTy(std::max(numElts, 8U)));
378}
379
380// TODO: The cgf parameter should be removed when all the NYI cases are
381// implemented.
382static std::optional<mlir::Value>
383emitX86MaskedCompare(CIRGenBuilderTy &builder, unsigned cc, bool isSigned,
384 ArrayRef<mlir::Value> ops, mlir::Location loc) {
385 assert((ops.size() == 2 || ops.size() == 4) &&
386 "Unexpected number of arguments");
387 unsigned numElts = cast<cir::VectorType>(ops[0].getType()).getSize();
388 mlir::Value cmp;
389 if (cc == 3) {
390 cmp = builder.getNullValue(
391 cir::VectorType::get(builder.getSIntNTy(1), numElts), loc);
392 } else if (cc == 7) {
393 cir::VectorType resultTy =
394 cir::VectorType::get(builder.getSIntNTy(1), numElts);
395 llvm::APInt allOnes = llvm::APInt::getAllOnes(1);
396 cmp = cir::VecSplatOp::create(
397 builder, loc, resultTy,
398 builder.getConstAPInt(loc, builder.getSIntNTy(1), allOnes));
399 } else {
400 cir::CmpOpKind pred;
401 switch (cc) {
402 default:
403 llvm_unreachable("Unknown condition code");
404 case 0:
405 pred = cir::CmpOpKind::eq;
406 break;
407 case 1:
408 pred = cir::CmpOpKind::lt;
409 break;
410 case 2:
411 pred = cir::CmpOpKind::le;
412 break;
413 case 4:
414 pred = cir::CmpOpKind::ne;
415 break;
416 case 5:
417 pred = cir::CmpOpKind::ge;
418 break;
419 case 6:
420 pred = cir::CmpOpKind::gt;
421 break;
422 }
423
424 auto resultTy = cir::VectorType::get(builder.getSIntNTy(1), numElts);
425 cmp = cir::VecCmpOp::create(builder, loc, resultTy, pred, ops[0], ops[1]);
426 }
427
428 mlir::Value maskIn;
429 if (ops.size() == 4)
430 maskIn = ops[3];
431
432 return emitX86MaskedCompareResult(builder, cmp, numElts, maskIn, loc);
433}
434
435// TODO: The cgf parameter should be removed when all the NYI cases are
436// implemented.
437static std::optional<mlir::Value> emitX86ConvertToMask(CIRGenFunction &cgf,
438 CIRGenBuilderTy &builder,
439 mlir::Value in,
440 mlir::Location loc) {
441 cir::ConstantOp zero = builder.getNullValue(in.getType(), loc);
442 return emitX86MaskedCompare(builder, 1, true, {in, zero}, loc);
443}
444
445static std::optional<mlir::Value> emitX86SExtMask(CIRGenBuilderTy &builder,
446 mlir::Value op,
447 mlir::Type dstTy,
448 mlir::Location loc) {
449 unsigned numberOfElements = cast<cir::VectorType>(dstTy).getSize();
450 mlir::Value mask = getMaskVecValue(builder, loc, op, numberOfElements);
451
452 return builder.createCast(loc, cir::CastKind::integral, mask, dstTy);
453}
454
455static mlir::Value emitVecInsert(CIRGenBuilderTy &builder, mlir::Location loc,
456 mlir::Value vec, mlir::Value value,
457 mlir::Value indexOp) {
458 unsigned numElts = cast<cir::VectorType>(vec.getType()).getSize();
459
460 uint64_t index =
461 indexOp.getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue();
462
463 index &= numElts - 1;
464
465 cir::ConstantOp indexVal = builder.getUInt64(index, loc);
466
467 return cir::VecInsertOp::create(builder, loc, vec, value, indexVal);
468}
469
470static mlir::Value emitX86FunnelShift(CIRGenBuilderTy &builder,
471 mlir::Location location, mlir::Value &op0,
472 mlir::Value &op1, mlir::Value &amt,
473 bool isRight) {
474 mlir::Type op0Ty = op0.getType();
475
476 // Amount may be scalar immediate, in which case create a splat vector.
477 // Funnel shifts amounts are treated as modulo and types are all power-of-2
478 // so we only care about the lowest log2 bits anyway.
479 if (amt.getType() != op0Ty) {
480 auto vecTy = mlir::cast<cir::VectorType>(op0Ty);
481 uint64_t numElems = vecTy.getSize();
482
483 auto amtTy = mlir::cast<cir::IntType>(amt.getType());
484 auto vecElemTy = mlir::cast<cir::IntType>(vecTy.getElementType());
485
486 // If signed, cast to the same width but unsigned first to
487 // ensure zero-extension when casting to a bigger unsigned `vecElemeTy`.
488 if (amtTy.isSigned()) {
489 cir::IntType unsignedAmtTy = builder.getUIntNTy(amtTy.getWidth());
490 amt = builder.createIntCast(amt, unsignedAmtTy);
491 }
492 cir::IntType unsignedVecElemType = builder.getUIntNTy(vecElemTy.getWidth());
493 amt = builder.createIntCast(amt, unsignedVecElemType);
494 amt = cir::VecSplatOp::create(
495 builder, location, cir::VectorType::get(unsignedVecElemType, numElems),
496 amt);
497 }
498
499 const StringRef intrinsicName = isRight ? "fshr" : "fshl";
500 return builder.emitIntrinsicCallOp(location, intrinsicName, op0Ty,
501 mlir::ValueRange{op0, op1, amt});
502}
503
504static mlir::Value emitX86Muldq(CIRGenBuilderTy &builder, mlir::Location loc,
505 bool isSigned,
507 unsigned opTypePrimitiveSizeInBits) {
508 mlir::Type ty = cir::VectorType::get(builder.getSInt64Ty(),
509 opTypePrimitiveSizeInBits / 64);
510 mlir::Value lhs = builder.createBitcast(loc, ops[0], ty);
511 mlir::Value rhs = builder.createBitcast(loc, ops[1], ty);
512 if (isSigned) {
513 cir::ConstantOp shiftAmt =
514 builder.getConstant(loc, cir::IntAttr::get(builder.getSInt64Ty(), 32));
515 cir::VecSplatOp shiftSplatVecOp =
516 cir::VecSplatOp::create(builder, loc, ty, shiftAmt.getResult());
517 mlir::Value shiftSplatValue = shiftSplatVecOp.getResult();
518 // In CIR, right-shift operations are automatically lowered to either an
519 // arithmetic or logical shift depending on the operand type. The purpose
520 // of the shifts here is to propagate the sign bit of the 32-bit input
521 // into the upper bits of each vector lane.
522 lhs = builder.createShift(loc, lhs, shiftSplatValue, true);
523 lhs = builder.createShift(loc, lhs, shiftSplatValue, false);
524 rhs = builder.createShift(loc, rhs, shiftSplatValue, true);
525 rhs = builder.createShift(loc, rhs, shiftSplatValue, false);
526 } else {
527 cir::ConstantOp maskScalar = builder.getConstant(
528 loc, cir::IntAttr::get(builder.getSInt64Ty(), 0xffffffff));
529 cir::VecSplatOp mask =
530 cir::VecSplatOp::create(builder, loc, ty, maskScalar.getResult());
531 // Clear the upper bits
532 lhs = builder.createAnd(loc, lhs, mask);
533 rhs = builder.createAnd(loc, rhs, mask);
534 }
535 return builder.createMul(loc, lhs, rhs);
536}
537
538// Convert f16 half values to floats.
539static mlir::Value emitX86CvtF16ToFloatExpr(CIRGenBuilderTy &builder,
540 mlir::Location loc,
542 mlir::Type dstTy) {
543 assert((ops.size() == 1 || ops.size() == 3 || ops.size() == 4) &&
544 "Unknown cvtph2ps intrinsic");
545
546 // If the SAE intrinsic doesn't use default rounding then we can't upgrade.
547 if (ops.size() == 4) {
548 auto constOp = ops[3].getDefiningOp<cir::ConstantOp>();
549 assert(constOp && "Expected constant operand");
550 if (constOp.getIntValue().getZExtValue() != 4) {
551 return builder.emitIntrinsicCallOp(loc, "x86.avx512.mask.vcvtph2ps.512",
552 dstTy, ops);
553 }
554 }
555
556 unsigned numElts = cast<cir::VectorType>(dstTy).getSize();
557 mlir::Value src = ops[0];
558
559 // Extract the subvector
560 if (numElts != cast<cir::VectorType>(src.getType()).getSize()) {
561 assert(numElts == 4 && "Unexpected vector size");
562 src = builder.createVecShuffle(loc, src, {0, 1, 2, 3});
563 }
564
565 // Bitcast from vXi16 to vXf16.
566 cir::VectorType halfTy =
567 cir::VectorType::get(cir::FP16Type::get(builder.getContext()), numElts);
568
569 src = builder.createCast(cir::CastKind::bitcast, src, halfTy);
570
571 // Perform the fp-extension
572 mlir::Value res = builder.createCast(cir::CastKind::floating, src, dstTy);
573
574 if (ops.size() >= 3)
575 res = emitX86Select(builder, loc, ops[2], res, ops[1]);
576 return res;
577}
578
579static mlir::Value emitX86vpcom(CIRGenBuilderTy &builder, mlir::Location loc,
581 bool isSigned) {
582 mlir::Value op0 = ops[0];
583 mlir::Value op1 = ops[1];
584
585 cir::VectorType ty = cast<cir::VectorType>(op0.getType());
586 cir::IntType elementTy = cast<cir::IntType>(ty.getElementType());
587
588 uint64_t imm = CIRGenFunction::getZExtIntValueFromConstOp(ops[2]) & 0x7;
589
590 cir::CmpOpKind pred;
591 switch (imm) {
592 case 0x0:
593 pred = cir::CmpOpKind::lt;
594 break;
595 case 0x1:
596 pred = cir::CmpOpKind::le;
597 break;
598 case 0x2:
599 pred = cir::CmpOpKind::gt;
600 break;
601 case 0x3:
602 pred = cir::CmpOpKind::ge;
603 break;
604 case 0x4:
605 pred = cir::CmpOpKind::eq;
606 break;
607 case 0x5:
608 pred = cir::CmpOpKind::ne;
609 break;
610 case 0x6:
611 return builder.getNullValue(ty, loc); // FALSE
612 case 0x7: {
613 llvm::APInt allOnes = llvm::APInt::getAllOnes(elementTy.getWidth());
614 return cir::VecSplatOp::create(
615 builder, loc, ty,
616 builder.getConstAPInt(loc, elementTy, allOnes)); // TRUE
617 }
618 default:
619 llvm_unreachable("Unexpected XOP vpcom/vpcomu predicate");
620 }
621
622 if ((!isSigned && elementTy.isSigned()) ||
623 (isSigned && elementTy.isUnsigned())) {
624 elementTy = elementTy.isSigned() ? builder.getUIntNTy(elementTy.getWidth())
625 : builder.getSIntNTy(elementTy.getWidth());
626 ty = cir::VectorType::get(elementTy, ty.getSize());
627 op0 = builder.createBitcast(op0, ty);
628 op1 = builder.createBitcast(op1, ty);
629 }
630
631 return builder.createVecCompare(loc, pred, op0, op1);
632}
633
634static mlir::Value emitX86Fpclass(CIRGenBuilderTy &builder, mlir::Location loc,
635 unsigned builtinID,
637 unsigned numElts = cast<cir::VectorType>(ops[0].getType()).getSize();
638 mlir::Value maskIn = ops[2];
639 ops.erase(ops.begin() + 2);
640
641 StringRef intrinsicName;
642 switch (builtinID) {
643 default:
644 llvm_unreachable("Unsupported fpclass builtin");
645 case X86::BI__builtin_ia32_vfpclassbf16128_mask:
646 intrinsicName = "x86.avx10.fpclass.bf16.128";
647 break;
648 case X86::BI__builtin_ia32_vfpclassbf16256_mask:
649 intrinsicName = "x86.avx10.fpclass.bf16.256";
650 break;
651 case X86::BI__builtin_ia32_vfpclassbf16512_mask:
652 intrinsicName = "x86.avx10.fpclass.bf16.512";
653 break;
654 case X86::BI__builtin_ia32_fpclassph128_mask:
655 intrinsicName = "x86.avx512fp16.fpclass.ph.128";
656 break;
657 case X86::BI__builtin_ia32_fpclassph256_mask:
658 intrinsicName = "x86.avx512fp16.fpclass.ph.256";
659 break;
660 case X86::BI__builtin_ia32_fpclassph512_mask:
661 intrinsicName = "x86.avx512fp16.fpclass.ph.512";
662 break;
663 case X86::BI__builtin_ia32_fpclassps128_mask:
664 intrinsicName = "x86.avx512.fpclass.ps.128";
665 break;
666 case X86::BI__builtin_ia32_fpclassps256_mask:
667 intrinsicName = "x86.avx512.fpclass.ps.256";
668 break;
669 case X86::BI__builtin_ia32_fpclassps512_mask:
670 intrinsicName = "x86.avx512.fpclass.ps.512";
671 break;
672 case X86::BI__builtin_ia32_fpclasspd128_mask:
673 intrinsicName = "x86.avx512.fpclass.pd.128";
674 break;
675 case X86::BI__builtin_ia32_fpclasspd256_mask:
676 intrinsicName = "x86.avx512.fpclass.pd.256";
677 break;
678 case X86::BI__builtin_ia32_fpclasspd512_mask:
679 intrinsicName = "x86.avx512.fpclass.pd.512";
680 break;
681 }
682
683 auto cmpResultTy = cir::VectorType::get(builder.getSIntNTy(1), numElts);
684 mlir::Value fpclass =
685 builder.emitIntrinsicCallOp(loc, intrinsicName, cmpResultTy, ops);
686 return emitX86MaskedCompareResult(builder, fpclass, numElts, maskIn, loc);
687}
688
689static mlir::Value emitX86Aes(CIRGenBuilderTy &builder, mlir::Location loc,
690 llvm::StringRef intrinsicName, mlir::Type retType,
692 // Create return struct type and call intrinsic function.
693 mlir::Type vecType =
694 mlir::cast<cir::PointerType>(ops[0].getType()).getPointee();
695 cir::RecordType rstRecTy = builder.getAnonRecordTy({retType, vecType});
696 mlir::Value rstValueRec = builder.emitIntrinsicCallOp(
697 loc, intrinsicName, rstRecTy, mlir::ValueRange{ops[1], ops[2]});
698
699 // Extract the first return value and truncate it to 1 bit, then cast result
700 // to bool value.
701 mlir::Value flag =
702 cir::ExtractMemberOp::create(builder, loc, rstValueRec, /*index=*/0);
703 mlir::Value flagBit0 = builder.createCast(loc, cir::CastKind::integral, flag,
704 builder.getUIntNTy(1));
705 mlir::Value succ = builder.createCast(loc, cir::CastKind::int_to_bool,
706 flagBit0, builder.getBoolTy());
707
708 // Extract the second return value, store it to output address if success.
709 mlir::Value out =
710 cir::ExtractMemberOp::create(builder, loc, rstValueRec, /*index=*/1);
711 Address outAddr(ops[0], /*align=*/CharUnits::fromQuantity(16));
712 cir::IfOp::create(
713 builder, loc, succ, /*withElseRegion=*/true,
714 /*thenBuilder=*/
715 [&](mlir::OpBuilder &b, mlir::Location) {
716 builder.createStore(loc, out, outAddr);
717 builder.createYield(loc);
718 },
719 /*elseBuilder=*/
720 [&](mlir::OpBuilder &b, mlir::Location) {
721 mlir::Value zero = builder.getNullValue(vecType, loc);
722 builder.createStore(loc, zero, outAddr);
723 builder.createYield(loc);
724 });
725
726 return cir::ExtractMemberOp::create(builder, loc, rstValueRec, /*index=*/0);
727}
728
729static mlir::Value emitX86Aeswide(CIRGenBuilderTy &builder, mlir::Location loc,
730 llvm::StringRef intrinsicName,
731 mlir::Type retType,
733 mlir::Type vecType =
734 mlir::cast<cir::PointerType>(ops[1].getType()).getPointee();
735
736 // Create struct for return type and load input arguments, then call
737 // intrinsic function.
738 mlir::Type recTypes[9] = {retType, vecType, vecType, vecType, vecType,
739 vecType, vecType, vecType, vecType};
740 mlir::Value arguments[9];
741 arguments[0] = ops[2];
742 for (int i = 0; i < 8; i++) {
743 // Loading each vector argument from input address.
744 cir::ConstantOp idx = builder.getUInt32(i, loc);
745 mlir::Value nextInElePtr =
746 builder.getArrayElement(loc, loc, ops[1], vecType, idx,
747 /*shouldDecay=*/false);
748 arguments[i + 1] =
749 builder.createAlignedLoad(loc, vecType, nextInElePtr,
750 /*align=*/CharUnits::fromQuantity(16));
751 }
752 cir::RecordType rstRecTy = builder.getAnonRecordTy(recTypes);
753 mlir::Value rstValueRec =
754 builder.emitIntrinsicCallOp(loc, intrinsicName, rstRecTy, arguments);
755
756 // Extract the first return value and truncate it to 1 bit, then cast result
757 // to bool value.
758 mlir::Value flag =
759 cir::ExtractMemberOp::create(builder, loc, rstValueRec, /*index=*/0);
760 mlir::Value flagBit0 = builder.createCast(loc, cir::CastKind::integral, flag,
761 builder.getUIntNTy(1));
762 mlir::Value succ = builder.createCast(loc, cir::CastKind::int_to_bool,
763 flagBit0, builder.getBoolTy());
764
765 // Extract other return values, store those to output address if success.
766 cir::IfOp::create(
767 builder, loc, succ, /*withElseRegion=*/true,
768 /*thenBuilder=*/
769 [&](mlir::OpBuilder &b, mlir::Location) {
770 for (int i = 0; i < 8; i++) {
771 mlir::Value out =
772 cir::ExtractMemberOp::create(builder, loc, rstValueRec,
773 /*index=*/i + 1);
774 cir::ConstantOp idx = builder.getUInt32(i, loc);
775 mlir::Value nextOutEleAddr =
776 builder.getArrayElement(loc, loc, ops[0], vecType, idx,
777 /*shouldDecay=*/false);
778 Address outAddr(nextOutEleAddr,
779 /*align=*/CharUnits::fromQuantity(16));
780 builder.createStore(loc, out, outAddr);
781 }
782 builder.createYield(loc);
783 },
784 /*elseBuilder=*/
785 [&](mlir::OpBuilder &b, mlir::Location) {
786 mlir::Value zero = builder.getNullValue(vecType, loc);
787 for (int i = 0; i < 8; i++) {
788 cir::ConstantOp idx = builder.getUInt32(i, loc);
789 mlir::Value nextOutEleAddr =
790 builder.getArrayElement(loc, loc, ops[0], vecType, idx,
791 /*shouldDecay=*/false);
792 Address outAddr(nextOutEleAddr,
793 /*align=*/CharUnits::fromQuantity(16));
794 builder.createStore(loc, zero, outAddr);
795 }
796 builder.createYield(loc);
797 });
798
799 return cir::ExtractMemberOp::create(builder, loc, rstValueRec, /*index=*/0);
800}
801
802static mlir::Value emitX86MaskedLoad(CIRGenBuilderTy &builder,
804 llvm::Align alignment,
805 mlir::Location loc) {
806 mlir::Type ty = ops[1].getType();
807 mlir::Value ptr = ops[0];
808 mlir::Value maskVec = getMaskVecValue(builder, loc, ops[2],
809 cast<cir::VectorType>(ty).getSize());
810
811 return builder.createMaskedLoad(loc, ty, ptr, alignment, maskVec, ops[1]);
812}
813
814std::optional<mlir::Value>
816 if (builtinID == Builtin::BI__builtin_cpu_is) {
817 cgm.errorNYI(expr->getSourceRange(), "__builtin_cpu_is");
818 return mlir::Value{};
819 }
820 if (builtinID == Builtin::BI__builtin_cpu_supports) {
821 cgm.errorNYI(expr->getSourceRange(), "__builtin_cpu_supports");
822 return mlir::Value{};
823 }
824 if (builtinID == Builtin::BI__builtin_cpu_init) {
825 cgm.errorNYI(expr->getSourceRange(), "__builtin_cpu_init");
826 return mlir::Value{};
827 }
828
829 // Handle MSVC intrinsics before argument evaluation to prevent double
830 // evaluation.
832
833 // Find out if any arguments are required to be integer constant expressions.
835
836 // The operands of the builtin call
838
839 // `ICEArguments` is a bitmap indicating whether the argument at the i-th bit
840 // is required to be a constant integer expression.
841 unsigned iceArguments = 0;
843 getContext().GetBuiltinType(builtinID, error, &iceArguments);
844 assert(error == ASTContext::GE_None && "Error while getting builtin type.");
845
846 for (auto [idx, arg] : llvm::enumerate(expr->arguments()))
847 ops.push_back(emitScalarOrConstFoldImmArg(iceArguments, idx, arg));
848
849 CIRGenBuilderTy &builder = getBuilder();
850 mlir::Type voidTy = builder.getVoidTy();
851
852 switch (builtinID) {
853 default:
854 return std::nullopt;
855 case X86::BI_mm_clflush:
856 return builder.emitIntrinsicCallOp(getLoc(expr->getExprLoc()),
857 "x86.sse2.clflush", voidTy, ops[0]);
858 case X86::BI_mm_lfence:
859 return builder.emitIntrinsicCallOp(getLoc(expr->getExprLoc()),
860 "x86.sse2.lfence", voidTy);
861 case X86::BI_mm_pause:
862 return builder.emitIntrinsicCallOp(getLoc(expr->getExprLoc()),
863 "x86.sse2.pause", voidTy);
864 case X86::BI_mm_mfence:
865 return builder.emitIntrinsicCallOp(getLoc(expr->getExprLoc()),
866 "x86.sse2.mfence", voidTy);
867 case X86::BI_mm_sfence:
868 return builder.emitIntrinsicCallOp(getLoc(expr->getExprLoc()),
869 "x86.sse.sfence", voidTy);
870 case X86::BI_mm_prefetch:
871 case X86::BI_m_prefetch:
872 case X86::BI_m_prefetchw:
873 return emitPrefetch(*this, builtinID, expr, ops);
874 case X86::BI__rdtsc:
875 return builder.emitIntrinsicCallOp(getLoc(expr->getExprLoc()), "x86.rdtsc",
876 builder.getUInt64Ty());
877 case X86::BI__builtin_ia32_rdtscp: {
878 mlir::Location loc = getLoc(expr->getExprLoc());
879 mlir::Type i64Ty = builder.getUInt64Ty();
880 mlir::Type i32Ty = builder.getUInt32Ty();
881 mlir::Type structTy = builder.getAnonRecordTy({i64Ty, i32Ty});
882 mlir::Value result =
883 builder.emitIntrinsicCallOp(loc, "x86.rdtscp", structTy);
884
885 // Extract and store processor_id (element 1 of the returned struct)
886 mlir::Value processorId =
887 cir::ExtractMemberOp::create(builder, loc, i32Ty, result, 1);
888 // ops[0] is the address to store the processor ID
889 builder.createStore(loc, processorId, Address{ops[0], CharUnits::One()});
890
891 // Return timestamp (element 0 of the returned struct)
892 return cir::ExtractMemberOp::create(builder, loc, i64Ty, result, 0);
893 }
894 case X86::BI__builtin_ia32_lzcnt_u16:
895 case X86::BI__builtin_ia32_lzcnt_u32:
896 case X86::BI__builtin_ia32_lzcnt_u64: {
897 mlir::Location loc = getLoc(expr->getExprLoc());
898 mlir::Value isZeroPoison = builder.getFalse(loc);
899 return builder.emitIntrinsicCallOp(loc, "ctlz", ops[0].getType(),
900 mlir::ValueRange{ops[0], isZeroPoison});
901 }
902 case X86::BI__builtin_ia32_tzcnt_u16:
903 case X86::BI__builtin_ia32_tzcnt_u32:
904 case X86::BI__builtin_ia32_tzcnt_u64: {
905 mlir::Location loc = getLoc(expr->getExprLoc());
906 mlir::Value isZeroPoison = builder.getFalse(loc);
907 return builder.emitIntrinsicCallOp(loc, "cttz", ops[0].getType(),
908 mlir::ValueRange{ops[0], isZeroPoison});
909 }
910 case X86::BI__builtin_ia32_undef128:
911 case X86::BI__builtin_ia32_undef256:
912 case X86::BI__builtin_ia32_undef512:
913 // The x86 definition of "undef" is not the same as the LLVM definition
914 // (PR32176). We leave optimizing away an unnecessary zero constant to the
915 // IR optimizer and backend.
916 // TODO: If we had a "freeze" IR instruction to generate a fixed undef
917 // value, we should use that here instead of a zero.
918 return builder.getNullValue(convertType(expr->getType()),
919 getLoc(expr->getExprLoc()));
920 case X86::BI__builtin_ia32_vec_ext_v4hi:
921 case X86::BI__builtin_ia32_vec_ext_v16qi:
922 case X86::BI__builtin_ia32_vec_ext_v8hi:
923 case X86::BI__builtin_ia32_vec_ext_v4si:
924 case X86::BI__builtin_ia32_vec_ext_v4sf:
925 case X86::BI__builtin_ia32_vec_ext_v2di:
926 case X86::BI__builtin_ia32_vec_ext_v32qi:
927 case X86::BI__builtin_ia32_vec_ext_v16hi:
928 case X86::BI__builtin_ia32_vec_ext_v8si:
929 case X86::BI__builtin_ia32_vec_ext_v4di: {
930 unsigned numElts = cast<cir::VectorType>(ops[0].getType()).getSize();
931
932 uint64_t index = getZExtIntValueFromConstOp(ops[1]);
933 index &= numElts - 1;
934
935 cir::ConstantOp indexVal =
936 builder.getUInt64(index, getLoc(expr->getExprLoc()));
937
938 // These builtins exist so we can ensure the index is an ICE and in range.
939 // Otherwise we could just do this in the header file.
940 return cir::VecExtractOp::create(builder, getLoc(expr->getExprLoc()),
941 ops[0], indexVal);
942 }
943 case X86::BI__builtin_ia32_vec_set_v4hi:
944 case X86::BI__builtin_ia32_vec_set_v16qi:
945 case X86::BI__builtin_ia32_vec_set_v8hi:
946 case X86::BI__builtin_ia32_vec_set_v4si:
947 case X86::BI__builtin_ia32_vec_set_v2di:
948 case X86::BI__builtin_ia32_vec_set_v32qi:
949 case X86::BI__builtin_ia32_vec_set_v16hi:
950 case X86::BI__builtin_ia32_vec_set_v8si:
951 case X86::BI__builtin_ia32_vec_set_v4di: {
952 return emitVecInsert(builder, getLoc(expr->getExprLoc()), ops[0], ops[1],
953 ops[2]);
954 }
955 case X86::BI__builtin_ia32_kunpckhi:
956 return emitX86MaskUnpack(builder, getLoc(expr->getExprLoc()),
957 "x86.avx512.kunpackb", ops);
958 case X86::BI__builtin_ia32_kunpcksi:
959 return emitX86MaskUnpack(builder, getLoc(expr->getExprLoc()),
960 "x86.avx512.kunpackw", ops);
961 case X86::BI__builtin_ia32_kunpckdi:
962 return emitX86MaskUnpack(builder, getLoc(expr->getExprLoc()),
963 "x86.avx512.kunpackd", ops);
964 case X86::BI_mm_setcsr:
965 case X86::BI__builtin_ia32_ldmxcsr: {
966 mlir::Location loc = getLoc(expr->getExprLoc());
967 Address tmp = createMemTemp(expr->getArg(0)->getType(), loc);
968 builder.createStore(loc, ops[0], tmp);
969 return builder.emitIntrinsicCallOp(loc, "x86.sse.ldmxcsr",
970 builder.getVoidTy(), tmp.getPointer());
971 }
972 case X86::BI_mm_getcsr:
973 case X86::BI__builtin_ia32_stmxcsr: {
974 mlir::Location loc = getLoc(expr->getExprLoc());
975 Address tmp = createMemTemp(expr->getType(), loc);
976 builder.emitIntrinsicCallOp(loc, "x86.sse.stmxcsr", builder.getVoidTy(),
977 tmp.getPointer());
978 return builder.createLoad(loc, tmp);
979 }
980 case X86::BI__builtin_ia32_xsave:
981 case X86::BI__builtin_ia32_xsave64:
982 case X86::BI__builtin_ia32_xrstor:
983 case X86::BI__builtin_ia32_xrstor64:
984 case X86::BI__builtin_ia32_xsaveopt:
985 case X86::BI__builtin_ia32_xsaveopt64:
986 case X86::BI__builtin_ia32_xrstors:
987 case X86::BI__builtin_ia32_xrstors64:
988 case X86::BI__builtin_ia32_xsavec:
989 case X86::BI__builtin_ia32_xsavec64:
990 case X86::BI__builtin_ia32_xsaves:
991 case X86::BI__builtin_ia32_xsaves64:
992 case X86::BI__builtin_ia32_xsetbv:
993 case X86::BI_xsetbv: {
994 mlir::Location loc = getLoc(expr->getExprLoc());
995 StringRef intrinsicName;
996 switch (builtinID) {
997 default:
998 llvm_unreachable("Unexpected builtin");
999 case X86::BI__builtin_ia32_xsave:
1000 intrinsicName = "x86.xsave";
1001 break;
1002 case X86::BI__builtin_ia32_xsave64:
1003 intrinsicName = "x86.xsave64";
1004 break;
1005 case X86::BI__builtin_ia32_xrstor:
1006 intrinsicName = "x86.xrstor";
1007 break;
1008 case X86::BI__builtin_ia32_xrstor64:
1009 intrinsicName = "x86.xrstor64";
1010 break;
1011 case X86::BI__builtin_ia32_xsaveopt:
1012 intrinsicName = "x86.xsaveopt";
1013 break;
1014 case X86::BI__builtin_ia32_xsaveopt64:
1015 intrinsicName = "x86.xsaveopt64";
1016 break;
1017 case X86::BI__builtin_ia32_xrstors:
1018 intrinsicName = "x86.xrstors";
1019 break;
1020 case X86::BI__builtin_ia32_xrstors64:
1021 intrinsicName = "x86.xrstors64";
1022 break;
1023 case X86::BI__builtin_ia32_xsavec:
1024 intrinsicName = "x86.xsavec";
1025 break;
1026 case X86::BI__builtin_ia32_xsavec64:
1027 intrinsicName = "x86.xsavec64";
1028 break;
1029 case X86::BI__builtin_ia32_xsaves:
1030 intrinsicName = "x86.xsaves";
1031 break;
1032 case X86::BI__builtin_ia32_xsaves64:
1033 intrinsicName = "x86.xsaves64";
1034 break;
1035 case X86::BI__builtin_ia32_xsetbv:
1036 case X86::BI_xsetbv:
1037 intrinsicName = "x86.xsetbv";
1038 break;
1039 }
1040
1041 // The xsave family of instructions take a 64-bit mask that specifies
1042 // which processor state components to save/restore. The hardware expects
1043 // this mask split into two 32-bit registers: EDX (high 32 bits) and
1044 // EAX (low 32 bits).
1045 mlir::Type i32Ty = builder.getSInt32Ty();
1046
1047 // Mhi = (uint32_t)(ops[1] >> 32) - extract high 32 bits via right shift
1048 cir::ConstantOp shift32 = builder.getSInt64(32, loc);
1049 mlir::Value mhi = builder.createShift(loc, ops[1], shift32.getResult(),
1050 /*isShiftLeft=*/false);
1051 mhi = builder.createIntCast(mhi, i32Ty);
1052
1053 // Mlo = (uint32_t)ops[1] - extract low 32 bits by truncation
1054 mlir::Value mlo = builder.createIntCast(ops[1], i32Ty);
1055
1056 return builder.emitIntrinsicCallOp(loc, intrinsicName, voidTy,
1057 mlir::ValueRange{ops[0], mhi, mlo});
1058 }
1059 case X86::BI__builtin_ia32_xgetbv:
1060 case X86::BI_xgetbv:
1061 // xgetbv reads the extended control register specified by ops[0] (ECX)
1062 // and returns the 64-bit value
1063 return builder.emitIntrinsicCallOp(getLoc(expr->getExprLoc()), "x86.xgetbv",
1064 builder.getUInt64Ty(), ops[0]);
1065 case X86::BI__builtin_ia32_storedqudi128_mask:
1066 case X86::BI__builtin_ia32_storedqusi128_mask:
1067 case X86::BI__builtin_ia32_storedquhi128_mask:
1068 case X86::BI__builtin_ia32_storedquqi128_mask:
1069 case X86::BI__builtin_ia32_storeupd128_mask:
1070 case X86::BI__builtin_ia32_storeups128_mask:
1071 case X86::BI__builtin_ia32_storedqudi256_mask:
1072 case X86::BI__builtin_ia32_storedqusi256_mask:
1073 case X86::BI__builtin_ia32_storedquhi256_mask:
1074 case X86::BI__builtin_ia32_storedquqi256_mask:
1075 case X86::BI__builtin_ia32_storeupd256_mask:
1076 case X86::BI__builtin_ia32_storeups256_mask:
1077 case X86::BI__builtin_ia32_storedqudi512_mask:
1078 case X86::BI__builtin_ia32_storedqusi512_mask:
1079 case X86::BI__builtin_ia32_storedquhi512_mask:
1080 case X86::BI__builtin_ia32_storedquqi512_mask:
1081 case X86::BI__builtin_ia32_storeupd512_mask:
1082 case X86::BI__builtin_ia32_storeups512_mask:
1083 case X86::BI__builtin_ia32_storesbf16128_mask:
1084 case X86::BI__builtin_ia32_storesh128_mask:
1085 case X86::BI__builtin_ia32_storess128_mask:
1086 case X86::BI__builtin_ia32_storesd128_mask:
1087 cgm.errorNYI(expr->getSourceRange(),
1088 std::string("unimplemented x86 builtin call: ") +
1089 getContext().BuiltinInfo.getName(builtinID));
1090 return mlir::Value{};
1091 case X86::BI__builtin_ia32_cvtmask2b128:
1092 case X86::BI__builtin_ia32_cvtmask2b256:
1093 case X86::BI__builtin_ia32_cvtmask2b512:
1094 case X86::BI__builtin_ia32_cvtmask2w128:
1095 case X86::BI__builtin_ia32_cvtmask2w256:
1096 case X86::BI__builtin_ia32_cvtmask2w512:
1097 case X86::BI__builtin_ia32_cvtmask2d128:
1098 case X86::BI__builtin_ia32_cvtmask2d256:
1099 case X86::BI__builtin_ia32_cvtmask2d512:
1100 case X86::BI__builtin_ia32_cvtmask2q128:
1101 case X86::BI__builtin_ia32_cvtmask2q256:
1102 case X86::BI__builtin_ia32_cvtmask2q512:
1103 return emitX86SExtMask(this->getBuilder(), ops[0],
1104 convertType(expr->getType()),
1105 getLoc(expr->getExprLoc()));
1106 case X86::BI__builtin_ia32_cvtb2mask128:
1107 case X86::BI__builtin_ia32_cvtb2mask256:
1108 case X86::BI__builtin_ia32_cvtb2mask512:
1109 case X86::BI__builtin_ia32_cvtw2mask128:
1110 case X86::BI__builtin_ia32_cvtw2mask256:
1111 case X86::BI__builtin_ia32_cvtw2mask512:
1112 case X86::BI__builtin_ia32_cvtd2mask128:
1113 case X86::BI__builtin_ia32_cvtd2mask256:
1114 case X86::BI__builtin_ia32_cvtd2mask512:
1115 case X86::BI__builtin_ia32_cvtq2mask128:
1116 case X86::BI__builtin_ia32_cvtq2mask256:
1117 case X86::BI__builtin_ia32_cvtq2mask512:
1118 return emitX86ConvertToMask(*this, this->getBuilder(), ops[0],
1119 getLoc(expr->getExprLoc()));
1120 case X86::BI__builtin_ia32_cvtdq2ps512_mask:
1121 case X86::BI__builtin_ia32_cvtqq2ps512_mask:
1122 case X86::BI__builtin_ia32_cvtqq2pd512_mask:
1123 case X86::BI__builtin_ia32_vcvtw2ph512_mask:
1124 case X86::BI__builtin_ia32_vcvtdq2ph512_mask:
1125 case X86::BI__builtin_ia32_vcvtqq2ph512_mask:
1126 case X86::BI__builtin_ia32_cvtudq2ps512_mask:
1127 case X86::BI__builtin_ia32_cvtuqq2ps512_mask:
1128 case X86::BI__builtin_ia32_cvtuqq2pd512_mask:
1129 case X86::BI__builtin_ia32_vcvtuw2ph512_mask:
1130 case X86::BI__builtin_ia32_vcvtudq2ph512_mask:
1131 case X86::BI__builtin_ia32_vcvtuqq2ph512_mask:
1132 case X86::BI__builtin_ia32_vfmaddsh3_mask:
1133 case X86::BI__builtin_ia32_vfmaddss3_mask:
1134 case X86::BI__builtin_ia32_vfmaddsd3_mask:
1135 case X86::BI__builtin_ia32_vfmaddsh3_maskz:
1136 case X86::BI__builtin_ia32_vfmaddss3_maskz:
1137 case X86::BI__builtin_ia32_vfmaddsd3_maskz:
1138 case X86::BI__builtin_ia32_vfmaddsh3_mask3:
1139 case X86::BI__builtin_ia32_vfmaddss3_mask3:
1140 case X86::BI__builtin_ia32_vfmaddsd3_mask3:
1141 case X86::BI__builtin_ia32_vfmsubsh3_mask3:
1142 case X86::BI__builtin_ia32_vfmsubss3_mask3:
1143 case X86::BI__builtin_ia32_vfmsubsd3_mask3:
1144 case X86::BI__builtin_ia32_vfmaddph512_mask:
1145 case X86::BI__builtin_ia32_vfmaddph512_maskz:
1146 case X86::BI__builtin_ia32_vfmaddph512_mask3:
1147 case X86::BI__builtin_ia32_vfmaddps512_mask:
1148 case X86::BI__builtin_ia32_vfmaddps512_maskz:
1149 case X86::BI__builtin_ia32_vfmaddps512_mask3:
1150 case X86::BI__builtin_ia32_vfmsubps512_mask3:
1151 case X86::BI__builtin_ia32_vfmaddpd512_mask:
1152 case X86::BI__builtin_ia32_vfmaddpd512_maskz:
1153 case X86::BI__builtin_ia32_vfmaddpd512_mask3:
1154 case X86::BI__builtin_ia32_vfmsubpd512_mask3:
1155 case X86::BI__builtin_ia32_vfmsubph512_mask3:
1156 case X86::BI__builtin_ia32_vfmaddsubph512_mask:
1157 case X86::BI__builtin_ia32_vfmaddsubph512_maskz:
1158 case X86::BI__builtin_ia32_vfmaddsubph512_mask3:
1159 case X86::BI__builtin_ia32_vfmsubaddph512_mask3:
1160 case X86::BI__builtin_ia32_vfmaddsubps512_mask:
1161 case X86::BI__builtin_ia32_vfmaddsubps512_maskz:
1162 case X86::BI__builtin_ia32_vfmaddsubps512_mask3:
1163 case X86::BI__builtin_ia32_vfmsubaddps512_mask3:
1164 case X86::BI__builtin_ia32_vfmaddsubpd512_mask:
1165 case X86::BI__builtin_ia32_vfmaddsubpd512_maskz:
1166 case X86::BI__builtin_ia32_vfmaddsubpd512_mask3:
1167 case X86::BI__builtin_ia32_vfmsubaddpd512_mask3:
1168 case X86::BI__builtin_ia32_movdqa32store128_mask:
1169 case X86::BI__builtin_ia32_movdqa64store128_mask:
1170 case X86::BI__builtin_ia32_storeaps128_mask:
1171 case X86::BI__builtin_ia32_storeapd128_mask:
1172 case X86::BI__builtin_ia32_movdqa32store256_mask:
1173 case X86::BI__builtin_ia32_movdqa64store256_mask:
1174 case X86::BI__builtin_ia32_storeaps256_mask:
1175 case X86::BI__builtin_ia32_storeapd256_mask:
1176 case X86::BI__builtin_ia32_movdqa32store512_mask:
1177 case X86::BI__builtin_ia32_movdqa64store512_mask:
1178 case X86::BI__builtin_ia32_storeaps512_mask:
1179 case X86::BI__builtin_ia32_storeapd512_mask:
1180 cgm.errorNYI(expr->getSourceRange(),
1181 std::string("unimplemented X86 builtin call: ") +
1182 getContext().BuiltinInfo.getName(builtinID));
1183 return {};
1184
1185 case X86::BI__builtin_ia32_loadups128_mask:
1186 case X86::BI__builtin_ia32_loadups256_mask:
1187 case X86::BI__builtin_ia32_loadups512_mask:
1188 case X86::BI__builtin_ia32_loadupd128_mask:
1189 case X86::BI__builtin_ia32_loadupd256_mask:
1190 case X86::BI__builtin_ia32_loadupd512_mask:
1191 case X86::BI__builtin_ia32_loaddquqi128_mask:
1192 case X86::BI__builtin_ia32_loaddquqi256_mask:
1193 case X86::BI__builtin_ia32_loaddquqi512_mask:
1194 case X86::BI__builtin_ia32_loaddquhi128_mask:
1195 case X86::BI__builtin_ia32_loaddquhi256_mask:
1196 case X86::BI__builtin_ia32_loaddquhi512_mask:
1197 case X86::BI__builtin_ia32_loaddqusi128_mask:
1198 case X86::BI__builtin_ia32_loaddqusi256_mask:
1199 case X86::BI__builtin_ia32_loaddqusi512_mask:
1200 case X86::BI__builtin_ia32_loaddqudi128_mask:
1201 case X86::BI__builtin_ia32_loaddqudi256_mask:
1202 case X86::BI__builtin_ia32_loaddqudi512_mask:
1203 case X86::BI__builtin_ia32_loadsbf16128_mask:
1204 case X86::BI__builtin_ia32_loadsh128_mask:
1205 case X86::BI__builtin_ia32_loadss128_mask:
1206 case X86::BI__builtin_ia32_loadsd128_mask:
1207 return emitX86MaskedLoad(builder, ops, llvm::Align(1),
1208 getLoc(expr->getExprLoc()));
1209
1210 case X86::BI__builtin_ia32_loadaps128_mask:
1211 case X86::BI__builtin_ia32_loadaps256_mask:
1212 case X86::BI__builtin_ia32_loadaps512_mask:
1213 case X86::BI__builtin_ia32_loadapd128_mask:
1214 case X86::BI__builtin_ia32_loadapd256_mask:
1215 case X86::BI__builtin_ia32_loadapd512_mask:
1216 case X86::BI__builtin_ia32_movdqa32load128_mask:
1217 case X86::BI__builtin_ia32_movdqa32load256_mask:
1218 case X86::BI__builtin_ia32_movdqa32load512_mask:
1219 case X86::BI__builtin_ia32_movdqa64load128_mask:
1220 case X86::BI__builtin_ia32_movdqa64load256_mask:
1221 case X86::BI__builtin_ia32_movdqa64load512_mask:
1222 return emitX86MaskedLoad(
1223 builder, ops,
1224 getContext()
1225 .getTypeAlignInChars(expr->getArg(1)->getType())
1226 .getAsAlign(),
1227 getLoc(expr->getExprLoc()));
1228
1229 case X86::BI__builtin_ia32_expandloaddf128_mask:
1230 case X86::BI__builtin_ia32_expandloaddf256_mask:
1231 case X86::BI__builtin_ia32_expandloaddf512_mask:
1232 case X86::BI__builtin_ia32_expandloadsf128_mask:
1233 case X86::BI__builtin_ia32_expandloadsf256_mask:
1234 case X86::BI__builtin_ia32_expandloadsf512_mask:
1235 case X86::BI__builtin_ia32_expandloaddi128_mask:
1236 case X86::BI__builtin_ia32_expandloaddi256_mask:
1237 case X86::BI__builtin_ia32_expandloaddi512_mask:
1238 case X86::BI__builtin_ia32_expandloadsi128_mask:
1239 case X86::BI__builtin_ia32_expandloadsi256_mask:
1240 case X86::BI__builtin_ia32_expandloadsi512_mask:
1241 case X86::BI__builtin_ia32_expandloadhi128_mask:
1242 case X86::BI__builtin_ia32_expandloadhi256_mask:
1243 case X86::BI__builtin_ia32_expandloadhi512_mask:
1244 case X86::BI__builtin_ia32_expandloadqi128_mask:
1245 case X86::BI__builtin_ia32_expandloadqi256_mask:
1246 case X86::BI__builtin_ia32_expandloadqi512_mask: {
1247 cgm.errorNYI(expr->getSourceRange(),
1248 std::string("unimplemented X86 builtin call: ") +
1249 getContext().BuiltinInfo.getName(builtinID));
1250 return {};
1251 }
1252 case X86::BI__builtin_ia32_compressstoredf128_mask:
1253 case X86::BI__builtin_ia32_compressstoredf256_mask:
1254 case X86::BI__builtin_ia32_compressstoredf512_mask:
1255 case X86::BI__builtin_ia32_compressstoresf128_mask:
1256 case X86::BI__builtin_ia32_compressstoresf256_mask:
1257 case X86::BI__builtin_ia32_compressstoresf512_mask:
1258 case X86::BI__builtin_ia32_compressstoredi128_mask:
1259 case X86::BI__builtin_ia32_compressstoredi256_mask:
1260 case X86::BI__builtin_ia32_compressstoredi512_mask:
1261 case X86::BI__builtin_ia32_compressstoresi128_mask:
1262 case X86::BI__builtin_ia32_compressstoresi256_mask:
1263 case X86::BI__builtin_ia32_compressstoresi512_mask:
1264 case X86::BI__builtin_ia32_compressstorehi128_mask:
1265 case X86::BI__builtin_ia32_compressstorehi256_mask:
1266 case X86::BI__builtin_ia32_compressstorehi512_mask:
1267 case X86::BI__builtin_ia32_compressstoreqi128_mask:
1268 case X86::BI__builtin_ia32_compressstoreqi256_mask:
1269 case X86::BI__builtin_ia32_compressstoreqi512_mask:
1270 return emitX86CompressStore(builder, getLoc(expr->getExprLoc()), ops);
1271 case X86::BI__builtin_ia32_expanddf128_mask:
1272 case X86::BI__builtin_ia32_expanddf256_mask:
1273 case X86::BI__builtin_ia32_expanddf512_mask:
1274 case X86::BI__builtin_ia32_expandsf128_mask:
1275 case X86::BI__builtin_ia32_expandsf256_mask:
1276 case X86::BI__builtin_ia32_expandsf512_mask:
1277 case X86::BI__builtin_ia32_expanddi128_mask:
1278 case X86::BI__builtin_ia32_expanddi256_mask:
1279 case X86::BI__builtin_ia32_expanddi512_mask:
1280 case X86::BI__builtin_ia32_expandsi128_mask:
1281 case X86::BI__builtin_ia32_expandsi256_mask:
1282 case X86::BI__builtin_ia32_expandsi512_mask:
1283 case X86::BI__builtin_ia32_expandhi128_mask:
1284 case X86::BI__builtin_ia32_expandhi256_mask:
1285 case X86::BI__builtin_ia32_expandhi512_mask:
1286 case X86::BI__builtin_ia32_expandqi128_mask:
1287 case X86::BI__builtin_ia32_expandqi256_mask:
1288 case X86::BI__builtin_ia32_expandqi512_mask: {
1289 mlir::Location loc = getLoc(expr->getExprLoc());
1290 return emitX86CompressExpand(builder, loc, ops[0], ops[1], ops[2],
1291 "x86.avx512.mask.expand");
1292 }
1293 case X86::BI__builtin_ia32_compressdf128_mask:
1294 case X86::BI__builtin_ia32_compressdf256_mask:
1295 case X86::BI__builtin_ia32_compressdf512_mask:
1296 case X86::BI__builtin_ia32_compresssf128_mask:
1297 case X86::BI__builtin_ia32_compresssf256_mask:
1298 case X86::BI__builtin_ia32_compresssf512_mask:
1299 case X86::BI__builtin_ia32_compressdi128_mask:
1300 case X86::BI__builtin_ia32_compressdi256_mask:
1301 case X86::BI__builtin_ia32_compressdi512_mask:
1302 case X86::BI__builtin_ia32_compresssi128_mask:
1303 case X86::BI__builtin_ia32_compresssi256_mask:
1304 case X86::BI__builtin_ia32_compresssi512_mask:
1305 case X86::BI__builtin_ia32_compresshi128_mask:
1306 case X86::BI__builtin_ia32_compresshi256_mask:
1307 case X86::BI__builtin_ia32_compresshi512_mask:
1308 case X86::BI__builtin_ia32_compressqi128_mask:
1309 case X86::BI__builtin_ia32_compressqi256_mask:
1310 case X86::BI__builtin_ia32_compressqi512_mask: {
1311 mlir::Location loc = getLoc(expr->getExprLoc());
1312 return emitX86CompressExpand(builder, loc, ops[0], ops[1], ops[2],
1313 "x86.avx512.mask.compress");
1314 }
1315 case X86::BI__builtin_ia32_gather3div2df:
1316 case X86::BI__builtin_ia32_gather3div2di:
1317 case X86::BI__builtin_ia32_gather3div4df:
1318 case X86::BI__builtin_ia32_gather3div4di:
1319 case X86::BI__builtin_ia32_gather3div4sf:
1320 case X86::BI__builtin_ia32_gather3div4si:
1321 case X86::BI__builtin_ia32_gather3div8sf:
1322 case X86::BI__builtin_ia32_gather3div8si:
1323 case X86::BI__builtin_ia32_gather3siv2df:
1324 case X86::BI__builtin_ia32_gather3siv2di:
1325 case X86::BI__builtin_ia32_gather3siv4df:
1326 case X86::BI__builtin_ia32_gather3siv4di:
1327 case X86::BI__builtin_ia32_gather3siv4sf:
1328 case X86::BI__builtin_ia32_gather3siv4si:
1329 case X86::BI__builtin_ia32_gather3siv8sf:
1330 case X86::BI__builtin_ia32_gather3siv8si:
1331 case X86::BI__builtin_ia32_gathersiv8df:
1332 case X86::BI__builtin_ia32_gathersiv16sf:
1333 case X86::BI__builtin_ia32_gatherdiv8df:
1334 case X86::BI__builtin_ia32_gatherdiv16sf:
1335 case X86::BI__builtin_ia32_gathersiv8di:
1336 case X86::BI__builtin_ia32_gathersiv16si:
1337 case X86::BI__builtin_ia32_gatherdiv8di:
1338 case X86::BI__builtin_ia32_gatherdiv16si: {
1339 StringRef intrinsicName;
1340 switch (builtinID) {
1341 default:
1342 llvm_unreachable("Unexpected builtin");
1343 case X86::BI__builtin_ia32_gather3div2df:
1344 intrinsicName = "x86.avx512.mask.gather3div2.df";
1345 break;
1346 case X86::BI__builtin_ia32_gather3div2di:
1347 intrinsicName = "x86.avx512.mask.gather3div2.di";
1348 break;
1349 case X86::BI__builtin_ia32_gather3div4df:
1350 intrinsicName = "x86.avx512.mask.gather3div4.df";
1351 break;
1352 case X86::BI__builtin_ia32_gather3div4di:
1353 intrinsicName = "x86.avx512.mask.gather3div4.di";
1354 break;
1355 case X86::BI__builtin_ia32_gather3div4sf:
1356 intrinsicName = "x86.avx512.mask.gather3div4.sf";
1357 break;
1358 case X86::BI__builtin_ia32_gather3div4si:
1359 intrinsicName = "x86.avx512.mask.gather3div4.si";
1360 break;
1361 case X86::BI__builtin_ia32_gather3div8sf:
1362 intrinsicName = "x86.avx512.mask.gather3div8.sf";
1363 break;
1364 case X86::BI__builtin_ia32_gather3div8si:
1365 intrinsicName = "x86.avx512.mask.gather3div8.si";
1366 break;
1367 case X86::BI__builtin_ia32_gather3siv2df:
1368 intrinsicName = "x86.avx512.mask.gather3siv2.df";
1369 break;
1370 case X86::BI__builtin_ia32_gather3siv2di:
1371 intrinsicName = "x86.avx512.mask.gather3siv2.di";
1372 break;
1373 case X86::BI__builtin_ia32_gather3siv4df:
1374 intrinsicName = "x86.avx512.mask.gather3siv4.df";
1375 break;
1376 case X86::BI__builtin_ia32_gather3siv4di:
1377 intrinsicName = "x86.avx512.mask.gather3siv4.di";
1378 break;
1379 case X86::BI__builtin_ia32_gather3siv4sf:
1380 intrinsicName = "x86.avx512.mask.gather3siv4.sf";
1381 break;
1382 case X86::BI__builtin_ia32_gather3siv4si:
1383 intrinsicName = "x86.avx512.mask.gather3siv4.si";
1384 break;
1385 case X86::BI__builtin_ia32_gather3siv8sf:
1386 intrinsicName = "x86.avx512.mask.gather3siv8.sf";
1387 break;
1388 case X86::BI__builtin_ia32_gather3siv8si:
1389 intrinsicName = "x86.avx512.mask.gather3siv8.si";
1390 break;
1391 case X86::BI__builtin_ia32_gathersiv8df:
1392 intrinsicName = "x86.avx512.mask.gather.dpd.512";
1393 break;
1394 case X86::BI__builtin_ia32_gathersiv16sf:
1395 intrinsicName = "x86.avx512.mask.gather.dps.512";
1396 break;
1397 case X86::BI__builtin_ia32_gatherdiv8df:
1398 intrinsicName = "x86.avx512.mask.gather.qpd.512";
1399 break;
1400 case X86::BI__builtin_ia32_gatherdiv16sf:
1401 intrinsicName = "x86.avx512.mask.gather.qps.512";
1402 break;
1403 case X86::BI__builtin_ia32_gathersiv8di:
1404 intrinsicName = "x86.avx512.mask.gather.dpq.512";
1405 break;
1406 case X86::BI__builtin_ia32_gathersiv16si:
1407 intrinsicName = "x86.avx512.mask.gather.dpi.512";
1408 break;
1409 case X86::BI__builtin_ia32_gatherdiv8di:
1410 intrinsicName = "x86.avx512.mask.gather.qpq.512";
1411 break;
1412 case X86::BI__builtin_ia32_gatherdiv16si:
1413 intrinsicName = "x86.avx512.mask.gather.qpi.512";
1414 break;
1415 }
1416
1417 mlir::Location loc = getLoc(expr->getExprLoc());
1418 unsigned minElts =
1419 std::min(cast<cir::VectorType>(ops[0].getType()).getSize(),
1420 cast<cir::VectorType>(ops[2].getType()).getSize());
1421 ops[3] = getMaskVecValue(builder, loc, ops[3], minElts);
1422 return builder.emitIntrinsicCallOp(loc, intrinsicName,
1423 convertType(expr->getType()), ops);
1424 }
1425 case X86::BI__builtin_ia32_scattersiv8df:
1426 case X86::BI__builtin_ia32_scattersiv16sf:
1427 case X86::BI__builtin_ia32_scatterdiv8df:
1428 case X86::BI__builtin_ia32_scatterdiv16sf:
1429 case X86::BI__builtin_ia32_scattersiv8di:
1430 case X86::BI__builtin_ia32_scattersiv16si:
1431 case X86::BI__builtin_ia32_scatterdiv8di:
1432 case X86::BI__builtin_ia32_scatterdiv16si:
1433 case X86::BI__builtin_ia32_scatterdiv2df:
1434 case X86::BI__builtin_ia32_scatterdiv2di:
1435 case X86::BI__builtin_ia32_scatterdiv4df:
1436 case X86::BI__builtin_ia32_scatterdiv4di:
1437 case X86::BI__builtin_ia32_scatterdiv4sf:
1438 case X86::BI__builtin_ia32_scatterdiv4si:
1439 case X86::BI__builtin_ia32_scatterdiv8sf:
1440 case X86::BI__builtin_ia32_scatterdiv8si:
1441 case X86::BI__builtin_ia32_scattersiv2df:
1442 case X86::BI__builtin_ia32_scattersiv2di:
1443 case X86::BI__builtin_ia32_scattersiv4df:
1444 case X86::BI__builtin_ia32_scattersiv4di:
1445 case X86::BI__builtin_ia32_scattersiv4sf:
1446 case X86::BI__builtin_ia32_scattersiv4si:
1447 case X86::BI__builtin_ia32_scattersiv8sf:
1448 case X86::BI__builtin_ia32_scattersiv8si: {
1449 llvm::StringRef intrinsicName;
1450 switch (builtinID) {
1451 default:
1452 llvm_unreachable("Unexpected builtin");
1453 case X86::BI__builtin_ia32_scattersiv8df:
1454 intrinsicName = "x86.avx512.mask.scatter.dpd.512";
1455 break;
1456 case X86::BI__builtin_ia32_scattersiv16sf:
1457 intrinsicName = "x86.avx512.mask.scatter.dps.512";
1458 break;
1459 case X86::BI__builtin_ia32_scatterdiv8df:
1460 intrinsicName = "x86.avx512.mask.scatter.qpd.512";
1461 break;
1462 case X86::BI__builtin_ia32_scatterdiv16sf:
1463 intrinsicName = "x86.avx512.mask.scatter.qps.512";
1464 break;
1465 case X86::BI__builtin_ia32_scattersiv8di:
1466 intrinsicName = "x86.avx512.mask.scatter.dpq.512";
1467 break;
1468 case X86::BI__builtin_ia32_scattersiv16si:
1469 intrinsicName = "x86.avx512.mask.scatter.dpi.512";
1470 break;
1471 case X86::BI__builtin_ia32_scatterdiv8di:
1472 intrinsicName = "x86.avx512.mask.scatter.qpq.512";
1473 break;
1474 case X86::BI__builtin_ia32_scatterdiv16si:
1475 intrinsicName = "x86.avx512.mask.scatter.qpi.512";
1476 break;
1477 case X86::BI__builtin_ia32_scatterdiv2df:
1478 intrinsicName = "x86.avx512.mask.scatterdiv2.df";
1479 break;
1480 case X86::BI__builtin_ia32_scatterdiv2di:
1481 intrinsicName = "x86.avx512.mask.scatterdiv2.di";
1482 break;
1483 case X86::BI__builtin_ia32_scatterdiv4df:
1484 intrinsicName = "x86.avx512.mask.scatterdiv4.df";
1485 break;
1486 case X86::BI__builtin_ia32_scatterdiv4di:
1487 intrinsicName = "x86.avx512.mask.scatterdiv4.di";
1488 break;
1489 case X86::BI__builtin_ia32_scatterdiv4sf:
1490 intrinsicName = "x86.avx512.mask.scatterdiv4.sf";
1491 break;
1492 case X86::BI__builtin_ia32_scatterdiv4si:
1493 intrinsicName = "x86.avx512.mask.scatterdiv4.si";
1494 break;
1495 case X86::BI__builtin_ia32_scatterdiv8sf:
1496 intrinsicName = "x86.avx512.mask.scatterdiv8.sf";
1497 break;
1498 case X86::BI__builtin_ia32_scatterdiv8si:
1499 intrinsicName = "x86.avx512.mask.scatterdiv8.si";
1500 break;
1501 case X86::BI__builtin_ia32_scattersiv2df:
1502 intrinsicName = "x86.avx512.mask.scattersiv2.df";
1503 break;
1504 case X86::BI__builtin_ia32_scattersiv2di:
1505 intrinsicName = "x86.avx512.mask.scattersiv2.di";
1506 break;
1507 case X86::BI__builtin_ia32_scattersiv4df:
1508 intrinsicName = "x86.avx512.mask.scattersiv4.df";
1509 break;
1510 case X86::BI__builtin_ia32_scattersiv4di:
1511 intrinsicName = "x86.avx512.mask.scattersiv4.di";
1512 break;
1513 case X86::BI__builtin_ia32_scattersiv4sf:
1514 intrinsicName = "x86.avx512.mask.scattersiv4.sf";
1515 break;
1516 case X86::BI__builtin_ia32_scattersiv4si:
1517 intrinsicName = "x86.avx512.mask.scattersiv4.si";
1518 break;
1519 case X86::BI__builtin_ia32_scattersiv8sf:
1520 intrinsicName = "x86.avx512.mask.scattersiv8.sf";
1521 break;
1522 case X86::BI__builtin_ia32_scattersiv8si:
1523 intrinsicName = "x86.avx512.mask.scattersiv8.si";
1524 break;
1525 }
1526
1527 mlir::Location loc = getLoc(expr->getExprLoc());
1528 unsigned minElts =
1529 std::min(cast<cir::VectorType>(ops[2].getType()).getSize(),
1530 cast<cir::VectorType>(ops[3].getType()).getSize());
1531 ops[1] = getMaskVecValue(builder, loc, ops[1], minElts);
1532
1533 return builder.emitIntrinsicCallOp(loc, intrinsicName,
1534 convertType(expr->getType()), ops);
1535 }
1536 case X86::BI__builtin_ia32_vextractf128_pd256:
1537 case X86::BI__builtin_ia32_vextractf128_ps256:
1538 case X86::BI__builtin_ia32_vextractf128_si256:
1539 case X86::BI__builtin_ia32_extract128i256:
1540 case X86::BI__builtin_ia32_extractf64x4_mask:
1541 case X86::BI__builtin_ia32_extractf32x4_mask:
1542 case X86::BI__builtin_ia32_extracti64x4_mask:
1543 case X86::BI__builtin_ia32_extracti32x4_mask:
1544 case X86::BI__builtin_ia32_extractf32x8_mask:
1545 case X86::BI__builtin_ia32_extracti32x8_mask:
1546 case X86::BI__builtin_ia32_extractf32x4_256_mask:
1547 case X86::BI__builtin_ia32_extracti32x4_256_mask:
1548 case X86::BI__builtin_ia32_extractf64x2_256_mask:
1549 case X86::BI__builtin_ia32_extracti64x2_256_mask:
1550 case X86::BI__builtin_ia32_extractf64x2_512_mask:
1551 case X86::BI__builtin_ia32_extracti64x2_512_mask: {
1552 mlir::Location loc = getLoc(expr->getExprLoc());
1553 cir::VectorType dstTy = cast<cir::VectorType>(convertType(expr->getType()));
1554 unsigned numElts = dstTy.getSize();
1555 unsigned srcNumElts = cast<cir::VectorType>(ops[0].getType()).getSize();
1556 unsigned subVectors = srcNumElts / numElts;
1557 assert(llvm::isPowerOf2_32(subVectors) && "Expected power of 2 subvectors");
1558 unsigned index =
1559 ops[1].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue();
1560
1561 index &= subVectors - 1; // Remove any extra bits.
1562 index *= numElts;
1563
1564 int64_t indices[16];
1565 std::iota(indices, indices + numElts, index);
1566
1567 mlir::Value poison =
1568 builder.getConstant(loc, cir::PoisonAttr::get(ops[0].getType()));
1569 mlir::Value res = builder.createVecShuffle(loc, ops[0], poison,
1570 ArrayRef(indices, numElts));
1571 if (ops.size() == 4)
1572 res = emitX86Select(builder, loc, ops[3], res, ops[2]);
1573
1574 return res;
1575 }
1576 case X86::BI__builtin_ia32_vinsertf128_pd256:
1577 case X86::BI__builtin_ia32_vinsertf128_ps256:
1578 case X86::BI__builtin_ia32_vinsertf128_si256:
1579 case X86::BI__builtin_ia32_insert128i256:
1580 case X86::BI__builtin_ia32_insertf64x4:
1581 case X86::BI__builtin_ia32_insertf32x4:
1582 case X86::BI__builtin_ia32_inserti64x4:
1583 case X86::BI__builtin_ia32_inserti32x4:
1584 case X86::BI__builtin_ia32_insertf32x8:
1585 case X86::BI__builtin_ia32_inserti32x8:
1586 case X86::BI__builtin_ia32_insertf32x4_256:
1587 case X86::BI__builtin_ia32_inserti32x4_256:
1588 case X86::BI__builtin_ia32_insertf64x2_256:
1589 case X86::BI__builtin_ia32_inserti64x2_256:
1590 case X86::BI__builtin_ia32_insertf64x2_512:
1591 case X86::BI__builtin_ia32_inserti64x2_512: {
1592 unsigned dstNumElts = cast<cir::VectorType>(ops[0].getType()).getSize();
1593 unsigned srcNumElts = cast<cir::VectorType>(ops[1].getType()).getSize();
1594 unsigned subVectors = dstNumElts / srcNumElts;
1595 assert(llvm::isPowerOf2_32(subVectors) && "Expected power of 2 subvectors");
1596 assert(dstNumElts <= 16);
1597
1598 uint64_t index = getZExtIntValueFromConstOp(ops[2]);
1599 index &= subVectors - 1; // Remove any extra bits.
1600 index *= srcNumElts;
1601
1602 llvm::SmallVector<int64_t, 16> mask(dstNumElts);
1603 for (unsigned i = 0; i != dstNumElts; ++i)
1604 mask[i] = (i >= srcNumElts) ? srcNumElts + (i % srcNumElts) : i;
1605
1606 mlir::Value op1 =
1607 builder.createVecShuffle(getLoc(expr->getExprLoc()), ops[1], mask);
1608
1609 for (unsigned i = 0; i != dstNumElts; ++i) {
1610 if (i >= index && i < (index + srcNumElts))
1611 mask[i] = (i - index) + dstNumElts;
1612 else
1613 mask[i] = i;
1614 }
1615
1616 return builder.createVecShuffle(getLoc(expr->getExprLoc()), ops[0], op1,
1617 mask);
1618 }
1619 case X86::BI__builtin_ia32_pmovqd512_mask:
1620 case X86::BI__builtin_ia32_pmovwb512_mask: {
1621 mlir::Value Res =
1622 builder.createIntCast(ops[0], cast<cir::VectorType>(ops[1].getType()));
1623 return emitX86Select(builder, getLoc(expr->getExprLoc()), ops[2], Res,
1624 ops[1]);
1625 }
1626 case X86::BI__builtin_ia32_pblendw128:
1627 case X86::BI__builtin_ia32_blendpd:
1628 case X86::BI__builtin_ia32_blendps:
1629 case X86::BI__builtin_ia32_blendpd256:
1630 case X86::BI__builtin_ia32_blendps256:
1631 case X86::BI__builtin_ia32_pblendw256:
1632 case X86::BI__builtin_ia32_pblendd128:
1633 case X86::BI__builtin_ia32_pblendd256: {
1634 uint32_t imm = getZExtIntValueFromConstOp(ops[2]);
1635 unsigned numElts = cast<cir::VectorType>(ops[0].getType()).getSize();
1636
1638 // If there are more than 8 elements, the immediate is used twice so make
1639 // sure we handle that.
1640 mlir::Type i32Ty = builder.getSInt32Ty();
1641 for (unsigned i = 0; i != numElts; ++i)
1642 indices.push_back(
1643 cir::IntAttr::get(i32Ty, ((imm >> (i % 8)) & 0x1) ? numElts + i : i));
1644
1645 return builder.createVecShuffle(getLoc(expr->getExprLoc()), ops[0], ops[1],
1646 indices);
1647 }
1648 case X86::BI__builtin_ia32_pshuflw:
1649 case X86::BI__builtin_ia32_pshuflw256:
1650 case X86::BI__builtin_ia32_pshuflw512:
1651 return emitPshufWord(builder, ops[0], ops[1], getLoc(expr->getExprLoc()),
1652 true);
1653 case X86::BI__builtin_ia32_pshufhw:
1654 case X86::BI__builtin_ia32_pshufhw256:
1655 case X86::BI__builtin_ia32_pshufhw512:
1656 return emitPshufWord(builder, ops[0], ops[1], getLoc(expr->getExprLoc()),
1657 false);
1658 case X86::BI__builtin_ia32_pshufd:
1659 case X86::BI__builtin_ia32_pshufd256:
1660 case X86::BI__builtin_ia32_pshufd512:
1661 case X86::BI__builtin_ia32_vpermilpd:
1662 case X86::BI__builtin_ia32_vpermilps:
1663 case X86::BI__builtin_ia32_vpermilpd256:
1664 case X86::BI__builtin_ia32_vpermilps256:
1665 case X86::BI__builtin_ia32_vpermilpd512:
1666 case X86::BI__builtin_ia32_vpermilps512: {
1667 const uint32_t imm = getSExtIntValueFromConstOp(ops[1]);
1668
1670 computeFullLaneShuffleMask(*this, ops[0], imm, false, mask);
1671
1672 return builder.createVecShuffle(getLoc(expr->getExprLoc()), ops[0], mask);
1673 }
1674 case X86::BI__builtin_ia32_shufpd:
1675 case X86::BI__builtin_ia32_shufpd256:
1676 case X86::BI__builtin_ia32_shufpd512:
1677 case X86::BI__builtin_ia32_shufps:
1678 case X86::BI__builtin_ia32_shufps256:
1679 case X86::BI__builtin_ia32_shufps512: {
1680 const uint32_t imm = getZExtIntValueFromConstOp(ops[2]);
1681
1683 computeFullLaneShuffleMask(*this, ops[0], imm, true, mask);
1684
1685 return builder.createVecShuffle(getLoc(expr->getExprLoc()), ops[0], ops[1],
1686 mask);
1687 }
1688 case X86::BI__builtin_ia32_permdi256:
1689 case X86::BI__builtin_ia32_permdf256:
1690 case X86::BI__builtin_ia32_permdi512:
1691 case X86::BI__builtin_ia32_permdf512: {
1692 unsigned imm =
1693 ops[1].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue();
1694 unsigned numElts = cast<cir::VectorType>(ops[0].getType()).getSize();
1695
1696 // These intrinsics operate on 256-bit lanes of four 64-bit elements.
1697 int64_t Indices[8];
1698
1699 for (unsigned l = 0; l != numElts; l += 4)
1700 for (unsigned i = 0; i != 4; ++i)
1701 Indices[l + i] = l + ((imm >> (2 * i)) & 0x3);
1702
1703 return builder.createVecShuffle(getLoc(expr->getExprLoc()), ops[0],
1704 ArrayRef(Indices, numElts));
1705 }
1706 case X86::BI__builtin_ia32_palignr128:
1707 case X86::BI__builtin_ia32_palignr256:
1708 case X86::BI__builtin_ia32_palignr512: {
1709 uint32_t shiftVal = getZExtIntValueFromConstOp(ops[2]) & 0xff;
1710
1711 unsigned numElts = cast<cir::VectorType>(ops[0].getType()).getSize();
1712 assert(numElts % 16 == 0);
1713
1714 // If palignr is shifting the pair of vectors more than the size of two
1715 // lanes, emit zero.
1716 if (shiftVal >= 32)
1717 return builder.getNullValue(convertType(expr->getType()),
1718 getLoc(expr->getExprLoc()));
1719
1720 // If palignr is shifting the pair of input vectors more than one lane,
1721 // but less than two lanes, convert to shifting in zeroes.
1722 if (shiftVal > 16) {
1723 shiftVal -= 16;
1724 ops[1] = ops[0];
1725 ops[0] =
1726 builder.getNullValue(ops[0].getType(), getLoc(expr->getExprLoc()));
1727 }
1728
1729 int64_t indices[64];
1730 // 256-bit palignr operates on 128-bit lanes so we need to handle that
1731 for (unsigned l = 0; l != numElts; l += 16) {
1732 for (unsigned i = 0; i != 16; ++i) {
1733 uint32_t idx = shiftVal + i;
1734 if (idx >= 16)
1735 idx += numElts - 16; // End of lane, switch operand.
1736 indices[l + i] = l + idx;
1737 }
1738 }
1739
1740 return builder.createVecShuffle(getLoc(expr->getExprLoc()), ops[1], ops[0],
1741 ArrayRef(indices, numElts));
1742 }
1743 case X86::BI__builtin_ia32_alignd128:
1744 case X86::BI__builtin_ia32_alignd256:
1745 case X86::BI__builtin_ia32_alignd512:
1746 case X86::BI__builtin_ia32_alignq128:
1747 case X86::BI__builtin_ia32_alignq256:
1748 case X86::BI__builtin_ia32_alignq512: {
1749 unsigned numElts = cast<cir::VectorType>(ops[0].getType()).getSize();
1750 unsigned shiftVal =
1751 ops[2].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue() &
1752 0xff;
1753
1754 // Mask the shift amount to width of a vector.
1755 shiftVal &= numElts - 1;
1756
1758 mlir::Type i32Ty = builder.getSInt32Ty();
1759 for (unsigned i = 0; i != numElts; ++i)
1760 indices.push_back(cir::IntAttr::get(i32Ty, i + shiftVal));
1761
1762 return builder.createVecShuffle(getLoc(expr->getExprLoc()), ops[0], ops[1],
1763 indices);
1764 }
1765 case X86::BI__builtin_ia32_shuf_f32x4_256:
1766 case X86::BI__builtin_ia32_shuf_f64x2_256:
1767 case X86::BI__builtin_ia32_shuf_i32x4_256:
1768 case X86::BI__builtin_ia32_shuf_i64x2_256:
1769 case X86::BI__builtin_ia32_shuf_f32x4:
1770 case X86::BI__builtin_ia32_shuf_f64x2:
1771 case X86::BI__builtin_ia32_shuf_i32x4:
1772 case X86::BI__builtin_ia32_shuf_i64x2: {
1773 mlir::Value src1 = ops[0];
1774 mlir::Value src2 = ops[1];
1775
1776 unsigned imm =
1777 ops[2].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue();
1778
1779 unsigned numElems = cast<cir::VectorType>(src1.getType()).getSize();
1780 unsigned totalBits = getContext().getTypeSize(expr->getArg(0)->getType());
1781 unsigned numLanes = totalBits == 512 ? 4 : 2;
1782 unsigned numElemsPerLane = numElems / numLanes;
1783
1785 mlir::Type i32Ty = builder.getSInt32Ty();
1786
1787 for (unsigned l = 0; l != numElems; l += numElemsPerLane) {
1788 unsigned index = (imm % numLanes) * numElemsPerLane;
1789 imm /= numLanes;
1790 if (l >= (numElems / 2))
1791 index += numElems;
1792 for (unsigned i = 0; i != numElemsPerLane; ++i) {
1793 indices.push_back(cir::IntAttr::get(i32Ty, index + i));
1794 }
1795 }
1796
1797 return builder.createVecShuffle(getLoc(expr->getExprLoc()), src1, src2,
1798 indices);
1799 }
1800 case X86::BI__builtin_ia32_vperm2f128_pd256:
1801 case X86::BI__builtin_ia32_vperm2f128_ps256:
1802 case X86::BI__builtin_ia32_vperm2f128_si256:
1803 case X86::BI__builtin_ia32_permti256:
1804 case X86::BI__builtin_ia32_pslldqi128_byteshift:
1805 case X86::BI__builtin_ia32_pslldqi256_byteshift:
1806 case X86::BI__builtin_ia32_pslldqi512_byteshift:
1807 case X86::BI__builtin_ia32_psrldqi128_byteshift:
1808 case X86::BI__builtin_ia32_psrldqi256_byteshift:
1809 case X86::BI__builtin_ia32_psrldqi512_byteshift:
1810 cgm.errorNYI(expr->getSourceRange(),
1811 std::string("unimplemented X86 builtin call: ") +
1812 getContext().BuiltinInfo.getName(builtinID));
1813 return mlir::Value{};
1814 case X86::BI__builtin_ia32_kshiftliqi:
1815 case X86::BI__builtin_ia32_kshiftlihi:
1816 case X86::BI__builtin_ia32_kshiftlisi:
1817 case X86::BI__builtin_ia32_kshiftlidi: {
1818 mlir::Location loc = getLoc(expr->getExprLoc());
1819 unsigned shiftVal =
1820 ops[1].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue() &
1821 0xff;
1822 unsigned numElems = cast<cir::IntType>(ops[0].getType()).getWidth();
1823
1824 if (shiftVal >= numElems)
1825 return builder.getNullValue(ops[0].getType(), loc);
1826
1827 mlir::Value in = getMaskVecValue(builder, loc, ops[0], numElems);
1828
1830 mlir::Type i32Ty = builder.getSInt32Ty();
1831 for (auto i : llvm::seq<unsigned>(0, numElems))
1832 indices.push_back(cir::IntAttr::get(i32Ty, numElems + i - shiftVal));
1833
1834 mlir::Value zero = builder.getNullValue(in.getType(), loc);
1835 mlir::Value sv = builder.createVecShuffle(loc, zero, in, indices);
1836 return builder.createBitcast(sv, ops[0].getType());
1837 }
1838 case X86::BI__builtin_ia32_kshiftriqi:
1839 case X86::BI__builtin_ia32_kshiftrihi:
1840 case X86::BI__builtin_ia32_kshiftrisi:
1841 case X86::BI__builtin_ia32_kshiftridi: {
1842 mlir::Location loc = getLoc(expr->getExprLoc());
1843 unsigned shiftVal =
1844 ops[1].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue() &
1845 0xff;
1846 unsigned numElems = cast<cir::IntType>(ops[0].getType()).getWidth();
1847
1848 if (shiftVal >= numElems)
1849 return builder.getNullValue(ops[0].getType(), loc);
1850
1851 mlir::Value in = getMaskVecValue(builder, loc, ops[0], numElems);
1852
1854 mlir::Type i32Ty = builder.getSInt32Ty();
1855 for (auto i : llvm::seq<unsigned>(0, numElems))
1856 indices.push_back(cir::IntAttr::get(i32Ty, i + shiftVal));
1857
1858 mlir::Value zero = builder.getNullValue(in.getType(), loc);
1859 mlir::Value sv = builder.createVecShuffle(loc, in, zero, indices);
1860 return builder.createBitcast(sv, ops[0].getType());
1861 }
1862 case X86::BI__builtin_ia32_vprotbi:
1863 case X86::BI__builtin_ia32_vprotwi:
1864 case X86::BI__builtin_ia32_vprotdi:
1865 case X86::BI__builtin_ia32_vprotqi:
1866 case X86::BI__builtin_ia32_prold128:
1867 case X86::BI__builtin_ia32_prold256:
1868 case X86::BI__builtin_ia32_prold512:
1869 case X86::BI__builtin_ia32_prolq128:
1870 case X86::BI__builtin_ia32_prolq256:
1871 case X86::BI__builtin_ia32_prolq512:
1872 return emitX86FunnelShift(builder, getLoc(expr->getExprLoc()), ops[0],
1873 ops[0], ops[1], false);
1874 case X86::BI__builtin_ia32_prord128:
1875 case X86::BI__builtin_ia32_prord256:
1876 case X86::BI__builtin_ia32_prord512:
1877 case X86::BI__builtin_ia32_prorq128:
1878 case X86::BI__builtin_ia32_prorq256:
1879 case X86::BI__builtin_ia32_prorq512:
1880 return emitX86FunnelShift(builder, getLoc(expr->getExprLoc()), ops[0],
1881 ops[0], ops[1], true);
1882 case X86::BI__builtin_ia32_selectb_128:
1883 case X86::BI__builtin_ia32_selectb_256:
1884 case X86::BI__builtin_ia32_selectb_512:
1885 case X86::BI__builtin_ia32_selectw_128:
1886 case X86::BI__builtin_ia32_selectw_256:
1887 case X86::BI__builtin_ia32_selectw_512:
1888 case X86::BI__builtin_ia32_selectd_128:
1889 case X86::BI__builtin_ia32_selectd_256:
1890 case X86::BI__builtin_ia32_selectd_512:
1891 case X86::BI__builtin_ia32_selectq_128:
1892 case X86::BI__builtin_ia32_selectq_256:
1893 case X86::BI__builtin_ia32_selectq_512:
1894 case X86::BI__builtin_ia32_selectph_128:
1895 case X86::BI__builtin_ia32_selectph_256:
1896 case X86::BI__builtin_ia32_selectph_512:
1897 case X86::BI__builtin_ia32_selectpbf_128:
1898 case X86::BI__builtin_ia32_selectpbf_256:
1899 case X86::BI__builtin_ia32_selectpbf_512:
1900 case X86::BI__builtin_ia32_selectps_128:
1901 case X86::BI__builtin_ia32_selectps_256:
1902 case X86::BI__builtin_ia32_selectps_512:
1903 case X86::BI__builtin_ia32_selectpd_128:
1904 case X86::BI__builtin_ia32_selectpd_256:
1905 case X86::BI__builtin_ia32_selectpd_512:
1906 return emitX86Select(builder, getLoc(expr->getExprLoc()), ops[0], ops[1],
1907 ops[2]);
1908 case X86::BI__builtin_ia32_selectsh_128:
1909 case X86::BI__builtin_ia32_selectsbf_128:
1910 case X86::BI__builtin_ia32_selectss_128:
1911 case X86::BI__builtin_ia32_selectsd_128: {
1912 mlir::Location loc = getLoc(expr->getExprLoc());
1913 mlir::Value scalar1 =
1914 builder.createExtractElement(loc, ops[1], uint64_t(0));
1915 mlir::Value scalar2 =
1916 builder.createExtractElement(loc, ops[2], uint64_t(0));
1917 mlir::Value result =
1918 emitX86ScalarSelect(builder, loc, ops[0], scalar1, scalar2);
1919 return builder.createInsertElement(loc, ops[1], result, uint64_t(0));
1920 }
1921 case X86::BI__builtin_ia32_cmpb128_mask:
1922 case X86::BI__builtin_ia32_cmpb256_mask:
1923 case X86::BI__builtin_ia32_cmpb512_mask:
1924 case X86::BI__builtin_ia32_cmpw128_mask:
1925 case X86::BI__builtin_ia32_cmpw256_mask:
1926 case X86::BI__builtin_ia32_cmpw512_mask:
1927 case X86::BI__builtin_ia32_cmpd128_mask:
1928 case X86::BI__builtin_ia32_cmpd256_mask:
1929 case X86::BI__builtin_ia32_cmpd512_mask:
1930 case X86::BI__builtin_ia32_cmpq128_mask:
1931 case X86::BI__builtin_ia32_cmpq256_mask:
1932 case X86::BI__builtin_ia32_cmpq512_mask:
1933 case X86::BI__builtin_ia32_ucmpb128_mask:
1934 case X86::BI__builtin_ia32_ucmpb256_mask:
1935 case X86::BI__builtin_ia32_ucmpb512_mask:
1936 case X86::BI__builtin_ia32_ucmpw128_mask:
1937 case X86::BI__builtin_ia32_ucmpw256_mask:
1938 case X86::BI__builtin_ia32_ucmpw512_mask:
1939 case X86::BI__builtin_ia32_ucmpd128_mask:
1940 case X86::BI__builtin_ia32_ucmpd256_mask:
1941 case X86::BI__builtin_ia32_ucmpd512_mask:
1942 case X86::BI__builtin_ia32_ucmpq128_mask:
1943 case X86::BI__builtin_ia32_ucmpq256_mask:
1944 case X86::BI__builtin_ia32_ucmpq512_mask: {
1945 int64_t cc = CIRGenFunction::getZExtIntValueFromConstOp(ops[2]) & 0x7;
1946 return emitX86MaskedCompare(builder, cc, 1, ops,
1947 getLoc(expr->getExprLoc()));
1948 }
1949 case X86::BI__builtin_ia32_vpcomb:
1950 case X86::BI__builtin_ia32_vpcomw:
1951 case X86::BI__builtin_ia32_vpcomd:
1952 case X86::BI__builtin_ia32_vpcomq:
1953 return emitX86vpcom(builder, getLoc(expr->getExprLoc()), ops, true);
1954 case X86::BI__builtin_ia32_vpcomub:
1955 case X86::BI__builtin_ia32_vpcomuw:
1956 case X86::BI__builtin_ia32_vpcomud:
1957 case X86::BI__builtin_ia32_vpcomuq:
1958 return emitX86vpcom(builder, getLoc(expr->getExprLoc()), ops, false);
1959 case X86::BI__builtin_ia32_kortestcqi:
1960 case X86::BI__builtin_ia32_kortestchi:
1961 case X86::BI__builtin_ia32_kortestcsi:
1962 case X86::BI__builtin_ia32_kortestcdi: {
1963 mlir::Location loc = getLoc(expr->getExprLoc());
1964 cir::IntType ty = cast<cir::IntType>(ops[0].getType());
1965 mlir::Value allOnesOp =
1966 builder.getConstAPInt(loc, ty, APInt::getAllOnes(ty.getWidth()));
1967 mlir::Value orOp = emitX86MaskLogic<cir::OrOp>(builder, loc, ops);
1968 mlir::Value cmp =
1969 cir::CmpOp::create(builder, loc, cir::CmpOpKind::eq, orOp, allOnesOp);
1970 return builder.createCast(cir::CastKind::bool_to_int, cmp,
1971 cgm.convertType(expr->getType()));
1972 }
1973 case X86::BI__builtin_ia32_kortestzqi:
1974 case X86::BI__builtin_ia32_kortestzhi:
1975 case X86::BI__builtin_ia32_kortestzsi:
1976 case X86::BI__builtin_ia32_kortestzdi: {
1977 mlir::Location loc = getLoc(expr->getExprLoc());
1978 cir::IntType ty = cast<cir::IntType>(ops[0].getType());
1979 mlir::Value allZerosOp = builder.getNullValue(ty, loc).getResult();
1980 mlir::Value orOp = emitX86MaskLogic<cir::OrOp>(builder, loc, ops);
1981 mlir::Value cmp =
1982 cir::CmpOp::create(builder, loc, cir::CmpOpKind::eq, orOp, allZerosOp);
1983 return builder.createCast(cir::CastKind::bool_to_int, cmp,
1984 cgm.convertType(expr->getType()));
1985 }
1986 case X86::BI__builtin_ia32_ktestcqi:
1987 return emitX86MaskTest(builder, getLoc(expr->getExprLoc()),
1988 "x86.avx512.ktestc.b", ops);
1989 case X86::BI__builtin_ia32_ktestzqi:
1990 return emitX86MaskTest(builder, getLoc(expr->getExprLoc()),
1991 "x86.avx512.ktestz.b", ops);
1992 case X86::BI__builtin_ia32_ktestchi:
1993 return emitX86MaskTest(builder, getLoc(expr->getExprLoc()),
1994 "x86.avx512.ktestc.w", ops);
1995 case X86::BI__builtin_ia32_ktestzhi:
1996 return emitX86MaskTest(builder, getLoc(expr->getExprLoc()),
1997 "x86.avx512.ktestz.w", ops);
1998 case X86::BI__builtin_ia32_ktestcsi:
1999 return emitX86MaskTest(builder, getLoc(expr->getExprLoc()),
2000 "x86.avx512.ktestc.d", ops);
2001 case X86::BI__builtin_ia32_ktestzsi:
2002 return emitX86MaskTest(builder, getLoc(expr->getExprLoc()),
2003 "x86.avx512.ktestz.d", ops);
2004 case X86::BI__builtin_ia32_ktestcdi:
2005 return emitX86MaskTest(builder, getLoc(expr->getExprLoc()),
2006 "x86.avx512.ktestc.q", ops);
2007 case X86::BI__builtin_ia32_ktestzdi:
2008 return emitX86MaskTest(builder, getLoc(expr->getExprLoc()),
2009 "x86.avx512.ktestz.q", ops);
2010 case X86::BI__builtin_ia32_kaddqi:
2011 return emitX86MaskAddLogic(builder, getLoc(expr->getExprLoc()),
2012 "x86.avx512.kadd.b", ops);
2013 case X86::BI__builtin_ia32_kaddhi:
2014 return emitX86MaskAddLogic(builder, getLoc(expr->getExprLoc()),
2015 "x86.avx512.kadd.w", ops);
2016 case X86::BI__builtin_ia32_kaddsi:
2017 return emitX86MaskAddLogic(builder, getLoc(expr->getExprLoc()),
2018 "x86.avx512.kadd.d", ops);
2019 case X86::BI__builtin_ia32_kadddi:
2020 return emitX86MaskAddLogic(builder, getLoc(expr->getExprLoc()),
2021 "x86.avx512.kadd.q", ops);
2022 case X86::BI__builtin_ia32_kandqi:
2023 case X86::BI__builtin_ia32_kandhi:
2024 case X86::BI__builtin_ia32_kandsi:
2025 case X86::BI__builtin_ia32_kanddi:
2026 return emitX86MaskLogic<cir::AndOp>(builder, getLoc(expr->getExprLoc()),
2027 ops);
2028 case X86::BI__builtin_ia32_kandnqi:
2029 case X86::BI__builtin_ia32_kandnhi:
2030 case X86::BI__builtin_ia32_kandnsi:
2031 case X86::BI__builtin_ia32_kandndi:
2032 return emitX86MaskLogic<cir::AndOp>(builder, getLoc(expr->getExprLoc()),
2033 ops, /*invertLHS=*/true);
2034 case X86::BI__builtin_ia32_korqi:
2035 case X86::BI__builtin_ia32_korhi:
2036 case X86::BI__builtin_ia32_korsi:
2037 case X86::BI__builtin_ia32_kordi:
2038 return emitX86MaskLogic<cir::OrOp>(builder, getLoc(expr->getExprLoc()),
2039 ops);
2040 case X86::BI__builtin_ia32_kxnorqi:
2041 case X86::BI__builtin_ia32_kxnorhi:
2042 case X86::BI__builtin_ia32_kxnorsi:
2043 case X86::BI__builtin_ia32_kxnordi:
2044 return emitX86MaskLogic<cir::XorOp>(builder, getLoc(expr->getExprLoc()),
2045 ops, /*invertLHS=*/true);
2046 case X86::BI__builtin_ia32_kxorqi:
2047 case X86::BI__builtin_ia32_kxorhi:
2048 case X86::BI__builtin_ia32_kxorsi:
2049 case X86::BI__builtin_ia32_kxordi:
2050 return emitX86MaskLogic<cir::XorOp>(builder, getLoc(expr->getExprLoc()),
2051 ops);
2052 case X86::BI__builtin_ia32_knotqi:
2053 case X86::BI__builtin_ia32_knothi:
2054 case X86::BI__builtin_ia32_knotsi:
2055 case X86::BI__builtin_ia32_knotdi: {
2056 cir::IntType intTy = cast<cir::IntType>(ops[0].getType());
2057 unsigned numElts = intTy.getWidth();
2058 mlir::Value resVec =
2059 getMaskVecValue(builder, getLoc(expr->getExprLoc()), ops[0], numElts);
2060 return builder.createBitcast(builder.createNot(resVec), ops[0].getType());
2061 }
2062 case X86::BI__builtin_ia32_kmovb:
2063 case X86::BI__builtin_ia32_kmovw:
2064 case X86::BI__builtin_ia32_kmovd:
2065 case X86::BI__builtin_ia32_kmovq: {
2066 // Bitcast to vXi1 type and then back to integer. This gets the mask
2067 // register type into the IR, but might be optimized out depending on
2068 // what's around it.
2069 cir::IntType intTy = cast<cir::IntType>(ops[0].getType());
2070 unsigned numElts = intTy.getWidth();
2071 mlir::Value resVec =
2072 getMaskVecValue(builder, getLoc(expr->getExprLoc()), ops[0], numElts);
2073 return builder.createBitcast(resVec, ops[0].getType());
2074 }
2075 case X86::BI__builtin_ia32_sqrtsh_round_mask:
2076 case X86::BI__builtin_ia32_sqrtsd_round_mask:
2077 case X86::BI__builtin_ia32_sqrtss_round_mask:
2078 cgm.errorNYI(expr->getSourceRange(),
2079 std::string("unimplemented X86 builtin call: ") +
2080 getContext().BuiltinInfo.getName(builtinID));
2081 return mlir::Value{};
2082 case X86::BI__builtin_ia32_sqrtph512:
2083 case X86::BI__builtin_ia32_sqrtps512:
2084 case X86::BI__builtin_ia32_sqrtpd512: {
2085 mlir::Location loc = getLoc(expr->getExprLoc());
2086 mlir::Value arg = ops[0];
2087 return cir::SqrtOp::create(builder, loc, arg.getType(), arg).getResult();
2088 }
2089 case X86::BI__builtin_ia32_pmuludq128:
2090 case X86::BI__builtin_ia32_pmuludq256:
2091 case X86::BI__builtin_ia32_pmuludq512: {
2092 unsigned opTypePrimitiveSizeInBits =
2093 cgm.getDataLayout().getTypeSizeInBits(ops[0].getType());
2094 return emitX86Muldq(builder, getLoc(expr->getExprLoc()), /*isSigned*/ false,
2095 ops, opTypePrimitiveSizeInBits);
2096 }
2097 case X86::BI__builtin_ia32_pmuldq128:
2098 case X86::BI__builtin_ia32_pmuldq256:
2099 case X86::BI__builtin_ia32_pmuldq512: {
2100 unsigned opTypePrimitiveSizeInBits =
2101 cgm.getDataLayout().getTypeSizeInBits(ops[0].getType());
2102 return emitX86Muldq(builder, getLoc(expr->getExprLoc()), /*isSigned*/ true,
2103 ops, opTypePrimitiveSizeInBits);
2104 }
2105 case X86::BI__builtin_ia32_pternlogd512_mask:
2106 case X86::BI__builtin_ia32_pternlogq512_mask:
2107 case X86::BI__builtin_ia32_pternlogd128_mask:
2108 case X86::BI__builtin_ia32_pternlogd256_mask:
2109 case X86::BI__builtin_ia32_pternlogq128_mask:
2110 case X86::BI__builtin_ia32_pternlogq256_mask:
2111 case X86::BI__builtin_ia32_pternlogd512_maskz:
2112 case X86::BI__builtin_ia32_pternlogq512_maskz:
2113 case X86::BI__builtin_ia32_pternlogd128_maskz:
2114 case X86::BI__builtin_ia32_pternlogd256_maskz:
2115 case X86::BI__builtin_ia32_pternlogq128_maskz:
2116 case X86::BI__builtin_ia32_pternlogq256_maskz:
2117 cgm.errorNYI(expr->getSourceRange(),
2118 std::string("unimplemented X86 builtin call: ") +
2119 getContext().BuiltinInfo.getName(builtinID));
2120 return mlir::Value{};
2121 case X86::BI__builtin_ia32_vpshldd128:
2122 case X86::BI__builtin_ia32_vpshldd256:
2123 case X86::BI__builtin_ia32_vpshldd512:
2124 case X86::BI__builtin_ia32_vpshldq128:
2125 case X86::BI__builtin_ia32_vpshldq256:
2126 case X86::BI__builtin_ia32_vpshldq512:
2127 case X86::BI__builtin_ia32_vpshldw128:
2128 case X86::BI__builtin_ia32_vpshldw256:
2129 case X86::BI__builtin_ia32_vpshldw512:
2130 return emitX86FunnelShift(builder, getLoc(expr->getExprLoc()), ops[0],
2131 ops[1], ops[2], false);
2132 case X86::BI__builtin_ia32_vpshrdd128:
2133 case X86::BI__builtin_ia32_vpshrdd256:
2134 case X86::BI__builtin_ia32_vpshrdd512:
2135 case X86::BI__builtin_ia32_vpshrdq128:
2136 case X86::BI__builtin_ia32_vpshrdq256:
2137 case X86::BI__builtin_ia32_vpshrdq512:
2138 case X86::BI__builtin_ia32_vpshrdw128:
2139 case X86::BI__builtin_ia32_vpshrdw256:
2140 case X86::BI__builtin_ia32_vpshrdw512:
2141 // Ops 0 and 1 are swapped.
2142 return emitX86FunnelShift(builder, getLoc(expr->getExprLoc()), ops[1],
2143 ops[0], ops[2], true);
2144 case X86::BI__builtin_ia32_reduce_fadd_pd512:
2145 case X86::BI__builtin_ia32_reduce_fadd_ps512:
2146 case X86::BI__builtin_ia32_reduce_fadd_ph512:
2147 case X86::BI__builtin_ia32_reduce_fadd_ph256:
2148 case X86::BI__builtin_ia32_reduce_fadd_ph128: {
2150 return builder.emitIntrinsicCallOp(getLoc(expr->getExprLoc()),
2151 "vector.reduce.fadd", ops[0].getType(),
2152 mlir::ValueRange{ops[0], ops[1]});
2153 }
2154 case X86::BI__builtin_ia32_reduce_fmul_pd512:
2155 case X86::BI__builtin_ia32_reduce_fmul_ps512:
2156 case X86::BI__builtin_ia32_reduce_fmul_ph512:
2157 case X86::BI__builtin_ia32_reduce_fmul_ph256:
2158 case X86::BI__builtin_ia32_reduce_fmul_ph128: {
2160 return builder.emitIntrinsicCallOp(getLoc(expr->getExprLoc()),
2161 "vector.reduce.fmul", ops[0].getType(),
2162 mlir::ValueRange{ops[0], ops[1]});
2163 }
2164 case X86::BI__builtin_ia32_reduce_fmax_pd512:
2165 case X86::BI__builtin_ia32_reduce_fmax_ps512:
2166 case X86::BI__builtin_ia32_reduce_fmax_ph512:
2167 case X86::BI__builtin_ia32_reduce_fmax_ph256:
2168 case X86::BI__builtin_ia32_reduce_fmax_ph128: {
2170 cir::VectorType vecTy = cast<cir::VectorType>(ops[0].getType());
2171 return builder.emitIntrinsicCallOp(
2172 getLoc(expr->getExprLoc()), "vector.reduce.fmax",
2173 vecTy.getElementType(), mlir::ValueRange{ops[0]});
2174 }
2175 case X86::BI__builtin_ia32_reduce_fmin_pd512:
2176 case X86::BI__builtin_ia32_reduce_fmin_ps512:
2177 case X86::BI__builtin_ia32_reduce_fmin_ph512:
2178 case X86::BI__builtin_ia32_reduce_fmin_ph256:
2179 case X86::BI__builtin_ia32_reduce_fmin_ph128: {
2181 cir::VectorType vecTy = cast<cir::VectorType>(ops[0].getType());
2182 return builder.emitIntrinsicCallOp(
2183 getLoc(expr->getExprLoc()), "vector.reduce.fmin",
2184 vecTy.getElementType(), mlir::ValueRange{ops[0]});
2185 }
2186 case X86::BI__builtin_ia32_rdrand16_step:
2187 case X86::BI__builtin_ia32_rdrand32_step:
2188 case X86::BI__builtin_ia32_rdrand64_step:
2189 case X86::BI__builtin_ia32_rdseed16_step:
2190 case X86::BI__builtin_ia32_rdseed32_step:
2191 case X86::BI__builtin_ia32_rdseed64_step: {
2192 llvm::StringRef intrinsicName;
2193 switch (builtinID) {
2194 default:
2195 llvm_unreachable("Unsupported intrinsic!");
2196 case X86::BI__builtin_ia32_rdrand16_step:
2197 intrinsicName = "x86.rdrand.16";
2198 break;
2199 case X86::BI__builtin_ia32_rdrand32_step:
2200 intrinsicName = "x86.rdrand.32";
2201 break;
2202 case X86::BI__builtin_ia32_rdrand64_step:
2203 intrinsicName = "x86.rdrand.64";
2204 break;
2205 case X86::BI__builtin_ia32_rdseed16_step:
2206 intrinsicName = "x86.rdseed.16";
2207 break;
2208 case X86::BI__builtin_ia32_rdseed32_step:
2209 intrinsicName = "x86.rdseed.32";
2210 break;
2211 case X86::BI__builtin_ia32_rdseed64_step:
2212 intrinsicName = "x86.rdseed.64";
2213 break;
2214 }
2215
2216 mlir::Location loc = getLoc(expr->getExprLoc());
2217 mlir::Type randTy = cast<cir::PointerType>(ops[0].getType()).getPointee();
2218 llvm::SmallVector<mlir::Type, 2> resultTypes = {randTy,
2219 builder.getUInt32Ty()};
2220 cir::RecordType resRecord =
2221 cir::RecordType::get(&getMLIRContext(), resultTypes, false, false,
2222 cir::RecordType::RecordKind::Struct);
2223
2224 mlir::Value call =
2225 builder.emitIntrinsicCallOp(loc, intrinsicName, resRecord);
2226 mlir::Value rand =
2227 cir::ExtractMemberOp::create(builder, loc, randTy, call, 0);
2228 builder.CIRBaseBuilderTy::createStore(loc, rand, ops[0]);
2229
2230 return cir::ExtractMemberOp::create(builder, loc, builder.getUInt32Ty(),
2231 call, 1);
2232 }
2233 case X86::BI__builtin_ia32_addcarryx_u32:
2234 case X86::BI__builtin_ia32_addcarryx_u64:
2235 case X86::BI__builtin_ia32_subborrow_u32:
2236 case X86::BI__builtin_ia32_subborrow_u64:
2237 cgm.errorNYI(expr->getSourceRange(),
2238 std::string("unimplemented X86 builtin call: ") +
2239 getContext().BuiltinInfo.getName(builtinID));
2240 return mlir::Value{};
2241 case X86::BI__builtin_ia32_fpclassps128_mask:
2242 case X86::BI__builtin_ia32_fpclassps256_mask:
2243 case X86::BI__builtin_ia32_fpclassps512_mask:
2244 case X86::BI__builtin_ia32_vfpclassbf16128_mask:
2245 case X86::BI__builtin_ia32_vfpclassbf16256_mask:
2246 case X86::BI__builtin_ia32_vfpclassbf16512_mask:
2247 case X86::BI__builtin_ia32_fpclassph128_mask:
2248 case X86::BI__builtin_ia32_fpclassph256_mask:
2249 case X86::BI__builtin_ia32_fpclassph512_mask:
2250 case X86::BI__builtin_ia32_fpclasspd128_mask:
2251 case X86::BI__builtin_ia32_fpclasspd256_mask:
2252 case X86::BI__builtin_ia32_fpclasspd512_mask:
2253 return emitX86Fpclass(builder, getLoc(expr->getExprLoc()), builtinID, ops);
2254 case X86::BI__builtin_ia32_vp2intersect_q_512:
2255 case X86::BI__builtin_ia32_vp2intersect_q_256:
2256 case X86::BI__builtin_ia32_vp2intersect_q_128:
2257 case X86::BI__builtin_ia32_vp2intersect_d_512:
2258 case X86::BI__builtin_ia32_vp2intersect_d_256:
2259 case X86::BI__builtin_ia32_vp2intersect_d_128: {
2260 unsigned numElts = cast<cir::VectorType>(ops[0].getType()).getSize();
2261 mlir::Location loc = getLoc(expr->getExprLoc());
2262 StringRef intrinsicName;
2263
2264 switch (builtinID) {
2265 default:
2266 llvm_unreachable("Unexpected builtin");
2267 case X86::BI__builtin_ia32_vp2intersect_q_512:
2268 intrinsicName = "x86.avx512.vp2intersect.q.512";
2269 break;
2270 case X86::BI__builtin_ia32_vp2intersect_q_256:
2271 intrinsicName = "x86.avx512.vp2intersect.q.256";
2272 break;
2273 case X86::BI__builtin_ia32_vp2intersect_q_128:
2274 intrinsicName = "x86.avx512.vp2intersect.q.128";
2275 break;
2276 case X86::BI__builtin_ia32_vp2intersect_d_512:
2277 intrinsicName = "x86.avx512.vp2intersect.d.512";
2278 break;
2279 case X86::BI__builtin_ia32_vp2intersect_d_256:
2280 intrinsicName = "x86.avx512.vp2intersect.d.256";
2281 break;
2282 case X86::BI__builtin_ia32_vp2intersect_d_128:
2283 intrinsicName = "x86.avx512.vp2intersect.d.128";
2284 break;
2285 }
2286
2287 auto resVector = cir::VectorType::get(builder.getBoolTy(), numElts);
2288
2289 cir::RecordType resRecord =
2290 cir::RecordType::get(&getMLIRContext(), {resVector, resVector}, false,
2291 false, cir::RecordType::RecordKind::Struct);
2292
2293 mlir::Value call = builder.emitIntrinsicCallOp(
2294 getLoc(expr->getExprLoc()), intrinsicName, resRecord,
2295 mlir::ValueRange{ops[0], ops[1]});
2296 mlir::Value result =
2297 cir::ExtractMemberOp::create(builder, loc, resVector, call, 0);
2298 result = emitX86MaskedCompareResult(builder, result, numElts, nullptr, loc);
2299 Address addr = Address(
2300 ops[2], clang::CharUnits::fromQuantity(std::max(1U, numElts / 8)));
2301 builder.createStore(loc, result, addr);
2302
2303 result = cir::ExtractMemberOp::create(builder, loc, resVector, call, 1);
2304 result = emitX86MaskedCompareResult(builder, result, numElts, nullptr, loc);
2305 addr = Address(ops[3],
2306 clang::CharUnits::fromQuantity(std::max(1U, numElts / 8)));
2307 builder.createStore(loc, result, addr);
2308 return mlir::Value{};
2309 }
2310 case X86::BI__builtin_ia32_vpmultishiftqb128:
2311 case X86::BI__builtin_ia32_vpmultishiftqb256:
2312 case X86::BI__builtin_ia32_vpmultishiftqb512:
2313 case X86::BI__builtin_ia32_vpshufbitqmb128_mask:
2314 case X86::BI__builtin_ia32_vpshufbitqmb256_mask:
2315 case X86::BI__builtin_ia32_vpshufbitqmb512_mask:
2316 case X86::BI__builtin_ia32_cmpeqps:
2317 case X86::BI__builtin_ia32_cmpeqpd:
2318 return emitVectorFCmp(*this, *expr, ops, cir::CmpOpKind::eq,
2319 /*shouldInvert=*/false);
2320 case X86::BI__builtin_ia32_cmpltps:
2321 case X86::BI__builtin_ia32_cmpltpd:
2322 return emitVectorFCmp(*this, *expr, ops, cir::CmpOpKind::lt,
2323 /*shouldInvert=*/false);
2324 case X86::BI__builtin_ia32_cmpleps:
2325 case X86::BI__builtin_ia32_cmplepd:
2326 return emitVectorFCmp(*this, *expr, ops, cir::CmpOpKind::le,
2327 /*shouldInvert=*/false);
2328 case X86::BI__builtin_ia32_cmpunordps:
2329 case X86::BI__builtin_ia32_cmpunordpd:
2330 return emitVectorFCmp(*this, *expr, ops, cir::CmpOpKind::uno,
2331 /*shouldInvert=*/false);
2332 case X86::BI__builtin_ia32_cmpneqps:
2333 case X86::BI__builtin_ia32_cmpneqpd:
2334 return emitVectorFCmp(*this, *expr, ops, cir::CmpOpKind::ne,
2335 /*shouldInvert=*/false);
2336 case X86::BI__builtin_ia32_cmpnltps:
2337 case X86::BI__builtin_ia32_cmpnltpd:
2338 return emitVectorFCmp(*this, *expr, ops, cir::CmpOpKind::lt,
2339 /*shouldInvert=*/true);
2340 case X86::BI__builtin_ia32_cmpnleps:
2341 case X86::BI__builtin_ia32_cmpnlepd:
2342 return emitVectorFCmp(*this, *expr, ops, cir::CmpOpKind::le,
2343 /*shouldInvert=*/true);
2344 case X86::BI__builtin_ia32_cmpordps:
2345 case X86::BI__builtin_ia32_cmpordpd:
2346 return emitVectorFCmp(*this, *expr, ops, cir::CmpOpKind::uno,
2347 /*shouldInvert=*/true);
2348 case X86::BI__builtin_ia32_cmpph128_mask:
2349 case X86::BI__builtin_ia32_cmpph256_mask:
2350 case X86::BI__builtin_ia32_cmpph512_mask:
2351 case X86::BI__builtin_ia32_cmpps128_mask:
2352 case X86::BI__builtin_ia32_cmpps256_mask:
2353 case X86::BI__builtin_ia32_cmpps512_mask:
2354 case X86::BI__builtin_ia32_cmppd128_mask:
2355 case X86::BI__builtin_ia32_cmppd256_mask:
2356 case X86::BI__builtin_ia32_cmppd512_mask:
2357 case X86::BI__builtin_ia32_vcmpbf16512_mask:
2358 case X86::BI__builtin_ia32_vcmpbf16256_mask:
2359 case X86::BI__builtin_ia32_vcmpbf16128_mask:
2360 case X86::BI__builtin_ia32_cmpps:
2361 case X86::BI__builtin_ia32_cmpps256:
2362 case X86::BI__builtin_ia32_cmppd:
2363 case X86::BI__builtin_ia32_cmppd256:
2364 case X86::BI__builtin_ia32_cmpeqss:
2365 case X86::BI__builtin_ia32_cmpltss:
2366 case X86::BI__builtin_ia32_cmpless:
2367 case X86::BI__builtin_ia32_cmpunordss:
2368 case X86::BI__builtin_ia32_cmpneqss:
2369 case X86::BI__builtin_ia32_cmpnltss:
2370 case X86::BI__builtin_ia32_cmpnless:
2371 case X86::BI__builtin_ia32_cmpordss:
2372 case X86::BI__builtin_ia32_cmpeqsd:
2373 case X86::BI__builtin_ia32_cmpltsd:
2374 case X86::BI__builtin_ia32_cmplesd:
2375 case X86::BI__builtin_ia32_cmpunordsd:
2376 case X86::BI__builtin_ia32_cmpneqsd:
2377 case X86::BI__builtin_ia32_cmpnltsd:
2378 case X86::BI__builtin_ia32_cmpnlesd:
2379 case X86::BI__builtin_ia32_cmpordsd:
2380 cgm.errorNYI(expr->getSourceRange(),
2381 std::string("unimplemented X86 builtin call: ") +
2382 getContext().BuiltinInfo.getName(builtinID));
2383 return {};
2384 case X86::BI__builtin_ia32_vcvtph2ps_mask:
2385 case X86::BI__builtin_ia32_vcvtph2ps256_mask:
2386 case X86::BI__builtin_ia32_vcvtph2ps512_mask: {
2387 mlir::Location loc = getLoc(expr->getExprLoc());
2388 return emitX86CvtF16ToFloatExpr(builder, loc, ops,
2389 convertType(expr->getType()));
2390 }
2391 case X86::BI__builtin_ia32_cvtneps2bf16_128_mask: {
2392 mlir::Location loc = getLoc(expr->getExprLoc());
2393 cir::VectorType resTy = cast<cir::VectorType>(convertType(expr->getType()));
2394
2395 cir::VectorType inputTy = cast<cir::VectorType>(ops[0].getType());
2396 unsigned numElts = inputTy.getSize();
2397
2398 mlir::Value mask = getMaskVecValue(builder, loc, ops[2], numElts);
2399
2401 args.push_back(ops[0]);
2402 args.push_back(ops[1]);
2403 args.push_back(mask);
2404
2405 return builder.emitIntrinsicCallOp(
2406 loc, "x86.avx512bf16.mask.cvtneps2bf16.128", resTy, args);
2407 }
2408 case X86::BI__builtin_ia32_cvtneps2bf16_256_mask:
2409 case X86::BI__builtin_ia32_cvtneps2bf16_512_mask: {
2410 mlir::Location loc = getLoc(expr->getExprLoc());
2411 cir::VectorType resTy = cast<cir::VectorType>(convertType(expr->getType()));
2412 StringRef intrinsicName;
2413 if (builtinID == X86::BI__builtin_ia32_cvtneps2bf16_256_mask) {
2414 intrinsicName = "x86.avx512bf16.cvtneps2bf16.256";
2415 } else {
2416 assert(builtinID == X86::BI__builtin_ia32_cvtneps2bf16_512_mask);
2417 intrinsicName = "x86.avx512bf16.cvtneps2bf16.512";
2418 }
2419
2420 mlir::Value res = builder.emitIntrinsicCallOp(loc, intrinsicName, resTy,
2421 mlir::ValueRange{ops[0]});
2422
2423 return emitX86Select(builder, loc, ops[2], res, ops[1]);
2424 }
2425 case X86::BI__cpuid:
2426 case X86::BI__cpuidex: {
2427 mlir::Location loc = getLoc(expr->getExprLoc());
2428 mlir::Value subFuncId = builtinID == X86::BI__cpuidex
2429 ? ops[2]
2430 : builder.getConstInt(loc, sInt32Ty, 0);
2431 cir::CpuIdOp::create(builder, loc, /*cpuInfo=*/ops[0],
2432 /*functionId=*/ops[1], /*subFunctionId=*/subFuncId);
2433 return mlir::Value{};
2434 }
2435 case X86::BI__emul:
2436 case X86::BI__emulu:
2437 case X86::BI__mulh:
2438 case X86::BI__umulh:
2439 case X86::BI_mul128:
2440 case X86::BI_umul128: {
2441 cgm.errorNYI(expr->getSourceRange(),
2442 std::string("unimplemented X86 builtin call: ") +
2443 getContext().BuiltinInfo.getName(builtinID));
2444 return mlir::Value{};
2445 }
2446 case X86::BI__faststorefence: {
2447 cir::AtomicFenceOp::create(
2448 builder, getLoc(expr->getExprLoc()),
2449 cir::MemOrder::SequentiallyConsistent,
2450 cir::SyncScopeKindAttr::get(&getMLIRContext(),
2451 cir::SyncScopeKind::System));
2452 return mlir::Value{};
2453 }
2454 case X86::BI__shiftleft128:
2455 case X86::BI__shiftright128: {
2456 // Flip low/high ops and zero-extend amount to matching type.
2457 // shiftleft128(Low, High, Amt) -> fshl(High, Low, Amt)
2458 // shiftright128(Low, High, Amt) -> fshr(High, Low, Amt)
2459 std::swap(ops[0], ops[1]);
2460
2461 // Zero-extend shift amount to i64 if needed
2462 auto amtTy = mlir::cast<cir::IntType>(ops[2].getType());
2463 cir::IntType i64Ty = builder.getUInt64Ty();
2464
2465 if (amtTy != i64Ty)
2466 ops[2] = builder.createIntCast(ops[2], i64Ty);
2467
2468 const StringRef intrinsicName =
2469 (builtinID == X86::BI__shiftleft128) ? "fshl" : "fshr";
2470 return builder.emitIntrinsicCallOp(
2471 getLoc(expr->getExprLoc()), intrinsicName, i64Ty,
2472 mlir::ValueRange{ops[0], ops[1], ops[2]});
2473 }
2474 case X86::BI_ReadWriteBarrier:
2475 case X86::BI_ReadBarrier:
2476 case X86::BI_WriteBarrier: {
2477 cir::AtomicFenceOp::create(
2478 builder, getLoc(expr->getExprLoc()),
2479 cir::MemOrder::SequentiallyConsistent,
2480 cir::SyncScopeKindAttr::get(&getMLIRContext(),
2481 cir::SyncScopeKind::SingleThread));
2482 return mlir::Value{};
2483 }
2484 case X86::BI_AddressOfReturnAddress: {
2485 mlir::Location loc = getLoc(expr->getExprLoc());
2486 mlir::Value addr =
2487 cir::AddrOfReturnAddrOp::create(builder, loc, allocaInt8PtrTy);
2488 return builder.createCast(loc, cir::CastKind::bitcast, addr, voidPtrTy);
2489 }
2490 case X86::BI__stosb:
2491 case X86::BI__ud2:
2492 case X86::BI__int2c:
2493 case X86::BI__readfsbyte:
2494 case X86::BI__readfsword:
2495 case X86::BI__readfsdword:
2496 case X86::BI__readfsqword:
2497 case X86::BI__readgsbyte:
2498 case X86::BI__readgsword:
2499 case X86::BI__readgsdword:
2500 case X86::BI__readgsqword: {
2501 cgm.errorNYI(expr->getSourceRange(),
2502 std::string("unimplemented X86 builtin call: ") +
2503 getContext().BuiltinInfo.getName(builtinID));
2504 return mlir::Value{};
2505 }
2506 case X86::BI__builtin_ia32_encodekey128_u32: {
2507 return emitEncodeKey(&getMLIRContext(), builder, getLoc(expr->getExprLoc()),
2508 {ops[0], ops[1]}, ops[2], 6, "x86.encodekey128", 3);
2509 }
2510 case X86::BI__builtin_ia32_encodekey256_u32: {
2511
2512 return emitEncodeKey(&getMLIRContext(), builder, getLoc(expr->getExprLoc()),
2513 {ops[0], ops[1], ops[2]}, ops[3], 7,
2514 "x86.encodekey256", 4);
2515 }
2516
2517 case X86::BI__builtin_ia32_aesenc128kl_u8:
2518 case X86::BI__builtin_ia32_aesdec128kl_u8:
2519 case X86::BI__builtin_ia32_aesenc256kl_u8:
2520 case X86::BI__builtin_ia32_aesdec256kl_u8: {
2521 llvm::StringRef intrinsicName;
2522 switch (builtinID) {
2523 default:
2524 llvm_unreachable("Unexpected builtin");
2525 case X86::BI__builtin_ia32_aesenc128kl_u8:
2526 intrinsicName = "x86.aesenc128kl";
2527 break;
2528 case X86::BI__builtin_ia32_aesdec128kl_u8:
2529 intrinsicName = "x86.aesdec128kl";
2530 break;
2531 case X86::BI__builtin_ia32_aesenc256kl_u8:
2532 intrinsicName = "x86.aesenc256kl";
2533 break;
2534 case X86::BI__builtin_ia32_aesdec256kl_u8:
2535 intrinsicName = "x86.aesdec256kl";
2536 break;
2537 }
2538
2539 return emitX86Aes(builder, getLoc(expr->getExprLoc()), intrinsicName,
2540 convertType(expr->getType()), ops);
2541 }
2542 case X86::BI__builtin_ia32_aesencwide128kl_u8:
2543 case X86::BI__builtin_ia32_aesdecwide128kl_u8:
2544 case X86::BI__builtin_ia32_aesencwide256kl_u8:
2545 case X86::BI__builtin_ia32_aesdecwide256kl_u8: {
2546 llvm::StringRef intrinsicName;
2547 switch (builtinID) {
2548 default:
2549 llvm_unreachable("Unexpected builtin");
2550 case X86::BI__builtin_ia32_aesencwide128kl_u8:
2551 intrinsicName = "x86.aesencwide128kl";
2552 break;
2553 case X86::BI__builtin_ia32_aesdecwide128kl_u8:
2554 intrinsicName = "x86.aesdecwide128kl";
2555 break;
2556 case X86::BI__builtin_ia32_aesencwide256kl_u8:
2557 intrinsicName = "x86.aesencwide256kl";
2558 break;
2559 case X86::BI__builtin_ia32_aesdecwide256kl_u8:
2560 intrinsicName = "x86.aesdecwide256kl";
2561 break;
2562 }
2563
2564 return emitX86Aeswide(builder, getLoc(expr->getExprLoc()), intrinsicName,
2565 convertType(expr->getType()), ops);
2566 }
2567 case X86::BI__builtin_ia32_vfcmaddcph512_mask:
2568 case X86::BI__builtin_ia32_vfmaddcph512_mask:
2569 case X86::BI__builtin_ia32_vfcmaddcsh_round_mask:
2570 case X86::BI__builtin_ia32_vfmaddcsh_round_mask:
2571 case X86::BI__builtin_ia32_vfcmaddcsh_round_mask3:
2572 case X86::BI__builtin_ia32_vfmaddcsh_round_mask3:
2573 case X86::BI__builtin_ia32_prefetchi:
2574 cgm.errorNYI(expr->getSourceRange(),
2575 std::string("unimplemented X86 builtin call: ") +
2576 getContext().BuiltinInfo.getName(builtinID));
2577 return mlir::Value{};
2578 }
2579}
Defines enum values for all the target-independent builtin functions.
static mlir::Value emitX86MaskLogic(CIRGenBuilderTy &builder, mlir::Location loc, SmallVectorImpl< mlir::Value > &ops, bool invertLHS=false)
static mlir::Value emitX86vpcom(CIRGenBuilderTy &builder, mlir::Location loc, llvm::SmallVector< mlir::Value > ops, bool isSigned)
static std::optional< mlir::Value > emitX86ConvertToMask(CIRGenFunction &cgf, CIRGenBuilderTy &builder, mlir::Value in, mlir::Location loc)
static mlir::Value emitX86CompressExpand(CIRGenBuilderTy &builder, mlir::Location loc, mlir::Value source, mlir::Value mask, mlir::Value inputVector, const std::string &id)
static void computeFullLaneShuffleMask(CIRGenFunction &cgf, const mlir::Value vec, uint32_t imm, const bool isShufP, llvm::SmallVectorImpl< int64_t > &outIndices)
static std::optional< mlir::Value > emitX86SExtMask(CIRGenBuilderTy &builder, mlir::Value op, mlir::Type dstTy, mlir::Location loc)
static std::optional< mlir::Value > emitX86MaskedCompare(CIRGenBuilderTy &builder, unsigned cc, bool isSigned, ArrayRef< mlir::Value > ops, mlir::Location loc)
static mlir::Value emitPrefetch(CIRGenFunction &cgf, unsigned builtinID, const CallExpr *e, const SmallVector< mlir::Value > &ops)
static mlir::Value getMaskZeroBitAsBool(CIRGenBuilderTy &builder, mlir::Location loc, mlir::Value mask)
static mlir::Value emitX86Aeswide(CIRGenBuilderTy &builder, mlir::Location loc, llvm::StringRef intrinsicName, mlir::Type retType, llvm::ArrayRef< mlir::Value > ops)
static mlir::Value emitX86MaskTest(CIRGenBuilderTy &builder, mlir::Location loc, const std::string &intrinsicName, SmallVectorImpl< mlir::Value > &ops)
static mlir::Value emitEncodeKey(mlir::MLIRContext *context, CIRGenBuilderTy &builder, const mlir::Location &location, mlir::ValueRange inputOperands, mlir::Value outputOperand, std::uint8_t vecOutputCount, const std::string &intrinsicName, std::uint8_t numResults)
static mlir::Value emitVecInsert(CIRGenBuilderTy &builder, mlir::Location loc, mlir::Value vec, mlir::Value value, mlir::Value indexOp)
static mlir::Value emitX86Fpclass(CIRGenBuilderTy &builder, mlir::Location loc, unsigned builtinID, SmallVectorImpl< mlir::Value > &ops)
static mlir::Value emitX86MaskedLoad(CIRGenBuilderTy &builder, ArrayRef< mlir::Value > ops, llvm::Align alignment, mlir::Location loc)
static mlir::Value emitX86MaskUnpack(CIRGenBuilderTy &builder, mlir::Location loc, const std::string &intrinsicName, SmallVectorImpl< mlir::Value > &ops)
static mlir::Value emitVectorFCmp(CIRGenFunction &cgf, const CallExpr &expr, llvm::SmallVector< mlir::Value > &ops, cir::CmpOpKind pred, bool shouldInvert)
static cir::VecShuffleOp emitPshufWord(CIRGenBuilderTy &builder, const mlir::Value vec, const mlir::Value immediate, const mlir::Location loc, const bool isLow)
static mlir::Value emitX86MaskedCompareResult(CIRGenBuilderTy &builder, mlir::Value cmp, unsigned numElts, mlir::Value maskIn, mlir::Location loc)
static mlir::Value emitX86Select(CIRGenBuilderTy &builder, mlir::Location loc, mlir::Value mask, mlir::Value op0, mlir::Value op1)
static mlir::Value emitX86Aes(CIRGenBuilderTy &builder, mlir::Location loc, llvm::StringRef intrinsicName, mlir::Type retType, llvm::ArrayRef< mlir::Value > ops)
static mlir::Value emitX86CvtF16ToFloatExpr(CIRGenBuilderTy &builder, mlir::Location loc, llvm::ArrayRef< mlir::Value > ops, mlir::Type dstTy)
static mlir::Value emitX86FunnelShift(CIRGenBuilderTy &builder, mlir::Location location, mlir::Value &op0, mlir::Value &op1, mlir::Value &amt, bool isRight)
static mlir::Value emitX86Muldq(CIRGenBuilderTy &builder, mlir::Location loc, bool isSigned, SmallVectorImpl< mlir::Value > &ops, unsigned opTypePrimitiveSizeInBits)
static mlir::Value getMaskVecValue(CIRGenBuilderTy &builder, mlir::Location loc, mlir::Value mask, unsigned numElems)
static mlir::Value emitX86MaskAddLogic(CIRGenBuilderTy &builder, mlir::Location loc, const std::string &intrinsicName, SmallVectorImpl< mlir::Value > &ops)
static mlir::Value emitX86CompressStore(CIRGenBuilderTy &builder, mlir::Location loc, ArrayRef< mlir::Value > ops)
static mlir::Value emitX86ScalarSelect(CIRGenBuilderTy &builder, mlir::Location loc, mlir::Value mask, mlir::Value op0, mlir::Value op1)
TokenType getType() const
Returns the token's type, e.g.
Enumerates target-specific builtins in their own namespaces within namespace clang.
__device__ __2f16 b
__device__ __2f16 float c
mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ, const llvm::APInt &val)
mlir::Value createShift(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, bool isShiftLeft)
cir::ConstantOp getNullValue(mlir::Type ty, mlir::Location loc)
cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr)
mlir::Value createCast(mlir::Location loc, cir::CastKind kind, mlir::Value src, mlir::Type newTy)
cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base, mlir::Value stride)
mlir::Value createPtrBitcast(mlir::Value src, mlir::Type newPointeeTy)
mlir::Value createAnd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createExtractElement(mlir::Location loc, mlir::Value vec, uint64_t idx)
cir::VecCmpOp createVecCompare(mlir::Location loc, cir::CmpOpKind kind, mlir::Value lhs, mlir::Value rhs)
mlir::Value createIntCast(mlir::Value src, mlir::Type newTy)
mlir::Value createBitcast(mlir::Value src, mlir::Type newTy)
mlir::Value createNot(mlir::Location loc, mlir::Value value)
mlir::Value createSelect(mlir::Location loc, mlir::Value condition, mlir::Value trueValue, mlir::Value falseValue)
mlir::Value createMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowBehavior ob=OverflowBehavior::None)
cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value={})
Create a yield operation.
cir::BoolType getBoolTy()
llvm::TypeSize getTypeSizeInBits(mlir::Type ty) const
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error, unsigned *IntegerConstantArgs=nullptr) const
Return the type for the specified builtin.
@ GE_None
No error.
mlir::Value getPointer() const
Definition Address.h:98
cir::ConstantOp getUInt64(uint64_t c, mlir::Location loc)
mlir::Value emitIntrinsicCallOp(mlir::Location loc, const llvm::StringRef str, const mlir::Type &resTy, Operands &&...op)
cir::IntType getSIntNTy(int n)
cir::ConstantOp getUInt32(uint32_t c, mlir::Location loc)
cir::VecShuffleOp createVecShuffle(mlir::Location loc, mlir::Value vec1, mlir::Value vec2, llvm::ArrayRef< mlir::Attribute > maskAttrs)
cir::RecordType getAnonRecordTy(llvm::ArrayRef< mlir::Type > members, bool packed=false, bool padded=false)
Get a CIR anonymous record type.
mlir::Value createMaskedLoad(mlir::Location loc, mlir::Type ty, mlir::Value ptr, llvm::Align alignment, mlir::Value mask, mlir::Value passThru)
cir::LoadOp createAlignedLoad(mlir::Location loc, mlir::Type ty, mlir::Value ptr, llvm::MaybeAlign align)
cir::StoreOp createStore(mlir::Location loc, mlir::Value val, Address dst, bool isVolatile=false, mlir::IntegerAttr align={}, cir::SyncScopeKindAttr scope={}, cir::MemOrderAttr order={})
cir::ConstantOp getSInt32(int32_t c, mlir::Location loc)
cir::IntType getUIntNTy(int n)
mlir::Value getArrayElement(mlir::Location arrayLocBegin, mlir::Location arrayLocEnd, mlir::Value arrayPtr, mlir::Type eltTy, mlir::Value idx, bool shouldDecay)
Create a cir.ptr_stride operation to get access to an array element.
mlir::Type convertType(clang::QualType t)
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
static int64_t getZExtIntValueFromConstOp(mlir::Value val)
Get zero-extended integer from a mlir::Value that is an int constant or a constant op.
static int64_t getSExtIntValueFromConstOp(mlir::Value val)
Get integer from a mlir::Value that is an int constant or a constant op.
std::optional< mlir::Value > emitX86BuiltinExpr(unsigned builtinID, const CallExpr *expr)
CIRGenBuilderTy & getBuilder()
mlir::MLIRContext & getMLIRContext()
clang::ASTContext & getContext() const
Address createMemTemp(QualType t, mlir::Location loc, const Twine &name="tmp", Address *alloca=nullptr, mlir::OpBuilder::InsertPoint ip={})
Create a temporary memory object of the given type, with appropriate alignmen and cast it to the defa...
mlir::Value emitScalarOrConstFoldImmArg(unsigned iceArguments, unsigned idx, const Expr *argExpr)
const cir::CIRDataLayout getDataLayout() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2946
static CharUnits One()
One - Construct a CharUnits quantity of one.
Definition CharUnits.h:58
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition CharUnits.h:63
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:282
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
The JSON file list parser is used to communicate input to InstallAPI.
U cast(CodeGen::Address addr)
Definition Address.h:327
static bool msvcBuiltins()
static bool handleBuiltinICEArguments()
static bool emitConstrainedFPCall()
static bool fastMathFlags()
cir::PointerType allocaInt8PtrTy
void* in alloca address space
cir::PointerType voidPtrTy
void* in address space 0