30#include "llvm/IR/IntrinsicsAArch64.h"
31#include "llvm/IR/IntrinsicsARM.h"
32#include "llvm/IR/IntrinsicsNVPTX.h"
33#include "llvm/IR/IntrinsicsRISCV.h"
34#include "llvm/IR/IntrinsicsWebAssembly.h"
35#include "llvm/IR/IntrinsicsX86.h"
50 cl::desc(
"Disable autoupgrade of debug info"));
60 Type *Arg0Type =
F->getFunctionType()->getParamType(0);
75 Type *LastArgType =
F->getFunctionType()->getParamType(
76 F->getFunctionType()->getNumParams() - 1);
91 if (
F->getReturnType()->isVectorTy())
101 if (
F->getReturnType()->getScalarType()->isBFloatTy())
111 if (
F->getFunctionType()->getParamType(1)->getScalarType()->isBFloatTy())
125 if (
Name.consume_front(
"avx."))
126 return (
Name.starts_with(
"blend.p") ||
127 Name ==
"cvt.ps2.pd.256" ||
128 Name ==
"cvtdq2.pd.256" ||
129 Name ==
"cvtdq2.ps.256" ||
130 Name.starts_with(
"movnt.") ||
131 Name.starts_with(
"sqrt.p") ||
132 Name.starts_with(
"storeu.") ||
133 Name.starts_with(
"vbroadcast.s") ||
134 Name.starts_with(
"vbroadcastf128") ||
135 Name.starts_with(
"vextractf128.") ||
136 Name.starts_with(
"vinsertf128.") ||
137 Name.starts_with(
"vperm2f128.") ||
138 Name.starts_with(
"vpermil."));
140 if (
Name.consume_front(
"avx2."))
141 return (
Name ==
"movntdqa" ||
142 Name.starts_with(
"pabs.") ||
143 Name.starts_with(
"padds.") ||
144 Name.starts_with(
"paddus.") ||
145 Name.starts_with(
"pblendd.") ||
147 Name.starts_with(
"pbroadcast") ||
148 Name.starts_with(
"pcmpeq.") ||
149 Name.starts_with(
"pcmpgt.") ||
150 Name.starts_with(
"pmax") ||
151 Name.starts_with(
"pmin") ||
152 Name.starts_with(
"pmovsx") ||
153 Name.starts_with(
"pmovzx") ||
155 Name ==
"pmulu.dq" ||
156 Name.starts_with(
"psll.dq") ||
157 Name.starts_with(
"psrl.dq") ||
158 Name.starts_with(
"psubs.") ||
159 Name.starts_with(
"psubus.") ||
160 Name.starts_with(
"vbroadcast") ||
161 Name ==
"vbroadcasti128" ||
162 Name ==
"vextracti128" ||
163 Name ==
"vinserti128" ||
164 Name ==
"vperm2i128");
166 if (
Name.consume_front(
"avx512.")) {
167 if (
Name.consume_front(
"mask."))
169 return (
Name.starts_with(
"add.p") ||
170 Name.starts_with(
"and.") ||
171 Name.starts_with(
"andn.") ||
172 Name.starts_with(
"broadcast.s") ||
173 Name.starts_with(
"broadcastf32x4.") ||
174 Name.starts_with(
"broadcastf32x8.") ||
175 Name.starts_with(
"broadcastf64x2.") ||
176 Name.starts_with(
"broadcastf64x4.") ||
177 Name.starts_with(
"broadcasti32x4.") ||
178 Name.starts_with(
"broadcasti32x8.") ||
179 Name.starts_with(
"broadcasti64x2.") ||
180 Name.starts_with(
"broadcasti64x4.") ||
181 Name.starts_with(
"cmp.b") ||
182 Name.starts_with(
"cmp.d") ||
183 Name.starts_with(
"cmp.q") ||
184 Name.starts_with(
"cmp.w") ||
185 Name.starts_with(
"compress.b") ||
186 Name.starts_with(
"compress.d") ||
187 Name.starts_with(
"compress.p") ||
188 Name.starts_with(
"compress.q") ||
189 Name.starts_with(
"compress.store.") ||
190 Name.starts_with(
"compress.w") ||
191 Name.starts_with(
"conflict.") ||
192 Name.starts_with(
"cvtdq2pd.") ||
193 Name.starts_with(
"cvtdq2ps.") ||
194 Name ==
"cvtpd2dq.256" ||
195 Name ==
"cvtpd2ps.256" ||
196 Name ==
"cvtps2pd.128" ||
197 Name ==
"cvtps2pd.256" ||
198 Name.starts_with(
"cvtqq2pd.") ||
199 Name ==
"cvtqq2ps.256" ||
200 Name ==
"cvtqq2ps.512" ||
201 Name ==
"cvttpd2dq.256" ||
202 Name ==
"cvttps2dq.128" ||
203 Name ==
"cvttps2dq.256" ||
204 Name.starts_with(
"cvtudq2pd.") ||
205 Name.starts_with(
"cvtudq2ps.") ||
206 Name.starts_with(
"cvtuqq2pd.") ||
207 Name ==
"cvtuqq2ps.256" ||
208 Name ==
"cvtuqq2ps.512" ||
209 Name.starts_with(
"dbpsadbw.") ||
210 Name.starts_with(
"div.p") ||
211 Name.starts_with(
"expand.b") ||
212 Name.starts_with(
"expand.d") ||
213 Name.starts_with(
"expand.load.") ||
214 Name.starts_with(
"expand.p") ||
215 Name.starts_with(
"expand.q") ||
216 Name.starts_with(
"expand.w") ||
217 Name.starts_with(
"fpclass.p") ||
218 Name.starts_with(
"insert") ||
219 Name.starts_with(
"load.") ||
220 Name.starts_with(
"loadu.") ||
221 Name.starts_with(
"lzcnt.") ||
222 Name.starts_with(
"max.p") ||
223 Name.starts_with(
"min.p") ||
224 Name.starts_with(
"movddup") ||
225 Name.starts_with(
"move.s") ||
226 Name.starts_with(
"movshdup") ||
227 Name.starts_with(
"movsldup") ||
228 Name.starts_with(
"mul.p") ||
229 Name.starts_with(
"or.") ||
230 Name.starts_with(
"pabs.") ||
231 Name.starts_with(
"packssdw.") ||
232 Name.starts_with(
"packsswb.") ||
233 Name.starts_with(
"packusdw.") ||
234 Name.starts_with(
"packuswb.") ||
235 Name.starts_with(
"padd.") ||
236 Name.starts_with(
"padds.") ||
237 Name.starts_with(
"paddus.") ||
238 Name.starts_with(
"palignr.") ||
239 Name.starts_with(
"pand.") ||
240 Name.starts_with(
"pandn.") ||
241 Name.starts_with(
"pavg") ||
242 Name.starts_with(
"pbroadcast") ||
243 Name.starts_with(
"pcmpeq.") ||
244 Name.starts_with(
"pcmpgt.") ||
245 Name.starts_with(
"perm.df.") ||
246 Name.starts_with(
"perm.di.") ||
247 Name.starts_with(
"permvar.") ||
248 Name.starts_with(
"pmaddubs.w.") ||
249 Name.starts_with(
"pmaddw.d.") ||
250 Name.starts_with(
"pmax") ||
251 Name.starts_with(
"pmin") ||
252 Name ==
"pmov.qd.256" ||
253 Name ==
"pmov.qd.512" ||
254 Name ==
"pmov.wb.256" ||
255 Name ==
"pmov.wb.512" ||
256 Name.starts_with(
"pmovsx") ||
257 Name.starts_with(
"pmovzx") ||
258 Name.starts_with(
"pmul.dq.") ||
259 Name.starts_with(
"pmul.hr.sw.") ||
260 Name.starts_with(
"pmulh.w.") ||
261 Name.starts_with(
"pmulhu.w.") ||
262 Name.starts_with(
"pmull.") ||
263 Name.starts_with(
"pmultishift.qb.") ||
264 Name.starts_with(
"pmulu.dq.") ||
265 Name.starts_with(
"por.") ||
266 Name.starts_with(
"prol.") ||
267 Name.starts_with(
"prolv.") ||
268 Name.starts_with(
"pror.") ||
269 Name.starts_with(
"prorv.") ||
270 Name.starts_with(
"pshuf.b.") ||
271 Name.starts_with(
"pshuf.d.") ||
272 Name.starts_with(
"pshufh.w.") ||
273 Name.starts_with(
"pshufl.w.") ||
274 Name.starts_with(
"psll.d") ||
275 Name.starts_with(
"psll.q") ||
276 Name.starts_with(
"psll.w") ||
277 Name.starts_with(
"pslli") ||
278 Name.starts_with(
"psllv") ||
279 Name.starts_with(
"psra.d") ||
280 Name.starts_with(
"psra.q") ||
281 Name.starts_with(
"psra.w") ||
282 Name.starts_with(
"psrai") ||
283 Name.starts_with(
"psrav") ||
284 Name.starts_with(
"psrl.d") ||
285 Name.starts_with(
"psrl.q") ||
286 Name.starts_with(
"psrl.w") ||
287 Name.starts_with(
"psrli") ||
288 Name.starts_with(
"psrlv") ||
289 Name.starts_with(
"psub.") ||
290 Name.starts_with(
"psubs.") ||
291 Name.starts_with(
"psubus.") ||
292 Name.starts_with(
"pternlog.") ||
293 Name.starts_with(
"punpckh") ||
294 Name.starts_with(
"punpckl") ||
295 Name.starts_with(
"pxor.") ||
296 Name.starts_with(
"shuf.f") ||
297 Name.starts_with(
"shuf.i") ||
298 Name.starts_with(
"shuf.p") ||
299 Name.starts_with(
"sqrt.p") ||
300 Name.starts_with(
"store.b.") ||
301 Name.starts_with(
"store.d.") ||
302 Name.starts_with(
"store.p") ||
303 Name.starts_with(
"store.q.") ||
304 Name.starts_with(
"store.w.") ||
305 Name ==
"store.ss" ||
306 Name.starts_with(
"storeu.") ||
307 Name.starts_with(
"sub.p") ||
308 Name.starts_with(
"ucmp.") ||
309 Name.starts_with(
"unpckh.") ||
310 Name.starts_with(
"unpckl.") ||
311 Name.starts_with(
"valign.") ||
312 Name ==
"vcvtph2ps.128" ||
313 Name ==
"vcvtph2ps.256" ||
314 Name.starts_with(
"vextract") ||
315 Name.starts_with(
"vfmadd.") ||
316 Name.starts_with(
"vfmaddsub.") ||
317 Name.starts_with(
"vfnmadd.") ||
318 Name.starts_with(
"vfnmsub.") ||
319 Name.starts_with(
"vpdpbusd.") ||
320 Name.starts_with(
"vpdpbusds.") ||
321 Name.starts_with(
"vpdpwssd.") ||
322 Name.starts_with(
"vpdpwssds.") ||
323 Name.starts_with(
"vpermi2var.") ||
324 Name.starts_with(
"vpermil.p") ||
325 Name.starts_with(
"vpermilvar.") ||
326 Name.starts_with(
"vpermt2var.") ||
327 Name.starts_with(
"vpmadd52") ||
328 Name.starts_with(
"vpshld.") ||
329 Name.starts_with(
"vpshldv.") ||
330 Name.starts_with(
"vpshrd.") ||
331 Name.starts_with(
"vpshrdv.") ||
332 Name.starts_with(
"vpshufbitqmb.") ||
333 Name.starts_with(
"xor."));
335 if (
Name.consume_front(
"mask3."))
337 return (
Name.starts_with(
"vfmadd.") ||
338 Name.starts_with(
"vfmaddsub.") ||
339 Name.starts_with(
"vfmsub.") ||
340 Name.starts_with(
"vfmsubadd.") ||
341 Name.starts_with(
"vfnmsub."));
343 if (
Name.consume_front(
"maskz."))
345 return (
Name.starts_with(
"pternlog.") ||
346 Name.starts_with(
"vfmadd.") ||
347 Name.starts_with(
"vfmaddsub.") ||
348 Name.starts_with(
"vpdpbusd.") ||
349 Name.starts_with(
"vpdpbusds.") ||
350 Name.starts_with(
"vpdpwssd.") ||
351 Name.starts_with(
"vpdpwssds.") ||
352 Name.starts_with(
"vpermt2var.") ||
353 Name.starts_with(
"vpmadd52") ||
354 Name.starts_with(
"vpshldv.") ||
355 Name.starts_with(
"vpshrdv."));
358 return (
Name ==
"movntdqa" ||
359 Name ==
"pmul.dq.512" ||
360 Name ==
"pmulu.dq.512" ||
361 Name.starts_with(
"broadcastm") ||
362 Name.starts_with(
"cmp.p") ||
363 Name.starts_with(
"cvtb2mask.") ||
364 Name.starts_with(
"cvtd2mask.") ||
365 Name.starts_with(
"cvtmask2") ||
366 Name.starts_with(
"cvtq2mask.") ||
367 Name ==
"cvtusi2sd" ||
368 Name.starts_with(
"cvtw2mask.") ||
373 Name ==
"kortestc.w" ||
374 Name ==
"kortestz.w" ||
375 Name.starts_with(
"kunpck") ||
378 Name.starts_with(
"padds.") ||
379 Name.starts_with(
"pbroadcast") ||
380 Name.starts_with(
"prol") ||
381 Name.starts_with(
"pror") ||
382 Name.starts_with(
"psll.dq") ||
383 Name.starts_with(
"psrl.dq") ||
384 Name.starts_with(
"psubs.") ||
385 Name.starts_with(
"ptestm") ||
386 Name.starts_with(
"ptestnm") ||
387 Name.starts_with(
"storent.") ||
388 Name.starts_with(
"vbroadcast.s") ||
389 Name.starts_with(
"vpshld.") ||
390 Name.starts_with(
"vpshrd."));
393 if (
Name.consume_front(
"fma."))
394 return (
Name.starts_with(
"vfmadd.") ||
395 Name.starts_with(
"vfmsub.") ||
396 Name.starts_with(
"vfmsubadd.") ||
397 Name.starts_with(
"vfnmadd.") ||
398 Name.starts_with(
"vfnmsub."));
400 if (
Name.consume_front(
"fma4."))
401 return Name.starts_with(
"vfmadd.s");
403 if (
Name.consume_front(
"sse."))
404 return (
Name ==
"add.ss" ||
405 Name ==
"cvtsi2ss" ||
406 Name ==
"cvtsi642ss" ||
409 Name.starts_with(
"sqrt.p") ||
411 Name.starts_with(
"storeu.") ||
414 if (
Name.consume_front(
"sse2."))
415 return (
Name ==
"add.sd" ||
416 Name ==
"cvtdq2pd" ||
417 Name ==
"cvtdq2ps" ||
418 Name ==
"cvtps2pd" ||
419 Name ==
"cvtsi2sd" ||
420 Name ==
"cvtsi642sd" ||
421 Name ==
"cvtss2sd" ||
424 Name.starts_with(
"padds.") ||
425 Name.starts_with(
"paddus.") ||
426 Name.starts_with(
"pcmpeq.") ||
427 Name.starts_with(
"pcmpgt.") ||
432 Name ==
"pmulu.dq" ||
433 Name.starts_with(
"pshuf") ||
434 Name.starts_with(
"psll.dq") ||
435 Name.starts_with(
"psrl.dq") ||
436 Name.starts_with(
"psubs.") ||
437 Name.starts_with(
"psubus.") ||
438 Name.starts_with(
"sqrt.p") ||
440 Name ==
"storel.dq" ||
441 Name.starts_with(
"storeu.") ||
444 if (
Name.consume_front(
"sse41."))
445 return (
Name.starts_with(
"blendp") ||
446 Name ==
"movntdqa" ||
456 Name.starts_with(
"pmovsx") ||
457 Name.starts_with(
"pmovzx") ||
460 if (
Name.consume_front(
"sse42."))
461 return Name ==
"crc32.64.8";
463 if (
Name.consume_front(
"sse4a."))
464 return Name.starts_with(
"movnt.");
466 if (
Name.consume_front(
"ssse3."))
467 return (
Name ==
"pabs.b.128" ||
468 Name ==
"pabs.d.128" ||
469 Name ==
"pabs.w.128");
471 if (
Name.consume_front(
"xop."))
472 return (
Name ==
"vpcmov" ||
473 Name ==
"vpcmov.256" ||
474 Name.starts_with(
"vpcom") ||
475 Name.starts_with(
"vprot"));
477 return (
Name ==
"addcarry.u32" ||
478 Name ==
"addcarry.u64" ||
479 Name ==
"addcarryx.u32" ||
480 Name ==
"addcarryx.u64" ||
481 Name ==
"subborrow.u32" ||
482 Name ==
"subborrow.u64" ||
483 Name.starts_with(
"vcvtph2ps."));
489 if (!
Name.consume_front(
"x86."))
497 if (
Name ==
"rdtscp") {
499 if (
F->getFunctionType()->getNumParams() == 0)
504 Intrinsic::x86_rdtscp);
511 if (
Name.consume_front(
"sse41.ptest")) {
513 .
Case(
"c", Intrinsic::x86_sse41_ptestc)
514 .
Case(
"z", Intrinsic::x86_sse41_ptestz)
515 .
Case(
"nzc", Intrinsic::x86_sse41_ptestnzc)
528 .
Case(
"sse41.insertps", Intrinsic::x86_sse41_insertps)
529 .
Case(
"sse41.dppd", Intrinsic::x86_sse41_dppd)
530 .
Case(
"sse41.dpps", Intrinsic::x86_sse41_dpps)
531 .
Case(
"sse41.mpsadbw", Intrinsic::x86_sse41_mpsadbw)
532 .
Case(
"avx.dp.ps.256", Intrinsic::x86_avx_dp_ps_256)
533 .
Case(
"avx2.mpsadbw", Intrinsic::x86_avx2_mpsadbw)
538 if (
Name.consume_front(
"avx512.mask.cmp.")) {
541 .
Case(
"pd.128", Intrinsic::x86_avx512_mask_cmp_pd_128)
542 .
Case(
"pd.256", Intrinsic::x86_avx512_mask_cmp_pd_256)
543 .
Case(
"pd.512", Intrinsic::x86_avx512_mask_cmp_pd_512)
544 .
Case(
"ps.128", Intrinsic::x86_avx512_mask_cmp_ps_128)
545 .
Case(
"ps.256", Intrinsic::x86_avx512_mask_cmp_ps_256)
546 .
Case(
"ps.512", Intrinsic::x86_avx512_mask_cmp_ps_512)
553 if (
Name.consume_front(
"avx512bf16.")) {
556 .
Case(
"cvtne2ps2bf16.128",
557 Intrinsic::x86_avx512bf16_cvtne2ps2bf16_128)
558 .
Case(
"cvtne2ps2bf16.256",
559 Intrinsic::x86_avx512bf16_cvtne2ps2bf16_256)
560 .
Case(
"cvtne2ps2bf16.512",
561 Intrinsic::x86_avx512bf16_cvtne2ps2bf16_512)
562 .
Case(
"mask.cvtneps2bf16.128",
563 Intrinsic::x86_avx512bf16_mask_cvtneps2bf16_128)
564 .
Case(
"cvtneps2bf16.256",
565 Intrinsic::x86_avx512bf16_cvtneps2bf16_256)
566 .
Case(
"cvtneps2bf16.512",
567 Intrinsic::x86_avx512bf16_cvtneps2bf16_512)
574 .
Case(
"dpbf16ps.128", Intrinsic::x86_avx512bf16_dpbf16ps_128)
575 .
Case(
"dpbf16ps.256", Intrinsic::x86_avx512bf16_dpbf16ps_256)
576 .
Case(
"dpbf16ps.512", Intrinsic::x86_avx512bf16_dpbf16ps_512)
583 if (
Name.consume_front(
"xop.")) {
585 if (
Name.starts_with(
"vpermil2")) {
588 auto Idx =
F->getFunctionType()->getParamType(2);
589 if (
Idx->isFPOrFPVectorTy()) {
590 unsigned IdxSize =
Idx->getPrimitiveSizeInBits();
591 unsigned EltSize =
Idx->getScalarSizeInBits();
592 if (EltSize == 64 && IdxSize == 128)
593 ID = Intrinsic::x86_xop_vpermil2pd;
594 else if (EltSize == 32 && IdxSize == 128)
595 ID = Intrinsic::x86_xop_vpermil2ps;
596 else if (EltSize == 64 && IdxSize == 256)
597 ID = Intrinsic::x86_xop_vpermil2pd_256;
599 ID = Intrinsic::x86_xop_vpermil2ps_256;
601 }
else if (
F->arg_size() == 2)
604 .
Case(
"vfrcz.ss", Intrinsic::x86_xop_vfrcz_ss)
605 .
Case(
"vfrcz.sd", Intrinsic::x86_xop_vfrcz_sd)
616 if (
Name ==
"seh.recoverfp") {
629 if (
Name.starts_with(
"rbit")) {
632 F->arg_begin()->getType());
636 if (
Name ==
"thread.pointer") {
643 bool Neon =
Name.consume_front(
"neon.");
648 if (
Name.consume_front(
"bfdot.")) {
652 .
Cases(
"v2f32.v8i8",
"v4f32.v16i8",
657 size_t OperandWidth =
F->getReturnType()->getPrimitiveSizeInBits();
658 assert((OperandWidth == 64 || OperandWidth == 128) &&
659 "Unexpected operand width");
661 std::array<Type *, 2> Tys{
672 if (
Name.consume_front(
"bfm")) {
674 if (
Name.consume_back(
".v4f32.v16i8")) {
714 F->arg_begin()->getType());
718 if (
Name.consume_front(
"vst")) {
720 static const Regex vstRegex(
"^([1234]|[234]lane)\\.v[a-z0-9]*$");
724 Intrinsic::arm_neon_vst1, Intrinsic::arm_neon_vst2,
725 Intrinsic::arm_neon_vst3, Intrinsic::arm_neon_vst4};
728 Intrinsic::arm_neon_vst2lane, Intrinsic::arm_neon_vst3lane,
729 Intrinsic::arm_neon_vst4lane};
731 auto fArgs =
F->getFunctionType()->params();
732 Type *Tys[] = {fArgs[0], fArgs[1]};
735 StoreInts[fArgs.size() - 3], Tys);
738 F->getParent(), StoreLaneInts[fArgs.size() - 5], Tys);
747 if (
Name.consume_front(
"mve.")) {
749 if (
Name ==
"vctp64") {
750 if (cast<FixedVectorType>(
F->getReturnType())->getNumElements() == 4) {
760 if (
Name.consume_back(
".v4i1")) {
762 if (
Name.consume_back(
".predicated.v2i64.v4i32"))
764 return Name ==
"mull.int" ||
Name ==
"vqdmull";
766 if (
Name.consume_back(
".v2i64")) {
768 bool IsGather =
Name.consume_front(
"vldr.gather.");
769 if (IsGather ||
Name.consume_front(
"vstr.scatter.")) {
770 if (
Name.consume_front(
"base.")) {
772 Name.consume_front(
"wb.");
775 return Name ==
"predicated.v2i64";
778 if (
Name.consume_front(
"offset.predicated."))
779 return Name == (IsGather ?
"v2i64.p0i64" :
"p0i64.v2i64") ||
780 Name == (IsGather ?
"v2i64.p0" :
"p0.v2i64");
793 if (
Name.consume_front(
"cde.vcx")) {
795 if (
Name.consume_back(
".predicated.v2i64.v4i1"))
812 F->arg_begin()->getType());
816 if (
Name.starts_with(
"addp")) {
818 if (
F->arg_size() != 2)
820 VectorType *Ty = dyn_cast<VectorType>(
F->getReturnType());
821 if (Ty && Ty->getElementType()->isFloatingPointTy()) {
823 Intrinsic::aarch64_neon_faddp, Ty);
829 if (
Name.consume_front(
"sve.")) {
831 if (
Name.consume_front(
"bf")) {
832 if (
Name.consume_back(
".lane")) {
836 .
Case(
"dot", Intrinsic::aarch64_sve_bfdot_lane_v2)
837 .
Case(
"mlalb", Intrinsic::aarch64_sve_bfmlalb_lane_v2)
838 .
Case(
"mlalt", Intrinsic::aarch64_sve_bfmlalt_lane_v2)
849 if (
Name.consume_front(
"addqv")) {
851 if (!
F->getReturnType()->isFPOrFPVectorTy())
854 auto Args =
F->getFunctionType()->params();
855 Type *Tys[] = {
F->getReturnType(), Args[1]};
857 Intrinsic::aarch64_sve_faddqv, Tys);
861 if (
Name.consume_front(
"ld")) {
863 static const Regex LdRegex(
"^[234](.nxv[a-z0-9]+|$)");
866 cast<VectorType>(
F->getReturnType())->getElementType();
868 cast<VectorType>(
F->arg_begin()->getType())->getElementCount();
869 Type *Ty = VectorType::get(ScalarTy, EC);
871 Intrinsic::aarch64_sve_ld2_sret,
872 Intrinsic::aarch64_sve_ld3_sret,
873 Intrinsic::aarch64_sve_ld4_sret,
876 LoadIDs[
Name[0] -
'2'], Ty);
882 if (
Name.consume_front(
"tuple.")) {
884 if (
Name.starts_with(
"get")) {
886 Type *Tys[] = {
F->getReturnType(),
F->arg_begin()->getType()};
888 Intrinsic::vector_extract, Tys);
892 if (
Name.starts_with(
"set")) {
894 auto Args =
F->getFunctionType()->params();
895 Type *Tys[] = {Args[0], Args[2], Args[1]};
897 Intrinsic::vector_insert, Tys);
901 static const Regex CreateTupleRegex(
"^create[234](.nxv[a-z0-9]+|$)");
904 auto Args =
F->getFunctionType()->params();
905 Type *Tys[] = {
F->getReturnType(), Args[1]};
907 Intrinsic::vector_insert, Tys);
919 if (
Name.consume_front(
"abs."))
921 .
Case(
"bf16", Intrinsic::nvvm_abs_bf16)
922 .
Case(
"bf16x2", Intrinsic::nvvm_abs_bf16x2)
925 if (
Name.consume_front(
"fma.rn."))
927 .
Case(
"bf16", Intrinsic::nvvm_fma_rn_bf16)
928 .
Case(
"bf16x2", Intrinsic::nvvm_fma_rn_bf16x2)
929 .
Case(
"ftz.bf16", Intrinsic::nvvm_fma_rn_ftz_bf16)
930 .
Case(
"ftz.bf16x2", Intrinsic::nvvm_fma_rn_ftz_bf16x2)
931 .
Case(
"ftz.relu.bf16", Intrinsic::nvvm_fma_rn_ftz_relu_bf16)
932 .
Case(
"ftz.relu.bf16x2", Intrinsic::nvvm_fma_rn_ftz_relu_bf16x2)
933 .
Case(
"ftz.sat.bf16", Intrinsic::nvvm_fma_rn_ftz_sat_bf16)
934 .
Case(
"ftz.sat.bf16x2", Intrinsic::nvvm_fma_rn_ftz_sat_bf16x2)
935 .
Case(
"relu.bf16", Intrinsic::nvvm_fma_rn_relu_bf16)
936 .
Case(
"relu.bf16x2", Intrinsic::nvvm_fma_rn_relu_bf16x2)
937 .
Case(
"sat.bf16", Intrinsic::nvvm_fma_rn_sat_bf16)
938 .
Case(
"sat.bf16x2", Intrinsic::nvvm_fma_rn_sat_bf16x2)
941 if (
Name.consume_front(
"fmax."))
943 .
Case(
"bf16", Intrinsic::nvvm_fmax_bf16)
944 .
Case(
"bf16x2", Intrinsic::nvvm_fmax_bf16x2)
945 .
Case(
"ftz.bf16", Intrinsic::nvvm_fmax_ftz_bf16)
946 .
Case(
"ftz.bf16x2", Intrinsic::nvvm_fmax_ftz_bf16x2)
947 .
Case(
"ftz.nan.bf16", Intrinsic::nvvm_fmax_ftz_nan_bf16)
948 .
Case(
"ftz.nan.bf16x2", Intrinsic::nvvm_fmax_ftz_nan_bf16x2)
949 .
Case(
"ftz.nan.xorsign.abs.bf16",
950 Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_bf16)
951 .
Case(
"ftz.nan.xorsign.abs.bf16x2",
952 Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_bf16x2)
953 .
Case(
"ftz.xorsign.abs.bf16", Intrinsic::nvvm_fmax_ftz_xorsign_abs_bf16)
954 .
Case(
"ftz.xorsign.abs.bf16x2",
955 Intrinsic::nvvm_fmax_ftz_xorsign_abs_bf16x2)
956 .
Case(
"nan.bf16", Intrinsic::nvvm_fmax_nan_bf16)
957 .
Case(
"nan.bf16x2", Intrinsic::nvvm_fmax_nan_bf16x2)
958 .
Case(
"nan.xorsign.abs.bf16", Intrinsic::nvvm_fmax_nan_xorsign_abs_bf16)
959 .
Case(
"nan.xorsign.abs.bf16x2",
960 Intrinsic::nvvm_fmax_nan_xorsign_abs_bf16x2)
961 .
Case(
"xorsign.abs.bf16", Intrinsic::nvvm_fmax_xorsign_abs_bf16)
962 .
Case(
"xorsign.abs.bf16x2", Intrinsic::nvvm_fmax_xorsign_abs_bf16x2)
965 if (
Name.consume_front(
"fmin."))
967 .
Case(
"bf16", Intrinsic::nvvm_fmin_bf16)
968 .
Case(
"bf16x2", Intrinsic::nvvm_fmin_bf16x2)
969 .
Case(
"ftz.bf16", Intrinsic::nvvm_fmin_ftz_bf16)
970 .
Case(
"ftz.bf16x2", Intrinsic::nvvm_fmin_ftz_bf16x2)
971 .
Case(
"ftz.nan.bf16", Intrinsic::nvvm_fmin_ftz_nan_bf16)
972 .
Case(
"ftz.nan.bf16x2", Intrinsic::nvvm_fmin_ftz_nan_bf16x2)
973 .
Case(
"ftz.nan.xorsign.abs.bf16",
974 Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_bf16)
975 .
Case(
"ftz.nan.xorsign.abs.bf16x2",
976 Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_bf16x2)
977 .
Case(
"ftz.xorsign.abs.bf16", Intrinsic::nvvm_fmin_ftz_xorsign_abs_bf16)
978 .
Case(
"ftz.xorsign.abs.bf16x2",
979 Intrinsic::nvvm_fmin_ftz_xorsign_abs_bf16x2)
980 .
Case(
"nan.bf16", Intrinsic::nvvm_fmin_nan_bf16)
981 .
Case(
"nan.bf16x2", Intrinsic::nvvm_fmin_nan_bf16x2)
982 .
Case(
"nan.xorsign.abs.bf16", Intrinsic::nvvm_fmin_nan_xorsign_abs_bf16)
983 .
Case(
"nan.xorsign.abs.bf16x2",
984 Intrinsic::nvvm_fmin_nan_xorsign_abs_bf16x2)
985 .
Case(
"xorsign.abs.bf16", Intrinsic::nvvm_fmin_xorsign_abs_bf16)
986 .
Case(
"xorsign.abs.bf16x2", Intrinsic::nvvm_fmin_xorsign_abs_bf16x2)
989 if (
Name.consume_front(
"neg."))
991 .
Case(
"bf16", Intrinsic::nvvm_neg_bf16)
992 .
Case(
"bf16x2", Intrinsic::nvvm_neg_bf16x2)
999 bool CanUpgradeDebugIntrinsicsToRecords) {
1000 assert(
F &&
"Illegal to upgrade a non-existent Function.");
1005 if (!
Name.consume_front(
"llvm.") ||
Name.empty())
1011 bool IsArm =
Name.consume_front(
"arm.");
1012 if (IsArm ||
Name.consume_front(
"aarch64.")) {
1018 if (
Name.consume_front(
"amdgcn.")) {
1019 if (
Name ==
"alignbit") {
1022 {F->getReturnType()});
1026 if (
Name.consume_front(
"atomic.")) {
1027 if (
Name.starts_with(
"inc") ||
Name.starts_with(
"dec")) {
1036 if (
Name.starts_with(
"ds.fadd") ||
Name.starts_with(
"ds.fmin") ||
1037 Name.starts_with(
"ds.fmax")) {
1044 if (
Name.starts_with(
"ldexp.")) {
1047 F->getParent(), Intrinsic::ldexp,
1048 {F->getReturnType(), F->getArg(1)->getType()});
1057 if (
F->arg_size() == 1) {
1065 F->arg_begin()->getType());
1070 if (
F->arg_size() == 2 &&
Name ==
"coro.end") {
1079 if (
Name.consume_front(
"dbg.")) {
1081 if (CanUpgradeDebugIntrinsicsToRecords &&
1082 F->getParent()->IsNewDbgInfoFormat) {
1083 if (
Name ==
"addr" ||
Name ==
"value" ||
Name ==
"assign" ||
1084 Name ==
"declare" ||
Name ==
"label") {
1093 if (
Name ==
"addr" || (
Name ==
"value" &&
F->arg_size() == 4)) {
1102 if (
Name.consume_front(
"experimental.vector.")) {
1105 .
StartsWith(
"extract.", Intrinsic::vector_extract)
1106 .
StartsWith(
"insert.", Intrinsic::vector_insert)
1107 .
StartsWith(
"splice.", Intrinsic::vector_splice)
1108 .
StartsWith(
"reverse.", Intrinsic::vector_reverse)
1109 .
StartsWith(
"interleave2.", Intrinsic::vector_interleave2)
1110 .
StartsWith(
"deinterleave2.", Intrinsic::vector_deinterleave2)
1113 const auto *FT =
F->getFunctionType();
1115 if (
ID == Intrinsic::vector_extract ||
1116 ID == Intrinsic::vector_interleave2)
1119 if (
ID != Intrinsic::vector_interleave2)
1121 if (
ID == Intrinsic::vector_insert)
1129 if (
Name.consume_front(
"reduce.")) {
1131 static const Regex R(
"^([a-z]+)\\.[a-z][0-9]+");
1134 .
Case(
"add", Intrinsic::vector_reduce_add)
1135 .
Case(
"mul", Intrinsic::vector_reduce_mul)
1136 .
Case(
"and", Intrinsic::vector_reduce_and)
1137 .
Case(
"or", Intrinsic::vector_reduce_or)
1138 .
Case(
"xor", Intrinsic::vector_reduce_xor)
1139 .
Case(
"smax", Intrinsic::vector_reduce_smax)
1140 .
Case(
"smin", Intrinsic::vector_reduce_smin)
1141 .
Case(
"umax", Intrinsic::vector_reduce_umax)
1142 .
Case(
"umin", Intrinsic::vector_reduce_umin)
1143 .
Case(
"fmax", Intrinsic::vector_reduce_fmax)
1144 .
Case(
"fmin", Intrinsic::vector_reduce_fmin)
1149 static const Regex R2(
"^v2\\.([a-z]+)\\.[fi][0-9]+");
1154 .
Case(
"fadd", Intrinsic::vector_reduce_fadd)
1155 .
Case(
"fmul", Intrinsic::vector_reduce_fmul)
1160 auto Args =
F->getFunctionType()->params();
1171 if (
Name.starts_with(
"flt.rounds")) {
1178 if (
Name.starts_with(
"invariant.group.barrier")) {
1180 auto Args =
F->getFunctionType()->params();
1181 Type* ObjectPtr[1] = {Args[0]};
1184 Intrinsic::launder_invariant_group, ObjectPtr);
1193 .StartsWith(
"memcpy.", Intrinsic::memcpy)
1194 .StartsWith(
"memmove.", Intrinsic::memmove)
1196 if (
F->arg_size() == 5) {
1200 F->getFunctionType()->params().slice(0, 3);
1205 if (
Name.starts_with(
"memset.") &&
F->arg_size() == 5) {
1208 const auto *FT =
F->getFunctionType();
1209 Type *ParamTypes[2] = {
1210 FT->getParamType(0),
1220 if (
Name.consume_front(
"nvvm.")) {
1222 if (
F->arg_size() == 1) {
1225 .
Cases(
"brev32",
"brev64", Intrinsic::bitreverse)
1226 .
Case(
"clz.i", Intrinsic::ctlz)
1227 .
Case(
"popc.i", Intrinsic::ctpop)
1231 {F->getReturnType()});
1237 if (!
F->getReturnType()->getScalarType()->isBFloatTy()) {
1249 bool Expand =
false;
1250 if (
Name.consume_front(
"abs."))
1252 Expand =
Name ==
"i" ||
Name ==
"ll";
1253 else if (
Name ==
"clz.ll" ||
Name ==
"popc.ll" ||
Name ==
"h2f")
1255 else if (
Name.consume_front(
"max.") ||
Name.consume_front(
"min."))
1259 else if (
Name.consume_front(
"atomic.load.add."))
1261 Expand =
Name.starts_with(
"f32.p") ||
Name.starts_with(
"f64.p");
1276 if (
Name.starts_with(
"objectsize.")) {
1277 Type *Tys[2] = {
F->getReturnType(),
F->arg_begin()->getType() };
1278 if (
F->arg_size() == 2 ||
F->arg_size() == 3 ||
1290 if (
Name.starts_with(
"ptr.annotation.") &&
F->arg_size() == 4) {
1293 F->getParent(), Intrinsic::ptr_annotation,
1294 {F->arg_begin()->getType(), F->getArg(1)->getType()});
1300 if (
Name.consume_front(
"riscv.")) {
1303 .
Case(
"aes32dsi", Intrinsic::riscv_aes32dsi)
1304 .
Case(
"aes32dsmi", Intrinsic::riscv_aes32dsmi)
1305 .
Case(
"aes32esi", Intrinsic::riscv_aes32esi)
1306 .
Case(
"aes32esmi", Intrinsic::riscv_aes32esmi)
1309 if (!
F->getFunctionType()->getParamType(2)->isIntegerTy(32)) {
1322 if (!
F->getFunctionType()->getParamType(2)->isIntegerTy(32) ||
1323 F->getFunctionType()->getReturnType()->isIntegerTy(64)) {
1332 .
StartsWith(
"sha256sig0", Intrinsic::riscv_sha256sig0)
1333 .
StartsWith(
"sha256sig1", Intrinsic::riscv_sha256sig1)
1334 .
StartsWith(
"sha256sum0", Intrinsic::riscv_sha256sum0)
1335 .
StartsWith(
"sha256sum1", Intrinsic::riscv_sha256sum1)
1340 if (
F->getFunctionType()->getReturnType()->isIntegerTy(64)) {
1352 if (
Name ==
"stackprotectorcheck") {
1359 if (
Name ==
"var.annotation" &&
F->arg_size() == 4) {
1362 F->getParent(), Intrinsic::var_annotation,
1363 {{F->arg_begin()->getType(), F->getArg(1)->getType()}});
1370 if (
Name.consume_front(
"wasm.")) {
1373 .
StartsWith(
"fma.", Intrinsic::wasm_relaxed_madd)
1374 .
StartsWith(
"fms.", Intrinsic::wasm_relaxed_nmadd)
1375 .
StartsWith(
"laneselect.", Intrinsic::wasm_relaxed_laneselect)
1384 if (
Name.consume_front(
"dot.i8x16.i7x16.")) {
1386 .
Case(
"signed", Intrinsic::wasm_relaxed_dot_i8x16_i7x16_signed)
1388 Intrinsic::wasm_relaxed_dot_i8x16_i7x16_add_signed)
1406 auto *
ST = dyn_cast<StructType>(
F->getReturnType());
1407 if (ST && (!
ST->isLiteral() ||
ST->isPacked()) &&
1416 auto *FT =
F->getFunctionType();
1418 auto *NewFT = FunctionType::get(NewST, FT->params(), FT->isVarArg());
1419 std::string
Name =
F->getName().str();
1422 Name,
F->getParent());
1433 if (Result != std::nullopt) {
1446 bool CanUpgradeDebugIntrinsicsToRecords) {
1450 assert(
F != NewFn &&
"Intrinsic function upgraded to the same function");
1462 GV->
getName() ==
"llvm.global_dtors")) ||
1477 unsigned N =
Init->getNumOperands();
1478 std::vector<Constant *> NewCtors(
N);
1479 for (
unsigned i = 0; i !=
N; ++i) {
1480 auto Ctor = cast<Constant>(
Init->getOperand(i));
1482 Ctor->getAggregateElement(1),
1495 auto *ResultTy = cast<FixedVectorType>(
Op->getType());
1496 unsigned NumElts = ResultTy->getNumElements() * 8;
1510 for (
unsigned l = 0; l != NumElts; l += 16)
1511 for (
unsigned i = 0; i != 16; ++i) {
1512 unsigned Idx = NumElts + i - Shift;
1514 Idx -= NumElts - 16;
1515 Idxs[l + i] =
Idx + l;
1529 auto *ResultTy = cast<FixedVectorType>(
Op->getType());
1530 unsigned NumElts = ResultTy->getNumElements() * 8;
1544 for (
unsigned l = 0; l != NumElts; l += 16)
1545 for (
unsigned i = 0; i != 16; ++i) {
1546 unsigned Idx = i + Shift;
1548 Idx += NumElts - 16;
1549 Idxs[l + i] =
Idx + l;
1570 for (
unsigned i = 0; i != NumElts; ++i)
1582 if (
const auto *
C = dyn_cast<Constant>(Mask))
1583 if (
C->isAllOnesValue())
1587 cast<FixedVectorType>(Op0->
getType())->getNumElements());
1594 if (
const auto *
C = dyn_cast<Constant>(Mask))
1595 if (
C->isAllOnesValue())
1599 Mask->getType()->getIntegerBitWidth());
1612 unsigned ShiftVal = cast<llvm::ConstantInt>(Shift)->getZExtValue();
1614 unsigned NumElts = cast<FixedVectorType>(Op0->
getType())->getNumElements();
1615 assert((IsVALIGN || NumElts % 16 == 0) &&
"Illegal NumElts for PALIGNR!");
1616 assert((!IsVALIGN || NumElts <= 16) &&
"NumElts too large for VALIGN!");
1621 ShiftVal &= (NumElts - 1);
1630 if (ShiftVal > 16) {
1638 for (
unsigned l = 0; l < NumElts; l += 16) {
1639 for (
unsigned i = 0; i != 16; ++i) {
1640 unsigned Idx = ShiftVal + i;
1641 if (!IsVALIGN &&
Idx >= 16)
1642 Idx += NumElts - 16;
1643 Indices[l + i] =
Idx + l;
1648 Op1, Op0,
ArrayRef(Indices, NumElts),
"palignr");
1654 bool ZeroMask,
bool IndexForm) {
1660 if (VecWidth == 128 && EltWidth == 32 && IsFloat)
1661 IID = Intrinsic::x86_avx512_vpermi2var_ps_128;
1662 else if (VecWidth == 128 && EltWidth == 32 && !IsFloat)
1663 IID = Intrinsic::x86_avx512_vpermi2var_d_128;
1664 else if (VecWidth == 128 && EltWidth == 64 && IsFloat)
1665 IID = Intrinsic::x86_avx512_vpermi2var_pd_128;
1666 else if (VecWidth == 128 && EltWidth == 64 && !IsFloat)
1667 IID = Intrinsic::x86_avx512_vpermi2var_q_128;
1668 else if (VecWidth == 256 && EltWidth == 32 && IsFloat)
1669 IID = Intrinsic::x86_avx512_vpermi2var_ps_256;
1670 else if (VecWidth == 256 && EltWidth == 32 && !IsFloat)
1671 IID = Intrinsic::x86_avx512_vpermi2var_d_256;
1672 else if (VecWidth == 256 && EltWidth == 64 && IsFloat)
1673 IID = Intrinsic::x86_avx512_vpermi2var_pd_256;
1674 else if (VecWidth == 256 && EltWidth == 64 && !IsFloat)
1675 IID = Intrinsic::x86_avx512_vpermi2var_q_256;
1676 else if (VecWidth == 512 && EltWidth == 32 && IsFloat)
1677 IID = Intrinsic::x86_avx512_vpermi2var_ps_512;
1678 else if (VecWidth == 512 && EltWidth == 32 && !IsFloat)
1679 IID = Intrinsic::x86_avx512_vpermi2var_d_512;
1680 else if (VecWidth == 512 && EltWidth == 64 && IsFloat)
1681 IID = Intrinsic::x86_avx512_vpermi2var_pd_512;
1682 else if (VecWidth == 512 && EltWidth == 64 && !IsFloat)
1683 IID = Intrinsic::x86_avx512_vpermi2var_q_512;
1684 else if (VecWidth == 128 && EltWidth == 16)
1685 IID = Intrinsic::x86_avx512_vpermi2var_hi_128;
1686 else if (VecWidth == 256 && EltWidth == 16)
1687 IID = Intrinsic::x86_avx512_vpermi2var_hi_256;
1688 else if (VecWidth == 512 && EltWidth == 16)
1689 IID = Intrinsic::x86_avx512_vpermi2var_hi_512;
1690 else if (VecWidth == 128 && EltWidth == 8)
1691 IID = Intrinsic::x86_avx512_vpermi2var_qi_128;
1692 else if (VecWidth == 256 && EltWidth == 8)
1693 IID = Intrinsic::x86_avx512_vpermi2var_qi_256;
1694 else if (VecWidth == 512 && EltWidth == 8)
1695 IID = Intrinsic::x86_avx512_vpermi2var_qi_512;
1731 bool IsRotateRight) {
1740 unsigned NumElts = cast<FixedVectorType>(Ty)->getNumElements();
1745 Intrinsic::ID IID = IsRotateRight ? Intrinsic::fshr : Intrinsic::fshl;
1766 Pred = IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
1769 Pred = IsSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE;
1772 Pred = IsSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
1775 Pred = IsSigned ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE;
1778 Pred = ICmpInst::ICMP_EQ;
1781 Pred = ICmpInst::ICMP_NE;
1797 bool IsShiftRight,
bool ZeroMask) {
1810 unsigned NumElts = cast<FixedVectorType>(Ty)->getNumElements();
1815 Intrinsic::ID IID = IsShiftRight ? Intrinsic::fshr : Intrinsic::fshl;
1835 const Align Alignment =
1837 ?
Align(Data->getType()->getPrimitiveSizeInBits().getFixedValue() / 8)
1841 if (
const auto *
C = dyn_cast<Constant>(Mask))
1842 if (
C->isAllOnesValue())
1846 unsigned NumElts = cast<FixedVectorType>(Data->getType())->getNumElements();
1856 const Align Alignment =
1864 if (
const auto *
C = dyn_cast<Constant>(Mask))
1865 if (
C->isAllOnesValue())
1869 unsigned NumElts = cast<FixedVectorType>(ValTy)->getNumElements();
1893 Constant *ShiftAmt = ConstantInt::get(Ty, 32);
1900 Constant *Mask = ConstantInt::get(Ty, 0xffffffff);
1916 unsigned NumElts = cast<FixedVectorType>(Vec->
getType())->getNumElements();
1918 const auto *
C = dyn_cast<Constant>(Mask);
1919 if (!
C || !
C->isAllOnesValue())
1925 for (
unsigned i = 0; i != NumElts; ++i)
1927 for (
unsigned i = NumElts; i != 8; ++i)
1928 Indices[i] = NumElts + i % NumElts;
1939 unsigned NumElts = cast<FixedVectorType>(Op0->
getType())->getNumElements();
1945 }
else if (
CC == 7) {
1952 case 0: Pred = ICmpInst::ICMP_EQ;
break;
1953 case 1: Pred =
Signed ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
break;
1954 case 2: Pred =
Signed ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE;
break;
1955 case 4: Pred = ICmpInst::ICMP_NE;
break;
1956 case 5: Pred =
Signed ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE;
break;
1957 case 6: Pred =
Signed ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
break;
1993 unsigned NumElts = cast<FixedVectorType>(CI.
getType())->getNumElements();
1995 return Builder.
CreateSExt(Mask, ReturnOp,
"vpmovm2");
2006 if (
Name.starts_with(
"max.p")) {
2007 if (VecWidth == 128 && EltWidth == 32)
2008 IID = Intrinsic::x86_sse_max_ps;
2009 else if (VecWidth == 128 && EltWidth == 64)
2010 IID = Intrinsic::x86_sse2_max_pd;
2011 else if (VecWidth == 256 && EltWidth == 32)
2012 IID = Intrinsic::x86_avx_max_ps_256;
2013 else if (VecWidth == 256 && EltWidth == 64)
2014 IID = Intrinsic::x86_avx_max_pd_256;
2017 }
else if (
Name.starts_with(
"min.p")) {
2018 if (VecWidth == 128 && EltWidth == 32)
2019 IID = Intrinsic::x86_sse_min_ps;
2020 else if (VecWidth == 128 && EltWidth == 64)
2021 IID = Intrinsic::x86_sse2_min_pd;
2022 else if (VecWidth == 256 && EltWidth == 32)
2023 IID = Intrinsic::x86_avx_min_ps_256;
2024 else if (VecWidth == 256 && EltWidth == 64)
2025 IID = Intrinsic::x86_avx_min_pd_256;
2028 }
else if (
Name.starts_with(
"pshuf.b.")) {
2029 if (VecWidth == 128)
2030 IID = Intrinsic::x86_ssse3_pshuf_b_128;
2031 else if (VecWidth == 256)
2032 IID = Intrinsic::x86_avx2_pshuf_b;
2033 else if (VecWidth == 512)
2034 IID = Intrinsic::x86_avx512_pshuf_b_512;
2037 }
else if (
Name.starts_with(
"pmul.hr.sw.")) {
2038 if (VecWidth == 128)
2039 IID = Intrinsic::x86_ssse3_pmul_hr_sw_128;
2040 else if (VecWidth == 256)
2041 IID = Intrinsic::x86_avx2_pmul_hr_sw;
2042 else if (VecWidth == 512)
2043 IID = Intrinsic::x86_avx512_pmul_hr_sw_512;
2046 }
else if (
Name.starts_with(
"pmulh.w.")) {
2047 if (VecWidth == 128)
2048 IID = Intrinsic::x86_sse2_pmulh_w;
2049 else if (VecWidth == 256)
2050 IID = Intrinsic::x86_avx2_pmulh_w;
2051 else if (VecWidth == 512)
2052 IID = Intrinsic::x86_avx512_pmulh_w_512;
2055 }
else if (
Name.starts_with(
"pmulhu.w.")) {
2056 if (VecWidth == 128)
2057 IID = Intrinsic::x86_sse2_pmulhu_w;
2058 else if (VecWidth == 256)
2059 IID = Intrinsic::x86_avx2_pmulhu_w;
2060 else if (VecWidth == 512)
2061 IID = Intrinsic::x86_avx512_pmulhu_w_512;
2064 }
else if (
Name.starts_with(
"pmaddw.d.")) {
2065 if (VecWidth == 128)
2066 IID = Intrinsic::x86_sse2_pmadd_wd;
2067 else if (VecWidth == 256)
2068 IID = Intrinsic::x86_avx2_pmadd_wd;
2069 else if (VecWidth == 512)
2070 IID = Intrinsic::x86_avx512_pmaddw_d_512;
2073 }
else if (
Name.starts_with(
"pmaddubs.w.")) {
2074 if (VecWidth == 128)
2075 IID = Intrinsic::x86_ssse3_pmadd_ub_sw_128;
2076 else if (VecWidth == 256)
2077 IID = Intrinsic::x86_avx2_pmadd_ub_sw;
2078 else if (VecWidth == 512)
2079 IID = Intrinsic::x86_avx512_pmaddubs_w_512;
2082 }
else if (
Name.starts_with(
"packsswb.")) {
2083 if (VecWidth == 128)
2084 IID = Intrinsic::x86_sse2_packsswb_128;
2085 else if (VecWidth == 256)
2086 IID = Intrinsic::x86_avx2_packsswb;
2087 else if (VecWidth == 512)
2088 IID = Intrinsic::x86_avx512_packsswb_512;
2091 }
else if (
Name.starts_with(
"packssdw.")) {
2092 if (VecWidth == 128)
2093 IID = Intrinsic::x86_sse2_packssdw_128;
2094 else if (VecWidth == 256)
2095 IID = Intrinsic::x86_avx2_packssdw;
2096 else if (VecWidth == 512)
2097 IID = Intrinsic::x86_avx512_packssdw_512;
2100 }
else if (
Name.starts_with(
"packuswb.")) {
2101 if (VecWidth == 128)
2102 IID = Intrinsic::x86_sse2_packuswb_128;
2103 else if (VecWidth == 256)
2104 IID = Intrinsic::x86_avx2_packuswb;
2105 else if (VecWidth == 512)
2106 IID = Intrinsic::x86_avx512_packuswb_512;
2109 }
else if (
Name.starts_with(
"packusdw.")) {
2110 if (VecWidth == 128)
2111 IID = Intrinsic::x86_sse41_packusdw;
2112 else if (VecWidth == 256)
2113 IID = Intrinsic::x86_avx2_packusdw;
2114 else if (VecWidth == 512)
2115 IID = Intrinsic::x86_avx512_packusdw_512;
2118 }
else if (
Name.starts_with(
"vpermilvar.")) {
2119 if (VecWidth == 128 && EltWidth == 32)
2120 IID = Intrinsic::x86_avx_vpermilvar_ps;
2121 else if (VecWidth == 128 && EltWidth == 64)
2122 IID = Intrinsic::x86_avx_vpermilvar_pd;
2123 else if (VecWidth == 256 && EltWidth == 32)
2124 IID = Intrinsic::x86_avx_vpermilvar_ps_256;
2125 else if (VecWidth == 256 && EltWidth == 64)
2126 IID = Intrinsic::x86_avx_vpermilvar_pd_256;
2127 else if (VecWidth == 512 && EltWidth == 32)
2128 IID = Intrinsic::x86_avx512_vpermilvar_ps_512;
2129 else if (VecWidth == 512 && EltWidth == 64)
2130 IID = Intrinsic::x86_avx512_vpermilvar_pd_512;
2133 }
else if (
Name ==
"cvtpd2dq.256") {
2134 IID = Intrinsic::x86_avx_cvt_pd2dq_256;
2135 }
else if (
Name ==
"cvtpd2ps.256") {
2136 IID = Intrinsic::x86_avx_cvt_pd2_ps_256;
2137 }
else if (
Name ==
"cvttpd2dq.256") {
2138 IID = Intrinsic::x86_avx_cvtt_pd2dq_256;
2139 }
else if (
Name ==
"cvttps2dq.128") {
2140 IID = Intrinsic::x86_sse2_cvttps2dq;
2141 }
else if (
Name ==
"cvttps2dq.256") {
2142 IID = Intrinsic::x86_avx_cvtt_ps2dq_256;
2143 }
else if (
Name.starts_with(
"permvar.")) {
2145 if (VecWidth == 256 && EltWidth == 32 && IsFloat)
2146 IID = Intrinsic::x86_avx2_permps;
2147 else if (VecWidth == 256 && EltWidth == 32 && !IsFloat)
2148 IID = Intrinsic::x86_avx2_permd;
2149 else if (VecWidth == 256 && EltWidth == 64 && IsFloat)
2150 IID = Intrinsic::x86_avx512_permvar_df_256;
2151 else if (VecWidth == 256 && EltWidth == 64 && !IsFloat)
2152 IID = Intrinsic::x86_avx512_permvar_di_256;
2153 else if (VecWidth == 512 && EltWidth == 32 && IsFloat)
2154 IID = Intrinsic::x86_avx512_permvar_sf_512;
2155 else if (VecWidth == 512 && EltWidth == 32 && !IsFloat)
2156 IID = Intrinsic::x86_avx512_permvar_si_512;
2157 else if (VecWidth == 512 && EltWidth == 64 && IsFloat)
2158 IID = Intrinsic::x86_avx512_permvar_df_512;
2159 else if (VecWidth == 512 && EltWidth == 64 && !IsFloat)
2160 IID = Intrinsic::x86_avx512_permvar_di_512;
2161 else if (VecWidth == 128 && EltWidth == 16)
2162 IID = Intrinsic::x86_avx512_permvar_hi_128;
2163 else if (VecWidth == 256 && EltWidth == 16)
2164 IID = Intrinsic::x86_avx512_permvar_hi_256;
2165 else if (VecWidth == 512 && EltWidth == 16)
2166 IID = Intrinsic::x86_avx512_permvar_hi_512;
2167 else if (VecWidth == 128 && EltWidth == 8)
2168 IID = Intrinsic::x86_avx512_permvar_qi_128;
2169 else if (VecWidth == 256 && EltWidth == 8)
2170 IID = Intrinsic::x86_avx512_permvar_qi_256;
2171 else if (VecWidth == 512 && EltWidth == 8)
2172 IID = Intrinsic::x86_avx512_permvar_qi_512;
2175 }
else if (
Name.starts_with(
"dbpsadbw.")) {
2176 if (VecWidth == 128)
2177 IID = Intrinsic::x86_avx512_dbpsadbw_128;
2178 else if (VecWidth == 256)
2179 IID = Intrinsic::x86_avx512_dbpsadbw_256;
2180 else if (VecWidth == 512)
2181 IID = Intrinsic::x86_avx512_dbpsadbw_512;
2184 }
else if (
Name.starts_with(
"pmultishift.qb.")) {
2185 if (VecWidth == 128)
2186 IID = Intrinsic::x86_avx512_pmultishift_qb_128;
2187 else if (VecWidth == 256)
2188 IID = Intrinsic::x86_avx512_pmultishift_qb_256;
2189 else if (VecWidth == 512)
2190 IID = Intrinsic::x86_avx512_pmultishift_qb_512;
2193 }
else if (
Name.starts_with(
"conflict.")) {
2194 if (
Name[9] ==
'd' && VecWidth == 128)
2195 IID = Intrinsic::x86_avx512_conflict_d_128;
2196 else if (
Name[9] ==
'd' && VecWidth == 256)
2197 IID = Intrinsic::x86_avx512_conflict_d_256;
2198 else if (
Name[9] ==
'd' && VecWidth == 512)
2199 IID = Intrinsic::x86_avx512_conflict_d_512;
2200 else if (
Name[9] ==
'q' && VecWidth == 128)
2201 IID = Intrinsic::x86_avx512_conflict_q_128;
2202 else if (
Name[9] ==
'q' && VecWidth == 256)
2203 IID = Intrinsic::x86_avx512_conflict_q_256;
2204 else if (
Name[9] ==
'q' && VecWidth == 512)
2205 IID = Intrinsic::x86_avx512_conflict_q_512;
2208 }
else if (
Name.starts_with(
"pavg.")) {
2209 if (
Name[5] ==
'b' && VecWidth == 128)
2210 IID = Intrinsic::x86_sse2_pavg_b;
2211 else if (
Name[5] ==
'b' && VecWidth == 256)
2212 IID = Intrinsic::x86_avx2_pavg_b;
2213 else if (
Name[5] ==
'b' && VecWidth == 512)
2214 IID = Intrinsic::x86_avx512_pavg_b_512;
2215 else if (
Name[5] ==
'w' && VecWidth == 128)
2216 IID = Intrinsic::x86_sse2_pavg_w;
2217 else if (
Name[5] ==
'w' && VecWidth == 256)
2218 IID = Intrinsic::x86_avx2_pavg_w;
2219 else if (
Name[5] ==
'w' && VecWidth == 512)
2220 IID = Intrinsic::x86_avx512_pavg_w_512;
2241 if (AsmStr->find(
"mov\tfp") == 0 &&
2242 AsmStr->find(
"objc_retainAutoreleaseReturnValue") != std::string::npos &&
2243 (Pos = AsmStr->find(
"# marker")) != std::string::npos) {
2244 AsmStr->replace(Pos, 1,
";");
2251 Value *Rep =
nullptr;
2253 if (
Name.starts_with(
"sse4a.movnt.")) {
2264 Type *SrcEltTy = cast<VectorType>(Arg1->
getType())->getElementType();
2265 PointerType *EltPtrTy = PointerType::getUnqual(SrcEltTy);
2271 SI->setMetadata(LLVMContext::MD_nontemporal,
Node);
2272 }
else if (
Name.starts_with(
"avx.movnt.") ||
2273 Name.starts_with(
"avx512.storent.")) {
2284 Arg0, PointerType::getUnqual(Arg1->
getType()),
"cast");
2288 SI->setMetadata(LLVMContext::MD_nontemporal,
Node);
2289 }
else if (
Name ==
"sse2.storel.dq") {
2297 Arg0, PointerType::getUnqual(Elt->
getType()),
"cast");
2299 }
else if (
Name.starts_with(
"sse.storeu.") ||
2300 Name.starts_with(
"sse2.storeu.") ||
2301 Name.starts_with(
"avx.storeu.")) {
2308 }
else if (
Name ==
"avx512.mask.store.ss") {
2312 }
else if (
Name.starts_with(
"avx512.mask.store")) {
2317 }
else if (
Name.starts_with(
"sse2.pcmp") ||
Name.starts_with(
"avx2.pcmp")) {
2320 bool CmpEq =
Name[9] ==
'e';
2321 Rep = Builder.
CreateICmp(CmpEq ? ICmpInst::ICMP_EQ : ICmpInst::ICMP_SGT,
2324 }
else if (
Name.starts_with(
"avx512.broadcastm")) {
2332 }
else if (
Name ==
"sse.sqrt.ss" ||
Name ==
"sse2.sqrt.sd") {
2339 }
else if (
Name.starts_with(
"avx.sqrt.p") ||
2340 Name.starts_with(
"sse2.sqrt.p") ||
2341 Name.starts_with(
"sse.sqrt.p")) {
2344 F->getParent(), Intrinsic::sqrt, CI->
getType()),
2345 {CI->getArgOperand(0)});
2346 }
else if (
Name.starts_with(
"avx512.mask.sqrt.p")) {
2349 cast<ConstantInt>(CI->
getArgOperand(3))->getZExtValue() != 4)) {
2351 : Intrinsic::x86_avx512_sqrt_pd_512;
2360 {CI->getArgOperand(0)});
2364 }
else if (
Name.starts_with(
"avx512.ptestm") ||
2365 Name.starts_with(
"avx512.ptestnm")) {
2374 : ICmpInst::ICMP_EQ;
2377 }
else if (
Name.starts_with(
"avx512.mask.pbroadcast")) {
2383 }
else if (
Name.starts_with(
"avx512.kunpck")) {
2388 for (
unsigned i = 0; i != NumElts; ++i)
2399 }
else if (
Name ==
"avx512.kand.w") {
2404 }
else if (
Name ==
"avx512.kandn.w") {
2410 }
else if (
Name ==
"avx512.kor.w") {
2415 }
else if (
Name ==
"avx512.kxor.w") {
2420 }
else if (
Name ==
"avx512.kxnor.w") {
2426 }
else if (
Name ==
"avx512.knot.w") {
2430 }
else if (
Name ==
"avx512.kortestz.w" ||
Name ==
"avx512.kortestc.w") {
2436 if (
Name[14] ==
'c')
2437 C = ConstantInt::getAllOnesValue(Builder.
getInt16Ty());
2439 C = ConstantInt::getNullValue(Builder.
getInt16Ty());
2442 }
else if (
Name ==
"sse.add.ss" ||
Name ==
"sse2.add.sd" ||
2443 Name ==
"sse.sub.ss" ||
Name ==
"sse2.sub.sd" ||
2444 Name ==
"sse.mul.ss" ||
Name ==
"sse2.mul.sd" ||
2445 Name ==
"sse.div.ss" ||
Name ==
"sse2.div.sd") {
2448 ConstantInt::get(I32Ty, 0));
2450 ConstantInt::get(I32Ty, 0));
2452 if (
Name.contains(
".add."))
2454 else if (
Name.contains(
".sub."))
2456 else if (
Name.contains(
".mul."))
2461 ConstantInt::get(I32Ty, 0));
2462 }
else if (
Name.starts_with(
"avx512.mask.pcmp")) {
2464 bool CmpEq =
Name[16] ==
'e';
2466 }
else if (
Name.starts_with(
"avx512.mask.vpshufbitqmb.")) {
2474 IID = Intrinsic::x86_avx512_vpshufbitqmb_128;
2477 IID = Intrinsic::x86_avx512_vpshufbitqmb_256;
2480 IID = Intrinsic::x86_avx512_vpshufbitqmb_512;
2485 {CI->getOperand(0), CI->getArgOperand(1)});
2487 }
else if (
Name.starts_with(
"avx512.mask.fpclass.p")) {
2492 if (VecWidth == 128 && EltWidth == 32)
2493 IID = Intrinsic::x86_avx512_fpclass_ps_128;
2494 else if (VecWidth == 256 && EltWidth == 32)
2495 IID = Intrinsic::x86_avx512_fpclass_ps_256;
2496 else if (VecWidth == 512 && EltWidth == 32)
2497 IID = Intrinsic::x86_avx512_fpclass_ps_512;
2498 else if (VecWidth == 128 && EltWidth == 64)
2499 IID = Intrinsic::x86_avx512_fpclass_pd_128;
2500 else if (VecWidth == 256 && EltWidth == 64)
2501 IID = Intrinsic::x86_avx512_fpclass_pd_256;
2502 else if (VecWidth == 512 && EltWidth == 64)
2503 IID = Intrinsic::x86_avx512_fpclass_pd_512;
2508 {CI->getOperand(0), CI->getArgOperand(1)});
2510 }
else if (
Name.starts_with(
"avx512.cmp.p")) {
2512 Type *OpTy = Args[0]->getType();
2516 if (VecWidth == 128 && EltWidth == 32)
2517 IID = Intrinsic::x86_avx512_mask_cmp_ps_128;
2518 else if (VecWidth == 256 && EltWidth == 32)
2519 IID = Intrinsic::x86_avx512_mask_cmp_ps_256;
2520 else if (VecWidth == 512 && EltWidth == 32)
2521 IID = Intrinsic::x86_avx512_mask_cmp_ps_512;
2522 else if (VecWidth == 128 && EltWidth == 64)
2523 IID = Intrinsic::x86_avx512_mask_cmp_pd_128;
2524 else if (VecWidth == 256 && EltWidth == 64)
2525 IID = Intrinsic::x86_avx512_mask_cmp_pd_256;
2526 else if (VecWidth == 512 && EltWidth == 64)
2527 IID = Intrinsic::x86_avx512_mask_cmp_pd_512;
2532 if (VecWidth == 512)
2534 Args.push_back(Mask);
2538 }
else if (
Name.starts_with(
"avx512.mask.cmp.")) {
2540 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(2))->getZExtValue();
2542 }
else if (
Name.starts_with(
"avx512.mask.ucmp.")) {
2543 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(2))->getZExtValue();
2545 }
else if (
Name.starts_with(
"avx512.cvtb2mask.") ||
2546 Name.starts_with(
"avx512.cvtw2mask.") ||
2547 Name.starts_with(
"avx512.cvtd2mask.") ||
2548 Name.starts_with(
"avx512.cvtq2mask.")) {
2551 Rep = Builder.
CreateICmp(ICmpInst::ICMP_SLT,
Op, Zero);
2553 }
else if (
Name ==
"ssse3.pabs.b.128" ||
Name ==
"ssse3.pabs.w.128" ||
2554 Name ==
"ssse3.pabs.d.128" ||
Name.starts_with(
"avx2.pabs") ||
2555 Name.starts_with(
"avx512.mask.pabs")) {
2557 }
else if (
Name ==
"sse41.pmaxsb" ||
Name ==
"sse2.pmaxs.w" ||
2558 Name ==
"sse41.pmaxsd" ||
Name.starts_with(
"avx2.pmaxs") ||
2559 Name.starts_with(
"avx512.mask.pmaxs")) {
2561 }
else if (
Name ==
"sse2.pmaxu.b" ||
Name ==
"sse41.pmaxuw" ||
2562 Name ==
"sse41.pmaxud" ||
Name.starts_with(
"avx2.pmaxu") ||
2563 Name.starts_with(
"avx512.mask.pmaxu")) {
2565 }
else if (
Name ==
"sse41.pminsb" ||
Name ==
"sse2.pmins.w" ||
2566 Name ==
"sse41.pminsd" ||
Name.starts_with(
"avx2.pmins") ||
2567 Name.starts_with(
"avx512.mask.pmins")) {
2569 }
else if (
Name ==
"sse2.pminu.b" ||
Name ==
"sse41.pminuw" ||
2570 Name ==
"sse41.pminud" ||
Name.starts_with(
"avx2.pminu") ||
2571 Name.starts_with(
"avx512.mask.pminu")) {
2573 }
else if (
Name ==
"sse2.pmulu.dq" ||
Name ==
"avx2.pmulu.dq" ||
2574 Name ==
"avx512.pmulu.dq.512" ||
2575 Name.starts_with(
"avx512.mask.pmulu.dq.")) {
2577 }
else if (
Name ==
"sse41.pmuldq" ||
Name ==
"avx2.pmul.dq" ||
2578 Name ==
"avx512.pmul.dq.512" ||
2579 Name.starts_with(
"avx512.mask.pmul.dq.")) {
2581 }
else if (
Name ==
"sse.cvtsi2ss" ||
Name ==
"sse2.cvtsi2sd" ||
2582 Name ==
"sse.cvtsi642ss" ||
Name ==
"sse2.cvtsi642sd") {
2585 cast<VectorType>(CI->
getType())->getElementType());
2587 }
else if (
Name ==
"avx512.cvtusi2sd") {
2590 cast<VectorType>(CI->
getType())->getElementType());
2592 }
else if (
Name ==
"sse2.cvtss2sd") {
2595 Rep, cast<VectorType>(CI->
getType())->getElementType());
2597 }
else if (
Name ==
"sse2.cvtdq2pd" ||
Name ==
"sse2.cvtdq2ps" ||
2598 Name ==
"avx.cvtdq2.pd.256" ||
Name ==
"avx.cvtdq2.ps.256" ||
2599 Name.starts_with(
"avx512.mask.cvtdq2pd.") ||
2600 Name.starts_with(
"avx512.mask.cvtudq2pd.") ||
2601 Name.starts_with(
"avx512.mask.cvtdq2ps.") ||
2602 Name.starts_with(
"avx512.mask.cvtudq2ps.") ||
2603 Name.starts_with(
"avx512.mask.cvtqq2pd.") ||
2604 Name.starts_with(
"avx512.mask.cvtuqq2pd.") ||
2605 Name ==
"avx512.mask.cvtqq2ps.256" ||
2606 Name ==
"avx512.mask.cvtqq2ps.512" ||
2607 Name ==
"avx512.mask.cvtuqq2ps.256" ||
2608 Name ==
"avx512.mask.cvtuqq2ps.512" ||
Name ==
"sse2.cvtps2pd" ||
2609 Name ==
"avx.cvt.ps2.pd.256" ||
2610 Name ==
"avx512.mask.cvtps2pd.128" ||
2611 Name ==
"avx512.mask.cvtps2pd.256") {
2612 auto *DstTy = cast<FixedVectorType>(CI->
getType());
2614 auto *SrcTy = cast<FixedVectorType>(Rep->
getType());
2616 unsigned NumDstElts = DstTy->getNumElements();
2618 assert(NumDstElts == 2 &&
"Unexpected vector size");
2622 bool IsPS2PD = SrcTy->getElementType()->isFloatTy();
2623 bool IsUnsigned =
Name.contains(
"cvtu");
2625 Rep = Builder.
CreateFPExt(Rep, DstTy,
"cvtps2pd");
2628 cast<ConstantInt>(CI->
getArgOperand(3))->getZExtValue() != 4)) {
2629 Intrinsic::ID IID = IsUnsigned ? Intrinsic::x86_avx512_uitofp_round
2630 : Intrinsic::x86_avx512_sitofp_round;
2635 Rep = IsUnsigned ? Builder.
CreateUIToFP(Rep, DstTy,
"cvt")
2642 }
else if (
Name.starts_with(
"avx512.mask.vcvtph2ps.") ||
2643 Name.starts_with(
"vcvtph2ps.")) {
2644 auto *DstTy = cast<FixedVectorType>(CI->
getType());
2646 auto *SrcTy = cast<FixedVectorType>(Rep->
getType());
2647 unsigned NumDstElts = DstTy->getNumElements();
2648 if (NumDstElts != SrcTy->getNumElements()) {
2649 assert(NumDstElts == 4 &&
"Unexpected vector size");
2654 Rep = Builder.
CreateFPExt(Rep, DstTy,
"cvtph2ps");
2658 }
else if (
Name.starts_with(
"avx512.mask.load")) {
2663 }
else if (
Name.starts_with(
"avx512.mask.expand.load.")) {
2664 auto *ResultTy = cast<FixedVectorType>(CI->
getType());
2665 Type *PtrTy = ResultTy->getElementType();
2672 ResultTy->getNumElements());
2675 F->getParent(), Intrinsic::masked_expandload, ResultTy);
2677 }
else if (
Name.starts_with(
"avx512.mask.compress.store.")) {
2679 Type *PtrTy = ResultTy->getElementType();
2687 cast<FixedVectorType>(ResultTy)->getNumElements());
2690 F->getParent(), Intrinsic::masked_compressstore, ResultTy);
2692 }
else if (
Name.starts_with(
"avx512.mask.compress.") ||
2693 Name.starts_with(
"avx512.mask.expand.")) {
2694 auto *ResultTy = cast<FixedVectorType>(CI->
getType());
2697 ResultTy->getNumElements());
2699 bool IsCompress =
Name[12] ==
'c';
2700 Intrinsic::ID IID = IsCompress ? Intrinsic::x86_avx512_mask_compress
2701 : Intrinsic::x86_avx512_mask_expand;
2705 }
else if (
Name.starts_with(
"xop.vpcom")) {
2707 if (
Name.ends_with(
"ub") ||
Name.ends_with(
"uw") ||
Name.ends_with(
"ud") ||
2708 Name.ends_with(
"uq"))
2710 else if (
Name.ends_with(
"b") ||
Name.ends_with(
"w") ||
2711 Name.ends_with(
"d") ||
Name.ends_with(
"q"))
2718 Imm = cast<ConstantInt>(CI->
getArgOperand(2))->getZExtValue();
2721 if (
Name.starts_with(
"lt"))
2723 else if (
Name.starts_with(
"le"))
2725 else if (
Name.starts_with(
"gt"))
2727 else if (
Name.starts_with(
"ge"))
2729 else if (
Name.starts_with(
"eq"))
2731 else if (
Name.starts_with(
"ne"))
2733 else if (
Name.starts_with(
"false"))
2735 else if (
Name.starts_with(
"true"))
2742 }
else if (
Name.starts_with(
"xop.vpcmov")) {
2747 Rep = Builder.
CreateOr(Sel0, Sel1);
2748 }
else if (
Name.starts_with(
"xop.vprot") ||
Name.starts_with(
"avx512.prol") ||
2749 Name.starts_with(
"avx512.mask.prol")) {
2751 }
else if (
Name.starts_with(
"avx512.pror") ||
2752 Name.starts_with(
"avx512.mask.pror")) {
2754 }
else if (
Name.starts_with(
"avx512.vpshld.") ||
2755 Name.starts_with(
"avx512.mask.vpshld") ||
2756 Name.starts_with(
"avx512.maskz.vpshld")) {
2757 bool ZeroMask =
Name[11] ==
'z';
2759 }
else if (
Name.starts_with(
"avx512.vpshrd.") ||
2760 Name.starts_with(
"avx512.mask.vpshrd") ||
2761 Name.starts_with(
"avx512.maskz.vpshrd")) {
2762 bool ZeroMask =
Name[11] ==
'z';
2764 }
else if (
Name ==
"sse42.crc32.64.8") {
2766 F->getParent(), Intrinsic::x86_sse42_crc32_32_8);
2771 }
else if (
Name.starts_with(
"avx.vbroadcast.s") ||
2772 Name.starts_with(
"avx512.vbroadcast.s")) {
2774 auto *VecTy = cast<FixedVectorType>(CI->
getType());
2775 Type *EltTy = VecTy->getElementType();
2776 unsigned EltNum = VecTy->getNumElements();
2780 for (
unsigned I = 0;
I < EltNum; ++
I)
2782 }
else if (
Name.starts_with(
"sse41.pmovsx") ||
2783 Name.starts_with(
"sse41.pmovzx") ||
2784 Name.starts_with(
"avx2.pmovsx") ||
2785 Name.starts_with(
"avx2.pmovzx") ||
2786 Name.starts_with(
"avx512.mask.pmovsx") ||
2787 Name.starts_with(
"avx512.mask.pmovzx")) {
2788 auto *DstTy = cast<FixedVectorType>(CI->
getType());
2789 unsigned NumDstElts = DstTy->getNumElements();
2793 for (
unsigned i = 0; i != NumDstElts; ++i)
2798 bool DoSext =
Name.contains(
"pmovsx");
2805 }
else if (
Name ==
"avx512.mask.pmov.qd.256" ||
2806 Name ==
"avx512.mask.pmov.qd.512" ||
2807 Name ==
"avx512.mask.pmov.wb.256" ||
2808 Name ==
"avx512.mask.pmov.wb.512") {
2813 }
else if (
Name.starts_with(
"avx.vbroadcastf128") ||
2814 Name ==
"avx2.vbroadcasti128") {
2816 Type *EltTy = cast<VectorType>(CI->
getType())->getElementType();
2820 PointerType::getUnqual(VT));
2822 if (NumSrcElts == 2)
2827 }
else if (
Name.starts_with(
"avx512.mask.shuf.i") ||
2828 Name.starts_with(
"avx512.mask.shuf.f")) {
2829 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(2))->getZExtValue();
2833 unsigned ControlBitsMask = NumLanes - 1;
2834 unsigned NumControlBits = NumLanes / 2;
2837 for (
unsigned l = 0; l != NumLanes; ++l) {
2838 unsigned LaneMask = (Imm >> (l * NumControlBits)) & ControlBitsMask;
2840 if (l >= NumLanes / 2)
2841 LaneMask += NumLanes;
2842 for (
unsigned i = 0; i != NumElementsInLane; ++i)
2843 ShuffleMask.
push_back(LaneMask * NumElementsInLane + i);
2849 }
else if (
Name.starts_with(
"avx512.mask.broadcastf") ||
2850 Name.starts_with(
"avx512.mask.broadcasti")) {
2853 unsigned NumDstElts =
2854 cast<FixedVectorType>(CI->
getType())->getNumElements();
2857 for (
unsigned i = 0; i != NumDstElts; ++i)
2858 ShuffleMask[i] = i % NumSrcElts;
2864 }
else if (
Name.starts_with(
"avx2.pbroadcast") ||
2865 Name.starts_with(
"avx2.vbroadcast") ||
2866 Name.starts_with(
"avx512.pbroadcast") ||
2867 Name.starts_with(
"avx512.mask.broadcast.s")) {
2879 }
else if (
Name.starts_with(
"sse2.padds.") ||
2880 Name.starts_with(
"avx2.padds.") ||
2881 Name.starts_with(
"avx512.padds.") ||
2882 Name.starts_with(
"avx512.mask.padds.")) {
2884 }
else if (
Name.starts_with(
"sse2.psubs.") ||
2885 Name.starts_with(
"avx2.psubs.") ||
2886 Name.starts_with(
"avx512.psubs.") ||
2887 Name.starts_with(
"avx512.mask.psubs.")) {
2889 }
else if (
Name.starts_with(
"sse2.paddus.") ||
2890 Name.starts_with(
"avx2.paddus.") ||
2891 Name.starts_with(
"avx512.mask.paddus.")) {
2893 }
else if (
Name.starts_with(
"sse2.psubus.") ||
2894 Name.starts_with(
"avx2.psubus.") ||
2895 Name.starts_with(
"avx512.mask.psubus.")) {
2897 }
else if (
Name.starts_with(
"avx512.mask.palignr.")) {
2902 }
else if (
Name.starts_with(
"avx512.mask.valign.")) {
2906 }
else if (
Name ==
"sse2.psll.dq" ||
Name ==
"avx2.psll.dq") {
2908 unsigned Shift = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
2911 }
else if (
Name ==
"sse2.psrl.dq" ||
Name ==
"avx2.psrl.dq") {
2913 unsigned Shift = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
2916 }
else if (
Name ==
"sse2.psll.dq.bs" ||
Name ==
"avx2.psll.dq.bs" ||
2917 Name ==
"avx512.psll.dq.512") {
2919 unsigned Shift = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
2921 }
else if (
Name ==
"sse2.psrl.dq.bs" ||
Name ==
"avx2.psrl.dq.bs" ||
2922 Name ==
"avx512.psrl.dq.512") {
2924 unsigned Shift = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
2926 }
else if (
Name ==
"sse41.pblendw" ||
Name.starts_with(
"sse41.blendp") ||
2927 Name.starts_with(
"avx.blend.p") ||
Name ==
"avx2.pblendw" ||
2928 Name.starts_with(
"avx2.pblendd.")) {
2931 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(2))->getZExtValue();
2932 auto *VecTy = cast<FixedVectorType>(CI->
getType());
2933 unsigned NumElts = VecTy->getNumElements();
2936 for (
unsigned i = 0; i != NumElts; ++i)
2937 Idxs[i] = ((Imm >> (i % 8)) & 1) ? i + NumElts : i;
2940 }
else if (
Name.starts_with(
"avx.vinsertf128.") ||
2941 Name ==
"avx2.vinserti128" ||
2942 Name.starts_with(
"avx512.mask.insert")) {
2945 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(2))->getZExtValue();
2946 unsigned DstNumElts =
2947 cast<FixedVectorType>(CI->
getType())->getNumElements();
2948 unsigned SrcNumElts =
2949 cast<FixedVectorType>(Op1->
getType())->getNumElements();
2950 unsigned Scale = DstNumElts / SrcNumElts;
2957 for (
unsigned i = 0; i != SrcNumElts; ++i)
2959 for (
unsigned i = SrcNumElts; i != DstNumElts; ++i)
2960 Idxs[i] = SrcNumElts;
2975 for (
unsigned i = 0; i != DstNumElts; ++i)
2978 for (
unsigned i = 0; i != SrcNumElts; ++i)
2979 Idxs[i + Imm * SrcNumElts] = i + DstNumElts;
2986 }
else if (
Name.starts_with(
"avx.vextractf128.") ||
2987 Name ==
"avx2.vextracti128" ||
2988 Name.starts_with(
"avx512.mask.vextract")) {
2990 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
2991 unsigned DstNumElts =
2992 cast<FixedVectorType>(CI->
getType())->getNumElements();
2993 unsigned SrcNumElts =
2994 cast<FixedVectorType>(Op0->
getType())->getNumElements();
2995 unsigned Scale = SrcNumElts / DstNumElts;
3002 for (
unsigned i = 0; i != DstNumElts; ++i) {
3003 Idxs[i] = i + (Imm * DstNumElts);
3011 }
else if (
Name.starts_with(
"avx512.mask.perm.df.") ||
3012 Name.starts_with(
"avx512.mask.perm.di.")) {
3014 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
3015 auto *VecTy = cast<FixedVectorType>(CI->
getType());
3016 unsigned NumElts = VecTy->getNumElements();
3019 for (
unsigned i = 0; i != NumElts; ++i)
3020 Idxs[i] = (i & ~0x3) + ((Imm >> (2 * (i & 0x3))) & 3);
3027 }
else if (
Name.starts_with(
"avx.vperm2f128.") ||
Name ==
"avx2.vperm2i128") {
3036 uint8_t Imm = cast<ConstantInt>(CI->
getArgOperand(2))->getZExtValue();
3038 unsigned NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
3039 unsigned HalfSize = NumElts / 2;
3051 unsigned StartIndex = (Imm & 0x01) ? HalfSize : 0;
3052 for (
unsigned i = 0; i < HalfSize; ++i)
3053 ShuffleMask[i] = StartIndex + i;
3056 StartIndex = (Imm & 0x10) ? HalfSize : 0;
3057 for (
unsigned i = 0; i < HalfSize; ++i)
3058 ShuffleMask[i + HalfSize] = NumElts + StartIndex + i;
3062 }
else if (
Name.starts_with(
"avx.vpermil.") ||
Name ==
"sse2.pshuf.d" ||
3063 Name.starts_with(
"avx512.mask.vpermil.p") ||
3064 Name.starts_with(
"avx512.mask.pshuf.d.")) {
3066 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
3067 auto *VecTy = cast<FixedVectorType>(CI->
getType());
3068 unsigned NumElts = VecTy->getNumElements();
3070 unsigned IdxSize = 64 / VecTy->getScalarSizeInBits();
3071 unsigned IdxMask = ((1 << IdxSize) - 1);
3077 for (
unsigned i = 0; i != NumElts; ++i)
3078 Idxs[i] = ((Imm >> ((i * IdxSize) % 8)) & IdxMask) | (i & ~IdxMask);
3085 }
else if (
Name ==
"sse2.pshufl.w" ||
3086 Name.starts_with(
"avx512.mask.pshufl.w.")) {
3088 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
3089 unsigned NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
3092 for (
unsigned l = 0; l != NumElts; l += 8) {
3093 for (
unsigned i = 0; i != 4; ++i)
3094 Idxs[i + l] = ((Imm >> (2 * i)) & 0x3) + l;
3095 for (
unsigned i = 4; i != 8; ++i)
3096 Idxs[i + l] = i + l;
3104 }
else if (
Name ==
"sse2.pshufh.w" ||
3105 Name.starts_with(
"avx512.mask.pshufh.w.")) {
3107 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
3108 unsigned NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
3111 for (
unsigned l = 0; l != NumElts; l += 8) {
3112 for (
unsigned i = 0; i != 4; ++i)
3113 Idxs[i + l] = i + l;
3114 for (
unsigned i = 0; i != 4; ++i)
3115 Idxs[i + l + 4] = ((Imm >> (2 * i)) & 0x3) + 4 + l;
3123 }
else if (
Name.starts_with(
"avx512.mask.shuf.p")) {
3126 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(2))->getZExtValue();
3127 unsigned NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
3130 unsigned HalfLaneElts = NumLaneElts / 2;
3133 for (
unsigned i = 0; i != NumElts; ++i) {
3135 Idxs[i] = i - (i % NumLaneElts);
3137 if ((i % NumLaneElts) >= HalfLaneElts)
3141 Idxs[i] += (Imm >> ((i * HalfLaneElts) % 8)) & ((1 << HalfLaneElts) - 1);
3148 }
else if (
Name.starts_with(
"avx512.mask.movddup") ||
3149 Name.starts_with(
"avx512.mask.movshdup") ||
3150 Name.starts_with(
"avx512.mask.movsldup")) {
3152 unsigned NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
3156 if (
Name.starts_with(
"avx512.mask.movshdup."))
3160 for (
unsigned l = 0; l != NumElts; l += NumLaneElts)
3161 for (
unsigned i = 0; i != NumLaneElts; i += 2) {
3162 Idxs[i + l + 0] = i + l +
Offset;
3163 Idxs[i + l + 1] = i + l +
Offset;
3170 }
else if (
Name.starts_with(
"avx512.mask.punpckl") ||
3171 Name.starts_with(
"avx512.mask.unpckl.")) {
3174 int NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
3178 for (
int l = 0; l != NumElts; l += NumLaneElts)
3179 for (
int i = 0; i != NumLaneElts; ++i)
3180 Idxs[i + l] = l + (i / 2) + NumElts * (i % 2);
3186 }
else if (
Name.starts_with(
"avx512.mask.punpckh") ||
3187 Name.starts_with(
"avx512.mask.unpckh.")) {
3190 int NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
3194 for (
int l = 0; l != NumElts; l += NumLaneElts)
3195 for (
int i = 0; i != NumLaneElts; ++i)
3196 Idxs[i + l] = (NumLaneElts / 2) + l + (i / 2) + NumElts * (i % 2);
3202 }
else if (
Name.starts_with(
"avx512.mask.and.") ||
3203 Name.starts_with(
"avx512.mask.pand.")) {
3205 VectorType *ITy = VectorType::getInteger(FTy);
3211 }
else if (
Name.starts_with(
"avx512.mask.andn.") ||
3212 Name.starts_with(
"avx512.mask.pandn.")) {
3214 VectorType *ITy = VectorType::getInteger(FTy);
3221 }
else if (
Name.starts_with(
"avx512.mask.or.") ||
3222 Name.starts_with(
"avx512.mask.por.")) {
3224 VectorType *ITy = VectorType::getInteger(FTy);
3230 }
else if (
Name.starts_with(
"avx512.mask.xor.") ||
3231 Name.starts_with(
"avx512.mask.pxor.")) {
3233 VectorType *ITy = VectorType::getInteger(FTy);
3239 }
else if (
Name.starts_with(
"avx512.mask.padd.")) {
3243 }
else if (
Name.starts_with(
"avx512.mask.psub.")) {
3247 }
else if (
Name.starts_with(
"avx512.mask.pmull.")) {
3251 }
else if (
Name.starts_with(
"avx512.mask.add.p")) {
3252 if (
Name.ends_with(
".512")) {
3254 if (
Name[17] ==
's')
3255 IID = Intrinsic::x86_avx512_add_ps_512;
3257 IID = Intrinsic::x86_avx512_add_pd_512;
3261 {CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4)});
3267 }
else if (
Name.starts_with(
"avx512.mask.div.p")) {
3268 if (
Name.ends_with(
".512")) {
3270 if (
Name[17] ==
's')
3271 IID = Intrinsic::x86_avx512_div_ps_512;
3273 IID = Intrinsic::x86_avx512_div_pd_512;
3277 {CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4)});
3283 }
else if (
Name.starts_with(
"avx512.mask.mul.p")) {
3284 if (
Name.ends_with(
".512")) {
3286 if (
Name[17] ==
's')
3287 IID = Intrinsic::x86_avx512_mul_ps_512;
3289 IID = Intrinsic::x86_avx512_mul_pd_512;
3293 {CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4)});
3299 }
else if (
Name.starts_with(
"avx512.mask.sub.p")) {
3300 if (
Name.ends_with(
".512")) {
3302 if (
Name[17] ==
's')
3303 IID = Intrinsic::x86_avx512_sub_ps_512;
3305 IID = Intrinsic::x86_avx512_sub_pd_512;
3309 {CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4)});
3315 }
else if ((
Name.starts_with(
"avx512.mask.max.p") ||
3316 Name.starts_with(
"avx512.mask.min.p")) &&
3317 Name.drop_front(18) ==
".512") {
3318 bool IsDouble =
Name[17] ==
'd';
3319 bool IsMin =
Name[13] ==
'i';
3321 {Intrinsic::x86_avx512_max_ps_512, Intrinsic::x86_avx512_max_pd_512},
3322 {Intrinsic::x86_avx512_min_ps_512, Intrinsic::x86_avx512_min_pd_512}};
3327 {CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4)});
3330 }
else if (
Name.starts_with(
"avx512.mask.lzcnt.")) {
3333 F->getParent(), Intrinsic::ctlz, CI->
getType()),
3334 {CI->getArgOperand(0), Builder.getInt1(false)});
3337 }
else if (
Name.starts_with(
"avx512.mask.psll")) {
3338 bool IsImmediate =
Name[16] ==
'i' || (
Name.size() > 18 &&
Name[18] ==
'i');
3339 bool IsVariable =
Name[16] ==
'v';
3346 if (IsVariable &&
Name[17] !=
'.') {
3347 if (
Size ==
'd' &&
Name[17] ==
'2')
3348 IID = Intrinsic::x86_avx2_psllv_q;
3349 else if (
Size ==
'd' &&
Name[17] ==
'4')
3350 IID = Intrinsic::x86_avx2_psllv_q_256;
3351 else if (
Size ==
's' &&
Name[17] ==
'4')
3352 IID = Intrinsic::x86_avx2_psllv_d;
3353 else if (
Size ==
's' &&
Name[17] ==
'8')
3354 IID = Intrinsic::x86_avx2_psllv_d_256;
3355 else if (
Size ==
'h' &&
Name[17] ==
'8')
3356 IID = Intrinsic::x86_avx512_psllv_w_128;
3357 else if (
Size ==
'h' &&
Name[17] ==
'1')
3358 IID = Intrinsic::x86_avx512_psllv_w_256;
3359 else if (
Name[17] ==
'3' &&
Name[18] ==
'2')
3360 IID = Intrinsic::x86_avx512_psllv_w_512;
3363 }
else if (
Name.ends_with(
".128")) {
3365 IID = IsImmediate ? Intrinsic::x86_sse2_pslli_d
3366 : Intrinsic::x86_sse2_psll_d;
3367 else if (
Size ==
'q')
3368 IID = IsImmediate ? Intrinsic::x86_sse2_pslli_q
3369 : Intrinsic::x86_sse2_psll_q;
3370 else if (
Size ==
'w')
3371 IID = IsImmediate ? Intrinsic::x86_sse2_pslli_w
3372 : Intrinsic::x86_sse2_psll_w;
3375 }
else if (
Name.ends_with(
".256")) {
3377 IID = IsImmediate ? Intrinsic::x86_avx2_pslli_d
3378 : Intrinsic::x86_avx2_psll_d;
3379 else if (
Size ==
'q')
3380 IID = IsImmediate ? Intrinsic::x86_avx2_pslli_q
3381 : Intrinsic::x86_avx2_psll_q;
3382 else if (
Size ==
'w')
3383 IID = IsImmediate ? Intrinsic::x86_avx2_pslli_w
3384 : Intrinsic::x86_avx2_psll_w;
3389 IID = IsImmediate ? Intrinsic::x86_avx512_pslli_d_512
3390 : IsVariable ? Intrinsic::x86_avx512_psllv_d_512
3391 : Intrinsic::x86_avx512_psll_d_512;
3392 else if (
Size ==
'q')
3393 IID = IsImmediate ? Intrinsic::x86_avx512_pslli_q_512
3394 : IsVariable ? Intrinsic::x86_avx512_psllv_q_512
3395 : Intrinsic::x86_avx512_psll_q_512;
3396 else if (
Size ==
'w')
3397 IID = IsImmediate ? Intrinsic::x86_avx512_pslli_w_512
3398 : Intrinsic::x86_avx512_psll_w_512;
3404 }
else if (
Name.starts_with(
"avx512.mask.psrl")) {
3405 bool IsImmediate =
Name[16] ==
'i' || (
Name.size() > 18 &&
Name[18] ==
'i');
3406 bool IsVariable =
Name[16] ==
'v';
3413 if (IsVariable &&
Name[17] !=
'.') {
3414 if (
Size ==
'd' &&
Name[17] ==
'2')
3415 IID = Intrinsic::x86_avx2_psrlv_q;
3416 else if (
Size ==
'd' &&
Name[17] ==
'4')
3417 IID = Intrinsic::x86_avx2_psrlv_q_256;
3418 else if (
Size ==
's' &&
Name[17] ==
'4')
3419 IID = Intrinsic::x86_avx2_psrlv_d;
3420 else if (
Size ==
's' &&
Name[17] ==
'8')
3421 IID = Intrinsic::x86_avx2_psrlv_d_256;
3422 else if (
Size ==
'h' &&
Name[17] ==
'8')
3423 IID = Intrinsic::x86_avx512_psrlv_w_128;
3424 else if (
Size ==
'h' &&
Name[17] ==
'1')
3425 IID = Intrinsic::x86_avx512_psrlv_w_256;
3426 else if (
Name[17] ==
'3' &&
Name[18] ==
'2')
3427 IID = Intrinsic::x86_avx512_psrlv_w_512;
3430 }
else if (
Name.ends_with(
".128")) {
3432 IID = IsImmediate ? Intrinsic::x86_sse2_psrli_d
3433 : Intrinsic::x86_sse2_psrl_d;
3434 else if (
Size ==
'q')
3435 IID = IsImmediate ? Intrinsic::x86_sse2_psrli_q
3436 : Intrinsic::x86_sse2_psrl_q;
3437 else if (
Size ==
'w')
3438 IID = IsImmediate ? Intrinsic::x86_sse2_psrli_w
3439 : Intrinsic::x86_sse2_psrl_w;
3442 }
else if (
Name.ends_with(
".256")) {
3444 IID = IsImmediate ? Intrinsic::x86_avx2_psrli_d
3445 : Intrinsic::x86_avx2_psrl_d;
3446 else if (
Size ==
'q')
3447 IID = IsImmediate ? Intrinsic::x86_avx2_psrli_q
3448 : Intrinsic::x86_avx2_psrl_q;
3449 else if (
Size ==
'w')
3450 IID = IsImmediate ? Intrinsic::x86_avx2_psrli_w
3451 : Intrinsic::x86_avx2_psrl_w;
3456 IID = IsImmediate ? Intrinsic::x86_avx512_psrli_d_512
3457 : IsVariable ? Intrinsic::x86_avx512_psrlv_d_512
3458 : Intrinsic::x86_avx512_psrl_d_512;
3459 else if (
Size ==
'q')
3460 IID = IsImmediate ? Intrinsic::x86_avx512_psrli_q_512
3461 : IsVariable ? Intrinsic::x86_avx512_psrlv_q_512
3462 : Intrinsic::x86_avx512_psrl_q_512;
3463 else if (
Size ==
'w')
3464 IID = IsImmediate ? Intrinsic::x86_avx512_psrli_w_512
3465 : Intrinsic::x86_avx512_psrl_w_512;
3471 }
else if (
Name.starts_with(
"avx512.mask.psra")) {
3472 bool IsImmediate =
Name[16] ==
'i' || (
Name.size() > 18 &&
Name[18] ==
'i');
3473 bool IsVariable =
Name[16] ==
'v';
3480 if (IsVariable &&
Name[17] !=
'.') {
3481 if (
Size ==
's' &&
Name[17] ==
'4')
3482 IID = Intrinsic::x86_avx2_psrav_d;
3483 else if (
Size ==
's' &&
Name[17] ==
'8')
3484 IID = Intrinsic::x86_avx2_psrav_d_256;
3485 else if (
Size ==
'h' &&
Name[17] ==
'8')
3486 IID = Intrinsic::x86_avx512_psrav_w_128;
3487 else if (
Size ==
'h' &&
Name[17] ==
'1')
3488 IID = Intrinsic::x86_avx512_psrav_w_256;
3489 else if (
Name[17] ==
'3' &&
Name[18] ==
'2')
3490 IID = Intrinsic::x86_avx512_psrav_w_512;
3493 }
else if (
Name.ends_with(
".128")) {
3495 IID = IsImmediate ? Intrinsic::x86_sse2_psrai_d
3496 : Intrinsic::x86_sse2_psra_d;
3497 else if (
Size ==
'q')
3498 IID = IsImmediate ? Intrinsic::x86_avx512_psrai_q_128
3499 : IsVariable ? Intrinsic::x86_avx512_psrav_q_128
3500 : Intrinsic::x86_avx512_psra_q_128;
3501 else if (
Size ==
'w')
3502 IID = IsImmediate ? Intrinsic::x86_sse2_psrai_w
3503 : Intrinsic::x86_sse2_psra_w;
3506 }
else if (
Name.ends_with(
".256")) {
3508 IID = IsImmediate ? Intrinsic::x86_avx2_psrai_d
3509 : Intrinsic::x86_avx2_psra_d;
3510 else if (
Size ==
'q')
3511 IID = IsImmediate ? Intrinsic::x86_avx512_psrai_q_256
3512 : IsVariable ? Intrinsic::x86_avx512_psrav_q_256
3513 : Intrinsic::x86_avx512_psra_q_256;
3514 else if (
Size ==
'w')
3515 IID = IsImmediate ? Intrinsic::x86_avx2_psrai_w
3516 : Intrinsic::x86_avx2_psra_w;
3521 IID = IsImmediate ? Intrinsic::x86_avx512_psrai_d_512
3522 : IsVariable ? Intrinsic::x86_avx512_psrav_d_512
3523 : Intrinsic::x86_avx512_psra_d_512;
3524 else if (
Size ==
'q')
3525 IID = IsImmediate ? Intrinsic::x86_avx512_psrai_q_512
3526 : IsVariable ? Intrinsic::x86_avx512_psrav_q_512
3527 : Intrinsic::x86_avx512_psra_q_512;
3528 else if (
Size ==
'w')
3529 IID = IsImmediate ? Intrinsic::x86_avx512_psrai_w_512
3530 : Intrinsic::x86_avx512_psra_w_512;
3536 }
else if (
Name.starts_with(
"avx512.mask.move.s")) {
3538 }
else if (
Name.starts_with(
"avx512.cvtmask2")) {
3540 }
else if (
Name.ends_with(
".movntdqa")) {
3548 Ptr, PointerType::getUnqual(CI->
getType()),
"cast");
3554 }
else if (
Name.starts_with(
"fma.vfmadd.") ||
3555 Name.starts_with(
"fma.vfmsub.") ||
3556 Name.starts_with(
"fma.vfnmadd.") ||
3557 Name.starts_with(
"fma.vfnmsub.")) {
3558 bool NegMul =
Name[6] ==
'n';
3559 bool NegAcc = NegMul ?
Name[8] ==
's' :
Name[7] ==
's';
3560 bool IsScalar = NegMul ?
Name[12] ==
's' :
Name[11] ==
's';
3571 if (NegMul && !IsScalar)
3573 if (NegMul && IsScalar)
3585 }
else if (
Name.starts_with(
"fma4.vfmadd.s")) {
3600 }
else if (
Name.starts_with(
"avx512.mask.vfmadd.s") ||
3601 Name.starts_with(
"avx512.maskz.vfmadd.s") ||
3602 Name.starts_with(
"avx512.mask3.vfmadd.s") ||
3603 Name.starts_with(
"avx512.mask3.vfmsub.s") ||
3604 Name.starts_with(
"avx512.mask3.vfnmsub.s")) {
3605 bool IsMask3 =
Name[11] ==
'3';
3606 bool IsMaskZ =
Name[11] ==
'z';
3608 Name =
Name.drop_front(IsMask3 || IsMaskZ ? 13 : 12);
3609 bool NegMul =
Name[2] ==
'n';
3610 bool NegAcc = NegMul ?
Name[4] ==
's' :
Name[3] ==
's';
3616 if (NegMul && (IsMask3 || IsMaskZ))
3618 if (NegMul && !(IsMask3 || IsMaskZ))
3628 cast<ConstantInt>(CI->
getArgOperand(4))->getZExtValue() != 4) {
3632 if (
Name.back() ==
'd')
3633 IID = Intrinsic::x86_avx512_vfmadd_f64;
3635 IID = Intrinsic::x86_avx512_vfmadd_f32;
3650 if (NegAcc && IsMask3)
3657 }
else if (
Name.starts_with(
"avx512.mask.vfmadd.p") ||
3658 Name.starts_with(
"avx512.mask.vfnmadd.p") ||
3659 Name.starts_with(
"avx512.mask.vfnmsub.p") ||
3660 Name.starts_with(
"avx512.mask3.vfmadd.p") ||
3661 Name.starts_with(
"avx512.mask3.vfmsub.p") ||
3662 Name.starts_with(
"avx512.mask3.vfnmsub.p") ||
3663 Name.starts_with(
"avx512.maskz.vfmadd.p")) {
3664 bool IsMask3 =
Name[11] ==
'3';
3665 bool IsMaskZ =
Name[11] ==
'z';
3667 Name =
Name.drop_front(IsMask3 || IsMaskZ ? 13 : 12);
3668 bool NegMul =
Name[2] ==
'n';
3669 bool NegAcc = NegMul ?
Name[4] ==
's' :
Name[3] ==
's';
3675 if (NegMul && (IsMask3 || IsMaskZ))
3677 if (NegMul && !(IsMask3 || IsMaskZ))
3684 cast<ConstantInt>(CI->
getArgOperand(4))->getZExtValue() != 4)) {
3688 IID = Intrinsic::x86_avx512_vfmadd_ps_512;
3690 IID = Intrinsic::x86_avx512_vfmadd_pd_512;
3693 {A, B, C, CI->getArgOperand(4)});
3705 }
else if (
Name.starts_with(
"fma.vfmsubadd.p")) {
3709 if (VecWidth == 128 && EltWidth == 32)
3710 IID = Intrinsic::x86_fma_vfmaddsub_ps;
3711 else if (VecWidth == 256 && EltWidth == 32)
3712 IID = Intrinsic::x86_fma_vfmaddsub_ps_256;
3713 else if (VecWidth == 128 && EltWidth == 64)
3714 IID = Intrinsic::x86_fma_vfmaddsub_pd;
3715 else if (VecWidth == 256 && EltWidth == 64)
3716 IID = Intrinsic::x86_fma_vfmaddsub_pd_256;
3725 }
else if (
Name.starts_with(
"avx512.mask.vfmaddsub.p") ||
3726 Name.starts_with(
"avx512.mask3.vfmaddsub.p") ||
3727 Name.starts_with(
"avx512.maskz.vfmaddsub.p") ||
3728 Name.starts_with(
"avx512.mask3.vfmsubadd.p")) {
3729 bool IsMask3 =
Name[11] ==
'3';
3730 bool IsMaskZ =
Name[11] ==
'z';
3732 Name =
Name.drop_front(IsMask3 || IsMaskZ ? 13 : 12);
3733 bool IsSubAdd =
Name[3] ==
's';
3738 IID = Intrinsic::x86_avx512_vfmaddsub_ps_512;
3740 IID = Intrinsic::x86_avx512_vfmaddsub_pd_512;
3750 int NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
3765 for (
int i = 0; i != NumElts; ++i)
3766 Idxs[i] = i + (i % 2) * NumElts;
3776 }
else if (
Name.starts_with(
"avx512.mask.pternlog.") ||
3777 Name.starts_with(
"avx512.maskz.pternlog.")) {
3778 bool ZeroMask =
Name[11] ==
'z';
3782 if (VecWidth == 128 && EltWidth == 32)
3783 IID = Intrinsic::x86_avx512_pternlog_d_128;
3784 else if (VecWidth == 256 && EltWidth == 32)
3785 IID = Intrinsic::x86_avx512_pternlog_d_256;
3786 else if (VecWidth == 512 && EltWidth == 32)
3787 IID = Intrinsic::x86_avx512_pternlog_d_512;
3788 else if (VecWidth == 128 && EltWidth == 64)
3789 IID = Intrinsic::x86_avx512_pternlog_q_128;
3790 else if (VecWidth == 256 && EltWidth == 64)
3791 IID = Intrinsic::x86_avx512_pternlog_q_256;
3792 else if (VecWidth == 512 && EltWidth == 64)
3793 IID = Intrinsic::x86_avx512_pternlog_q_512;
3804 }
else if (
Name.starts_with(
"avx512.mask.vpmadd52") ||
3805 Name.starts_with(
"avx512.maskz.vpmadd52")) {
3806 bool ZeroMask =
Name[11] ==
'z';
3810 if (VecWidth == 128 && !
High)
3811 IID = Intrinsic::x86_avx512_vpmadd52l_uq_128;
3812 else if (VecWidth == 256 && !
High)
3813 IID = Intrinsic::x86_avx512_vpmadd52l_uq_256;
3814 else if (VecWidth == 512 && !
High)
3815 IID = Intrinsic::x86_avx512_vpmadd52l_uq_512;
3816 else if (VecWidth == 128 &&
High)
3817 IID = Intrinsic::x86_avx512_vpmadd52h_uq_128;
3818 else if (VecWidth == 256 &&
High)
3819 IID = Intrinsic::x86_avx512_vpmadd52h_uq_256;
3820 else if (VecWidth == 512 &&
High)
3821 IID = Intrinsic::x86_avx512_vpmadd52h_uq_512;
3832 }
else if (
Name.starts_with(
"avx512.mask.vpermi2var.") ||
3833 Name.starts_with(
"avx512.mask.vpermt2var.") ||
3834 Name.starts_with(
"avx512.maskz.vpermt2var.")) {
3835 bool ZeroMask =
Name[11] ==
'z';
3836 bool IndexForm =
Name[17] ==
'i';
3838 }
else if (
Name.starts_with(
"avx512.mask.vpdpbusd.") ||
3839 Name.starts_with(
"avx512.maskz.vpdpbusd.") ||
3840 Name.starts_with(
"avx512.mask.vpdpbusds.") ||
3841 Name.starts_with(
"avx512.maskz.vpdpbusds.")) {
3842 bool ZeroMask =
Name[11] ==
'z';
3843 bool IsSaturating =
Name[ZeroMask ? 21 : 20] ==
's';
3846 if (VecWidth == 128 && !IsSaturating)
3847 IID = Intrinsic::x86_avx512_vpdpbusd_128;
3848 else if (VecWidth == 256 && !IsSaturating)
3849 IID = Intrinsic::x86_avx512_vpdpbusd_256;
3850 else if (VecWidth == 512 && !IsSaturating)
3851 IID = Intrinsic::x86_avx512_vpdpbusd_512;
3852 else if (VecWidth == 128 && IsSaturating)
3853 IID = Intrinsic::x86_avx512_vpdpbusds_128;
3854 else if (VecWidth == 256 && IsSaturating)
3855 IID = Intrinsic::x86_avx512_vpdpbusds_256;
3856 else if (VecWidth == 512 && IsSaturating)
3857 IID = Intrinsic::x86_avx512_vpdpbusds_512;
3868 }
else if (
Name.starts_with(
"avx512.mask.vpdpwssd.") ||
3869 Name.starts_with(
"avx512.maskz.vpdpwssd.") ||
3870 Name.starts_with(
"avx512.mask.vpdpwssds.") ||
3871 Name.starts_with(
"avx512.maskz.vpdpwssds.")) {
3872 bool ZeroMask =
Name[11] ==
'z';
3873 bool IsSaturating =
Name[ZeroMask ? 21 : 20] ==
's';
3876 if (VecWidth == 128 && !IsSaturating)
3877 IID = Intrinsic::x86_avx512_vpdpwssd_128;
3878 else if (VecWidth == 256 && !IsSaturating)
3879 IID = Intrinsic::x86_avx512_vpdpwssd_256;
3880 else if (VecWidth == 512 && !IsSaturating)
3881 IID = Intrinsic::x86_avx512_vpdpwssd_512;
3882 else if (VecWidth == 128 && IsSaturating)
3883 IID = Intrinsic::x86_avx512_vpdpwssds_128;
3884 else if (VecWidth == 256 && IsSaturating)
3885 IID = Intrinsic::x86_avx512_vpdpwssds_256;
3886 else if (VecWidth == 512 && IsSaturating)
3887 IID = Intrinsic::x86_avx512_vpdpwssds_512;
3898 }
else if (
Name ==
"addcarryx.u32" ||
Name ==
"addcarryx.u64" ||
3899 Name ==
"addcarry.u32" ||
Name ==
"addcarry.u64" ||
3900 Name ==
"subborrow.u32" ||
Name ==
"subborrow.u64") {
3902 if (
Name[0] ==
'a' &&
Name.back() ==
'2')
3903 IID = Intrinsic::x86_addcarry_32;
3904 else if (
Name[0] ==
'a' &&
Name.back() ==
'4')
3905 IID = Intrinsic::x86_addcarry_64;
3906 else if (
Name[0] ==
's' &&
Name.back() ==
'2')
3907 IID = Intrinsic::x86_subborrow_32;
3908 else if (
Name[0] ==
's' &&
Name.back() ==
'4')
3909 IID = Intrinsic::x86_subborrow_64;
3930 }
else if (
Name.starts_with(
"avx512.mask.") &&
3940 if (
Name ==
"mve.vctp64.old") {
3948 F->getParent(), Intrinsic::arm_mve_pred_v2i,
3949 {VectorType::get(Builder.getInt1Ty(), 2, false)}),
3953 F->getParent(), Intrinsic::arm_mve_pred_i2v,
3954 {VectorType::get(Builder.getInt1Ty(), 4, false)}),
3956 }
else if (
Name ==
"mve.mull.int.predicated.v2i64.v4i32.v4i1" ||
3957 Name ==
"mve.vqdmull.predicated.v2i64.v4i32.v4i1" ||
3958 Name ==
"mve.vldr.gather.base.predicated.v2i64.v2i64.v4i1" ||
3959 Name ==
"mve.vldr.gather.base.wb.predicated.v2i64.v2i64.v4i1" ||
3961 "mve.vldr.gather.offset.predicated.v2i64.p0i64.v2i64.v4i1" ||
3962 Name ==
"mve.vldr.gather.offset.predicated.v2i64.p0.v2i64.v4i1" ||
3963 Name ==
"mve.vstr.scatter.base.predicated.v2i64.v2i64.v4i1" ||
3964 Name ==
"mve.vstr.scatter.base.wb.predicated.v2i64.v2i64.v4i1" ||
3966 "mve.vstr.scatter.offset.predicated.p0i64.v2i64.v2i64.v4i1" ||
3967 Name ==
"mve.vstr.scatter.offset.predicated.p0.v2i64.v2i64.v4i1" ||
3968 Name ==
"cde.vcx1q.predicated.v2i64.v4i1" ||
3969 Name ==
"cde.vcx1qa.predicated.v2i64.v4i1" ||
3970 Name ==
"cde.vcx2q.predicated.v2i64.v4i1" ||
3971 Name ==
"cde.vcx2qa.predicated.v2i64.v4i1" ||
3972 Name ==
"cde.vcx3q.predicated.v2i64.v4i1" ||
3973 Name ==
"cde.vcx3qa.predicated.v2i64.v4i1") {
3974 std::vector<Type *> Tys;
3978 case Intrinsic::arm_mve_mull_int_predicated:
3979 case Intrinsic::arm_mve_vqdmull_predicated:
3980 case Intrinsic::arm_mve_vldr_gather_base_predicated:
3983 case Intrinsic::arm_mve_vldr_gather_base_wb_predicated:
3984 case Intrinsic::arm_mve_vstr_scatter_base_predicated:
3985 case Intrinsic::arm_mve_vstr_scatter_base_wb_predicated:
3989 case Intrinsic::arm_mve_vldr_gather_offset_predicated:
3993 case Intrinsic::arm_mve_vstr_scatter_offset_predicated:
3997 case Intrinsic::arm_cde_vcx1q_predicated:
3998 case Intrinsic::arm_cde_vcx1qa_predicated:
3999 case Intrinsic::arm_cde_vcx2q_predicated:
4000 case Intrinsic::arm_cde_vcx2qa_predicated:
4001 case Intrinsic::arm_cde_vcx3q_predicated:
4002 case Intrinsic::arm_cde_vcx3qa_predicated:
4009 std::vector<Value *> Ops;
4011 Type *Ty =
Op->getType();
4015 F->getParent(), Intrinsic::arm_mve_pred_v2i,
4016 {VectorType::get(Builder.getInt1Ty(), 4, false)}),
4020 Intrinsic::arm_mve_pred_i2v, {V2I1Ty}),
4048 if (NumOperands < 3)
4061 bool IsVolatile =
false;
4065 if (NumOperands > 3)
4070 if (NumOperands > 5) {
4072 IsVolatile = !VolatileArg || !VolatileArg->
isZero();
4078 if (Order == AtomicOrdering::NotAtomic || Order == AtomicOrdering::Unordered)
4079 Order = AtomicOrdering::SequentiallyConsistent;
4086 if (VT->getElementType()->isIntegerTy(16)) {
4099 if (PtrTy->getAddressSpace() != 3) {
4111template <
typename MDType>
4114 return dyn_cast<MDType>(MAV->getMetadata());
4123 if (
Name ==
"label") {
4125 }
else if (
Name ==
"assign") {
4127 unwrapMAVOp<Metadata>(CI, 0), unwrapMAVOp<DILocalVariable>(CI, 1),
4128 unwrapMAVOp<DIExpression>(CI, 2), unwrapMAVOp<DIAssignID>(CI, 3),
4129 unwrapMAVOp<Metadata>(CI, 4), unwrapMAVOp<DIExpression>(CI, 5),
4131 }
else if (
Name ==
"declare") {
4133 unwrapMAVOp<Metadata>(CI, 0), unwrapMAVOp<DILocalVariable>(CI, 1),
4134 unwrapMAVOp<DIExpression>(CI, 2), CI->
getDebugLoc(),
4135 DbgVariableRecord::LocationType::Declare);
4136 }
else if (
Name ==
"addr") {
4141 unwrapMAVOp<DILocalVariable>(CI, 1), Expr,
4143 }
else if (
Name ==
"value") {
4146 unsigned ExprOp = 2;
4156 unwrapMAVOp<Metadata>(CI, 0), unwrapMAVOp<DILocalVariable>(CI, VarOp),
4157 unwrapMAVOp<DIExpression>(CI, ExprOp), CI->
getDebugLoc());
4159 assert(DR &&
"Unhandled intrinsic kind in upgrade to DbgRecord");