@@ -486,10 +486,8 @@ static bool ShouldUpgradeX86Intrinsic(Function *F, StringRef Name) {
486
486
static bool UpgradeX86IntrinsicFunction (Function *F, StringRef Name,
487
487
Function *&NewFn) {
488
488
// Only handle intrinsics that start with "x86.".
489
- if (!Name.starts_with (" x86." ))
489
+ if (!Name.consume_front (" x86." ))
490
490
return false ;
491
- // Remove "x86." prefix.
492
- Name = Name.substr (4 );
493
491
494
492
if (ShouldUpgradeX86Intrinsic (F, Name)) {
495
493
NewFn = nullptr ;
@@ -507,113 +505,112 @@ static bool UpgradeX86IntrinsicFunction(Function *F, StringRef Name,
507
505
return true ;
508
506
}
509
507
508
+ Intrinsic::ID ID;
509
+
510
510
// SSE4.1 ptest functions may have an old signature.
511
- if (Name.starts_with (" sse41.ptest" )) { // Added in 3.2
512
- if (Name.substr (11 ) == " c" )
513
- return UpgradePTESTIntrinsic (F, Intrinsic::x86_sse41_ptestc, NewFn);
514
- if (Name.substr (11 ) == " z" )
515
- return UpgradePTESTIntrinsic (F, Intrinsic::x86_sse41_ptestz, NewFn);
516
- if (Name.substr (11 ) == " nzc" )
517
- return UpgradePTESTIntrinsic (F, Intrinsic::x86_sse41_ptestnzc, NewFn);
511
+ if (Name.consume_front (" sse41.ptest" )) { // Added in 3.2
512
+ ID = StringSwitch<Intrinsic::ID>(Name)
513
+ .Case (" c" , Intrinsic::x86_sse41_ptestc)
514
+ .Case (" z" , Intrinsic::x86_sse41_ptestz)
515
+ .Case (" nzc" , Intrinsic::x86_sse41_ptestnzc)
516
+ .Default (Intrinsic::not_intrinsic);
517
+ if (ID != Intrinsic::not_intrinsic)
518
+ return UpgradePTESTIntrinsic (F, ID, NewFn);
519
+
520
+ return false ;
518
521
}
522
+
519
523
// Several blend and other instructions with masks used the wrong number of
520
524
// bits.
521
- if (Name == " sse41.insertps" ) // Added in 3.6
522
- return UpgradeX86IntrinsicsWith8BitMask (F, Intrinsic::x86_sse41_insertps,
523
- NewFn);
524
- if (Name == " sse41.dppd" ) // Added in 3.6
525
- return UpgradeX86IntrinsicsWith8BitMask (F, Intrinsic::x86_sse41_dppd,
526
- NewFn);
527
- if (Name == " sse41.dpps" ) // Added in 3.6
528
- return UpgradeX86IntrinsicsWith8BitMask (F, Intrinsic::x86_sse41_dpps,
529
- NewFn);
530
- if (Name == " sse41.mpsadbw" ) // Added in 3.6
531
- return UpgradeX86IntrinsicsWith8BitMask (F, Intrinsic::x86_sse41_mpsadbw,
532
- NewFn);
533
- if (Name == " avx.dp.ps.256" ) // Added in 3.6
534
- return UpgradeX86IntrinsicsWith8BitMask (F, Intrinsic::x86_avx_dp_ps_256,
535
- NewFn);
536
- if (Name == " avx2.mpsadbw" ) // Added in 3.6
537
- return UpgradeX86IntrinsicsWith8BitMask (F, Intrinsic::x86_avx2_mpsadbw,
538
- NewFn);
539
- if (Name == " avx512.mask.cmp.pd.128" ) // Added in 7.0
540
- return UpgradeX86MaskedFPCompare (F, Intrinsic::x86_avx512_mask_cmp_pd_128,
541
- NewFn);
542
- if (Name == " avx512.mask.cmp.pd.256" ) // Added in 7.0
543
- return UpgradeX86MaskedFPCompare (F, Intrinsic::x86_avx512_mask_cmp_pd_256,
544
- NewFn);
545
- if (Name == " avx512.mask.cmp.pd.512" ) // Added in 7.0
546
- return UpgradeX86MaskedFPCompare (F, Intrinsic::x86_avx512_mask_cmp_pd_512,
547
- NewFn);
548
- if (Name == " avx512.mask.cmp.ps.128" ) // Added in 7.0
549
- return UpgradeX86MaskedFPCompare (F, Intrinsic::x86_avx512_mask_cmp_ps_128,
550
- NewFn);
551
- if (Name == " avx512.mask.cmp.ps.256" ) // Added in 7.0
552
- return UpgradeX86MaskedFPCompare (F, Intrinsic::x86_avx512_mask_cmp_ps_256,
553
- NewFn);
554
- if (Name == " avx512.mask.cmp.ps.512" ) // Added in 7.0
555
- return UpgradeX86MaskedFPCompare (F, Intrinsic::x86_avx512_mask_cmp_ps_512,
556
- NewFn);
557
- if (Name == " avx512bf16.cvtne2ps2bf16.128" ) // Added in 9.0
558
- return UpgradeX86BF16Intrinsic (
559
- F, Intrinsic::x86_avx512bf16_cvtne2ps2bf16_128, NewFn);
560
- if (Name == " avx512bf16.cvtne2ps2bf16.256" ) // Added in 9.0
561
- return UpgradeX86BF16Intrinsic (
562
- F, Intrinsic::x86_avx512bf16_cvtne2ps2bf16_256, NewFn);
563
- if (Name == " avx512bf16.cvtne2ps2bf16.512" ) // Added in 9.0
564
- return UpgradeX86BF16Intrinsic (
565
- F, Intrinsic::x86_avx512bf16_cvtne2ps2bf16_512, NewFn);
566
- if (Name == " avx512bf16.mask.cvtneps2bf16.128" ) // Added in 9.0
567
- return UpgradeX86BF16Intrinsic (
568
- F, Intrinsic::x86_avx512bf16_mask_cvtneps2bf16_128, NewFn);
569
- if (Name == " avx512bf16.cvtneps2bf16.256" ) // Added in 9.0
570
- return UpgradeX86BF16Intrinsic (
571
- F, Intrinsic::x86_avx512bf16_cvtneps2bf16_256, NewFn);
572
- if (Name == " avx512bf16.cvtneps2bf16.512" ) // Added in 9.0
573
- return UpgradeX86BF16Intrinsic (
574
- F, Intrinsic::x86_avx512bf16_cvtneps2bf16_512, NewFn);
575
- if (Name == " avx512bf16.dpbf16ps.128" ) // Added in 9.0
576
- return UpgradeX86BF16DPIntrinsic (
577
- F, Intrinsic::x86_avx512bf16_dpbf16ps_128, NewFn);
578
- if (Name == " avx512bf16.dpbf16ps.256" ) // Added in 9.0
579
- return UpgradeX86BF16DPIntrinsic (
580
- F, Intrinsic::x86_avx512bf16_dpbf16ps_256, NewFn);
581
- if (Name == " avx512bf16.dpbf16ps.512" ) // Added in 9.0
582
- return UpgradeX86BF16DPIntrinsic (
583
- F, Intrinsic::x86_avx512bf16_dpbf16ps_512, NewFn);
584
-
585
- // frcz.ss/sd may need to have an argument dropped. Added in 3.2
586
- if (Name.starts_with (" xop.vfrcz.ss" ) && F->arg_size () == 2 ) {
587
- rename (F);
588
- NewFn = Intrinsic::getDeclaration (F->getParent (),
589
- Intrinsic::x86_xop_vfrcz_ss);
590
- return true ;
525
+
526
+ // Added in 3.6
527
+ ID = StringSwitch<Intrinsic::ID>(Name)
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)
534
+ .Default (Intrinsic::not_intrinsic);
535
+ if (ID != Intrinsic::not_intrinsic)
536
+ return UpgradeX86IntrinsicsWith8BitMask (F, ID, NewFn);
537
+
538
+ if (Name.consume_front (" avx512.mask.cmp." )) {
539
+ // Added in 7.0
540
+ ID = StringSwitch<Intrinsic::ID>(Name)
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)
547
+ .Default (Intrinsic::not_intrinsic);
548
+ if (ID != Intrinsic::not_intrinsic)
549
+ return UpgradeX86MaskedFPCompare (F, ID, NewFn);
550
+ return false ; // No other 'x86.avx523.mask.cmp.*'.
591
551
}
592
- if (Name.starts_with (" xop.vfrcz.sd" ) && F->arg_size () == 2 ) {
593
- rename (F);
594
- NewFn = Intrinsic::getDeclaration (F->getParent (),
595
- Intrinsic::x86_xop_vfrcz_sd);
596
- return true ;
552
+
553
+ if (Name.consume_front (" avx512bf16." )) {
554
+ // Added in 9.0
555
+ ID = StringSwitch<Intrinsic::ID>(Name)
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)
568
+ .Default (Intrinsic::not_intrinsic);
569
+ if (ID != Intrinsic::not_intrinsic)
570
+ return UpgradeX86BF16Intrinsic (F, ID, NewFn);
571
+
572
+ // Added in 9.0
573
+ ID = StringSwitch<Intrinsic::ID>(Name)
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)
577
+ .Default (Intrinsic::not_intrinsic);
578
+ if (ID != Intrinsic::not_intrinsic)
579
+ return UpgradeX86BF16DPIntrinsic (F, ID, NewFn);
580
+ return false ; // No other 'x86.avx512bf16.*'.
597
581
}
598
- // Upgrade any XOP PERMIL2 index operand still using a float/double vector.
599
- if (Name.starts_with (" xop.vpermil2" )) { // Added in 3.9
600
- auto Idx = F->getFunctionType ()->getParamType (2 );
601
- if (Idx->isFPOrFPVectorTy ()) {
582
+
583
+ if (Name.consume_front (" xop." )) {
584
+ Intrinsic::ID ID = Intrinsic::not_intrinsic;
585
+ if (Name.startswith (" vpermil2" )) { // Added in 3.9
586
+ // Upgrade any XOP PERMIL2 index operand still using a float/double
587
+ // vector.
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;
598
+ else
599
+ ID = Intrinsic::x86_xop_vpermil2ps_256;
600
+ }
601
+ } else if (F->arg_size () == 2 )
602
+ // frcz.ss/sd may need to have an argument dropped. Added in 3.2
603
+ ID = StringSwitch<Intrinsic::ID>(Name)
604
+ .Case (" vfrcz.ss" , Intrinsic::x86_xop_vfrcz_ss)
605
+ .Case (" vfrcz.sd" , Intrinsic::x86_xop_vfrcz_sd)
606
+ .Default (Intrinsic::not_intrinsic);
607
+
608
+ if (ID != Intrinsic::not_intrinsic) {
602
609
rename (F);
603
- unsigned IdxSize = Idx->getPrimitiveSizeInBits ();
604
- unsigned EltSize = Idx->getScalarSizeInBits ();
605
- Intrinsic::ID Permil2ID;
606
- if (EltSize == 64 && IdxSize == 128 )
607
- Permil2ID = Intrinsic::x86_xop_vpermil2pd;
608
- else if (EltSize == 32 && IdxSize == 128 )
609
- Permil2ID = Intrinsic::x86_xop_vpermil2ps;
610
- else if (EltSize == 64 && IdxSize == 256 )
611
- Permil2ID = Intrinsic::x86_xop_vpermil2pd_256;
612
- else
613
- Permil2ID = Intrinsic::x86_xop_vpermil2ps_256;
614
- NewFn = Intrinsic::getDeclaration (F->getParent (), Permil2ID);
610
+ NewFn = Intrinsic::getDeclaration (F->getParent (), ID);
615
611
return true ;
616
612
}
613
+ return false ; // No other 'x86.xop.*'
617
614
}
618
615
619
616
if (Name == " seh.recoverfp" ) {
0 commit comments