Skip to content

Commit 97f8231

Browse files
committed
Add auto-upgrade to support intrinsics with old signatures. Added
upgrade tests.
1 parent 685ef89 commit 97f8231

File tree

3 files changed

+144
-22
lines changed

3 files changed

+144
-22
lines changed

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,24 @@ static bool upgradeX86MaskedFPCompare(Function *F, Intrinsic::ID IID,
107107
return true;
108108
}
109109

110+
// Upgrade the declaration of multiply and add bytes intrinsics whose input
111+
// arguments' types have changed from vectors of i32 to vectors of i8
112+
static bool upgradeX86MultiplyAddBytes(Function *F, Intrinsic::ID IID,
113+
Function *&NewFn) {
114+
// check if input argument type is a vector of i8
115+
Type *Arg1Type = F->getFunctionType()->getParamType(1);
116+
Type *Arg2Type = F->getFunctionType()->getParamType(2);
117+
if (Arg1Type->isVectorTy() &&
118+
cast<VectorType>(Arg1Type)->getElementType()->isIntegerTy(8) &&
119+
Arg2Type->isVectorTy() &&
120+
cast<VectorType>(Arg2Type)->getElementType()->isIntegerTy(8))
121+
return false;
122+
123+
rename(F);
124+
NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), IID);
125+
return true;
126+
}
127+
110128
static bool upgradeX86BF16Intrinsic(Function *F, Intrinsic::ID IID,
111129
Function *&NewFn) {
112130
if (F->getReturnType()->getScalarType()->isBFloatTy())
@@ -546,19 +564,37 @@ static bool upgradeX86IntrinsicFunction(Function *F, StringRef Name,
546564
if (ID != Intrinsic::not_intrinsic)
547565
return upgradeX86IntrinsicsWith8BitMask(F, ID, NewFn);
548566

567+
if (Name.consume_front("avx512.")) {
568+
if (Name.consume_front("mask.cmp.")) {
569+
// Added in 7.0
570+
ID = StringSwitch<Intrinsic::ID>(Name)
571+
.Case("pd.128", Intrinsic::x86_avx512_mask_cmp_pd_128)
572+
.Case("pd.256", Intrinsic::x86_avx512_mask_cmp_pd_256)
573+
.Case("pd.512", Intrinsic::x86_avx512_mask_cmp_pd_512)
574+
.Case("ps.128", Intrinsic::x86_avx512_mask_cmp_ps_128)
575+
.Case("ps.256", Intrinsic::x86_avx512_mask_cmp_ps_256)
576+
.Case("ps.512", Intrinsic::x86_avx512_mask_cmp_ps_512)
577+
.Default(Intrinsic::not_intrinsic);
578+
if (ID != Intrinsic::not_intrinsic)
579+
return upgradeX86MaskedFPCompare(F, ID, NewFn);
580+
} else if (Name.starts_with("vpdpbusd.") ||
581+
Name.starts_with("vpdpbusds.")) {
582+
// Added in 21.1
583+
ID = StringSwitch<Intrinsic::ID>(Name)
584+
.Case("vpdpbusd.128", Intrinsic::x86_avx512_vpdpbusd_128)
585+
.Case("vpdpbusd.256", Intrinsic::x86_avx512_vpdpbusd_256)
586+
.Case("vpdpbusd.512", Intrinsic::x86_avx512_vpdpbusd_512)
587+
.Case("vpdpbusds.128", Intrinsic::x86_avx512_vpdpbusds_128)
588+
.Case("vpdpbusds.256", Intrinsic::x86_avx512_vpdpbusds_256)
589+
.Case("vpdpbusds.512", Intrinsic::x86_avx512_vpdpbusds_512)
590+
.Default(Intrinsic::not_intrinsic);
591+
if (ID != Intrinsic::not_intrinsic)
592+
return upgradeX86MultiplyAddBytes(F, ID, NewFn);
593+
}
594+
return false; // No other 'x86.avx512.*'.
595+
}
596+
549597
if (Name.consume_front("avx512.mask.cmp.")) {
550-
// Added in 7.0
551-
ID = StringSwitch<Intrinsic::ID>(Name)
552-
.Case("pd.128", Intrinsic::x86_avx512_mask_cmp_pd_128)
553-
.Case("pd.256", Intrinsic::x86_avx512_mask_cmp_pd_256)
554-
.Case("pd.512", Intrinsic::x86_avx512_mask_cmp_pd_512)
555-
.Case("ps.128", Intrinsic::x86_avx512_mask_cmp_ps_128)
556-
.Case("ps.256", Intrinsic::x86_avx512_mask_cmp_ps_256)
557-
.Case("ps.512", Intrinsic::x86_avx512_mask_cmp_ps_512)
558-
.Default(Intrinsic::not_intrinsic);
559-
if (ID != Intrinsic::not_intrinsic)
560-
return upgradeX86MaskedFPCompare(F, ID, NewFn);
561-
return false; // No other 'x86.avx523.mask.cmp.*'.
562598
}
563599

564600
if (Name.consume_front("avx512bf16.")) {
@@ -5184,6 +5220,23 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
51845220
CI->eraseFromParent();
51855221
return;
51865222
}
5223+
5224+
case Intrinsic::x86_avx512_vpdpbusd_128:
5225+
case Intrinsic::x86_avx512_vpdpbusd_256:
5226+
case Intrinsic::x86_avx512_vpdpbusd_512:
5227+
case Intrinsic::x86_avx512_vpdpbusds_128:
5228+
case Intrinsic::x86_avx512_vpdpbusds_256:
5229+
case Intrinsic::x86_avx512_vpdpbusds_512: {
5230+
unsigned NumElts = CI->getType()->getPrimitiveSizeInBits() / 8;
5231+
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
5232+
CI->getArgOperand(2)};
5233+
Type *NewArgType = VectorType::get(Builder.getInt8Ty(), NumElts, false);
5234+
Args[1] = Builder.CreateBitCast(Args[1], NewArgType);
5235+
Args[2] = Builder.CreateBitCast(Args[2], NewArgType);
5236+
5237+
NewCall = Builder.CreateCall(NewFn, Args);
5238+
break;
5239+
}
51875240
}
51885241
assert(NewCall && "Should have either set this variable or returned through "
51895242
"the default case");

llvm/test/CodeGen/X86/avx512vnni-intrinsics-upgrade.ll

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,31 @@
22
; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+avx512vnni --show-mc-encoding | FileCheck %s --check-prefixes=CHECK,X86
33
; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx512vnni --show-mc-encoding | FileCheck %s --check-prefixes=CHECK,X64
44

5-
declare <16 x i32> @llvm.x86.avx512.mask.vpdpbusd.512(<16 x i32>, <16 x i32>, <16 x i32>, i16)
6-
declare <16 x i32> @llvm.x86.avx512.maskz.vpdpbusd.512(<16 x i32>, <16 x i32>, <16 x i32>, i16)
5+
declare <16 x i32> @llvm.x86.avx512.vpdpbusd.512(<16 x i32>, <16 x i32>, <16 x i32>, i16)
76

87
define <16 x i32>@test_int_x86_avx512_vpdpbusd_512(<16 x i32> %x0, <16 x i32> %x1, <16 x i32> %x2) {
98
; CHECK-LABEL: test_int_x86_avx512_vpdpbusd_512:
109
; CHECK: # %bb.0:
1110
; CHECK-NEXT: vpdpbusd %zmm2, %zmm1, %zmm0 # encoding: [0x62,0xf2,0x75,0x48,0x50,0xc2]
11+
; CHECK-NEXT: ret{{[l|q]}} # encoding: [0xc3]
12+
%res = call <16 x i32> @llvm.x86.avx512.vpdpbusd.512(<16 x i32> %x0, <16 x i32> %x1, <16 x i32> %x2)
13+
ret <16 x i32> %res
14+
}
15+
16+
declare <16 x i32> @llvm.x86.avx512.mask.vpdpbusd.512(<16 x i32>, <16 x i32>, <16 x i32>, i16)
17+
declare <16 x i32> @llvm.x86.avx512.maskz.vpdpbusd.512(<16 x i32>, <16 x i32>, <16 x i32>, i16)
18+
19+
define <16 x i32>@test_int_x86_avx512_mask_vpdpbusd_512(<16 x i32> %x0, <16 x i32> %x1, <16 x i32> %x2) {
20+
; CHECK-LABEL: test_int_x86_avx512_mask_vpdpbusd_512:
21+
; CHECK: # %bb.0:
22+
; CHECK-NEXT: vpdpbusd %zmm2, %zmm1, %zmm0 # encoding: [0x62,0xf2,0x75,0x48,0x50,0xc2]
1223
; CHECK-NEXT: ret{{[l|q]}} # encoding: [0xc3]
1324
%res = call <16 x i32> @llvm.x86.avx512.mask.vpdpbusd.512(<16 x i32> %x0, <16 x i32> %x1, <16 x i32> %x2, i16 -1)
1425
ret <16 x i32> %res
1526
}
1627

17-
define { <16 x i32>, <16 x i32> } @test_int_x86_avx512_mask_vpdpbusd_512(<16 x i32> %x0, <16 x i32> %x1, ptr %x2p, <16 x i32> %x4, i16 %x3) {
18-
; X86-LABEL: test_int_x86_avx512_mask_vpdpbusd_512:
28+
define { <16 x i32>, <16 x i32> } @test_int_x86_avx512_maskz_vpdpbusd_512(<16 x i32> %x0, <16 x i32> %x1, ptr %x2p, <16 x i32> %x4, i16 %x3) {
29+
; X86-LABEL: test_int_x86_avx512_maskz_vpdpbusd_512:
1930
; X86: # %bb.0:
2031
; X86-NEXT: vmovdqa64 %zmm0, %zmm3 # encoding: [0x62,0xf1,0xfd,0x48,0x6f,0xd8]
2132
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax # encoding: [0x8b,0x44,0x24,0x04]
@@ -25,7 +36,7 @@ define { <16 x i32>, <16 x i32> } @test_int_x86_avx512_mask_vpdpbusd_512(<16 x i
2536
; X86-NEXT: vmovdqa64 %zmm3, %zmm1 # encoding: [0x62,0xf1,0xfd,0x48,0x6f,0xcb]
2637
; X86-NEXT: retl # encoding: [0xc3]
2738
;
28-
; X64-LABEL: test_int_x86_avx512_mask_vpdpbusd_512:
39+
; X64-LABEL: test_int_x86_avx512_maskz_vpdpbusd_512:
2940
; X64: # %bb.0:
3041
; X64-NEXT: vmovdqa64 %zmm0, %zmm3 # encoding: [0x62,0xf1,0xfd,0x48,0x6f,0xd8]
3142
; X64-NEXT: kmovw %esi, %k1 # encoding: [0xc5,0xf8,0x92,0xce]
@@ -41,20 +52,31 @@ define { <16 x i32>, <16 x i32> } @test_int_x86_avx512_mask_vpdpbusd_512(<16 x i
4152
ret { <16 x i32>, <16 x i32> } %res3
4253
}
4354

44-
declare <16 x i32> @llvm.x86.avx512.mask.vpdpbusds.512(<16 x i32>, <16 x i32>, <16 x i32>, i16)
45-
declare <16 x i32> @llvm.x86.avx512.maskz.vpdpbusds.512(<16 x i32>, <16 x i32>, <16 x i32>, i16)
55+
declare <16 x i32> @llvm.x86.avx512.vpdpbusds.512(<16 x i32>, <16 x i32>, <16 x i32>, i16)
4656

4757
define <16 x i32>@test_int_x86_avx512_vpdpbusds_512(<16 x i32> %x0, <16 x i32> %x1, <16 x i32> %x2) {
4858
; CHECK-LABEL: test_int_x86_avx512_vpdpbusds_512:
4959
; CHECK: # %bb.0:
5060
; CHECK-NEXT: vpdpbusds %zmm2, %zmm1, %zmm0 # encoding: [0x62,0xf2,0x75,0x48,0x51,0xc2]
61+
; CHECK-NEXT: ret{{[l|q]}} # encoding: [0xc3]
62+
%res = call <16 x i32> @llvm.x86.avx512.vpdpbusds.512(<16 x i32> %x0, <16 x i32> %x1, <16 x i32> %x2)
63+
ret <16 x i32> %res
64+
}
65+
66+
declare <16 x i32> @llvm.x86.avx512.mask.vpdpbusds.512(<16 x i32>, <16 x i32>, <16 x i32>, i16)
67+
declare <16 x i32> @llvm.x86.avx512.maskz.vpdpbusds.512(<16 x i32>, <16 x i32>, <16 x i32>, i16)
68+
69+
define <16 x i32>@test_int_x86_avx512_mask_vpdpbusds_512(<16 x i32> %x0, <16 x i32> %x1, <16 x i32> %x2) {
70+
; CHECK-LABEL: test_int_x86_avx512_mask_vpdpbusds_512:
71+
; CHECK: # %bb.0:
72+
; CHECK-NEXT: vpdpbusds %zmm2, %zmm1, %zmm0 # encoding: [0x62,0xf2,0x75,0x48,0x51,0xc2]
5173
; CHECK-NEXT: ret{{[l|q]}} # encoding: [0xc3]
5274
%res = call <16 x i32> @llvm.x86.avx512.mask.vpdpbusds.512(<16 x i32> %x0, <16 x i32> %x1, <16 x i32> %x2, i16 -1)
5375
ret <16 x i32> %res
5476
}
5577

56-
define { <16 x i32>, <16 x i32> } @test_int_x86_avx512_mask_vpdpbusds_512(<16 x i32> %x0, <16 x i32> %x1, ptr %x2p, <16 x i32> %x4, i16 %x3) {
57-
; X86-LABEL: test_int_x86_avx512_mask_vpdpbusds_512:
78+
define { <16 x i32>, <16 x i32> } @test_int_x86_avx512_maskz_vpdpbusds_512(<16 x i32> %x0, <16 x i32> %x1, ptr %x2p, <16 x i32> %x4, i16 %x3) {
79+
; X86-LABEL: test_int_x86_avx512_maskz_vpdpbusds_512:
5880
; X86: # %bb.0:
5981
; X86-NEXT: vmovdqa64 %zmm0, %zmm3 # encoding: [0x62,0xf1,0xfd,0x48,0x6f,0xd8]
6082
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax # encoding: [0x8b,0x44,0x24,0x04]
@@ -64,7 +86,7 @@ define { <16 x i32>, <16 x i32> } @test_int_x86_avx512_mask_vpdpbusds_512(<16 x
6486
; X86-NEXT: vmovdqa64 %zmm3, %zmm1 # encoding: [0x62,0xf1,0xfd,0x48,0x6f,0xcb]
6587
; X86-NEXT: retl # encoding: [0xc3]
6688
;
67-
; X64-LABEL: test_int_x86_avx512_mask_vpdpbusds_512:
89+
; X64-LABEL: test_int_x86_avx512_maskz_vpdpbusds_512:
6890
; X64: # %bb.0:
6991
; X64-NEXT: vmovdqa64 %zmm0, %zmm3 # encoding: [0x62,0xf1,0xfd,0x48,0x6f,0xd8]
7092
; X64-NEXT: kmovw %esi, %k1 # encoding: [0xc5,0xf8,0x92,0xce]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+avxvnni --show-mc-encoding | FileCheck %s
3+
; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avxvnni --show-mc-encoding | FileCheck %s
4+
5+
declare <4 x i32> @llvm.x86.avx512.vpdpbusd.128(<4 x i32>, <4 x i32>, <4 x i32>)
6+
7+
define <4 x i32>@test_int_x86_avx_vpdpbusd_128(<4 x i32> %x0, <4 x i32> %x1, <4 x i32> %x2) {
8+
; CHECK-LABEL: test_int_x86_avx_vpdpbusd_128:
9+
; CHECK: # %bb.0:
10+
; CHECK-NEXT: {vex} vpdpbusd %xmm2, %xmm1, %xmm0 # encoding: [0xc4,0xe2,0x71,0x50,0xc2]
11+
; CHECK-NEXT: ret{{[l|q]}} # encoding: [0xc3]
12+
%res = call <4 x i32> @llvm.x86.avx512.vpdpbusd.128(<4 x i32> %x0, <4 x i32> %x1, <4 x i32> %x2)
13+
ret <4 x i32> %res
14+
}
15+
16+
declare <8 x i32> @llvm.x86.avx512.vpdpbusd.256(<8 x i32>, <8 x i32>, <8 x i32>)
17+
18+
define <8 x i32>@test_int_x86_avx_vpdpbusd_256(<8 x i32> %x0, <8 x i32> %x1, <8 x i32> %x2) {
19+
; CHECK-LABEL: test_int_x86_avx_vpdpbusd_256:
20+
; CHECK: # %bb.0:
21+
; CHECK-NEXT: {vex} vpdpbusd %ymm2, %ymm1, %ymm0 # encoding: [0xc4,0xe2,0x75,0x50,0xc2]
22+
; CHECK-NEXT: ret{{[l|q]}} # encoding: [0xc3]
23+
%res = call <8 x i32> @llvm.x86.avx512.vpdpbusd.256(<8 x i32> %x0, <8 x i32> %x1, <8 x i32> %x2)
24+
ret <8 x i32> %res
25+
}
26+
27+
declare <4 x i32> @llvm.x86.avx512.vpdpbusds.128(<4 x i32>, <4 x i32>, <4 x i32>)
28+
29+
define <4 x i32>@test_int_x86_avx_vpdpbusds_128(<4 x i32> %x0, <4 x i32> %x1, <4 x i32> %x2) {
30+
; CHECK-LABEL: test_int_x86_avx_vpdpbusds_128:
31+
; CHECK: # %bb.0:
32+
; CHECK-NEXT: {vex} vpdpbusds %xmm2, %xmm1, %xmm0 # encoding: [0xc4,0xe2,0x71,0x51,0xc2]
33+
; CHECK-NEXT: ret{{[l|q]}} # encoding: [0xc3]
34+
%res = call <4 x i32> @llvm.x86.avx512.vpdpbusds.128(<4 x i32> %x0, <4 x i32> %x1, <4 x i32> %x2)
35+
ret <4 x i32> %res
36+
}
37+
38+
declare <8 x i32> @llvm.x86.avx512.vpdpbusds.256(<8 x i32>, <8 x i32>, <8 x i32>)
39+
40+
define <8 x i32>@test_int_x86_avx_vpdpbusds_256(<8 x i32> %x0, <8 x i32> %x1, <8 x i32> %x2) {
41+
; CHECK-LABEL: test_int_x86_avx_vpdpbusds_256:
42+
; CHECK: # %bb.0:
43+
; CHECK-NEXT: {vex} vpdpbusds %ymm2, %ymm1, %ymm0 # encoding: [0xc4,0xe2,0x75,0x51,0xc2]
44+
; CHECK-NEXT: ret{{[l|q]}} # encoding: [0xc3]
45+
%res = call <8 x i32> @llvm.x86.avx512.vpdpbusds.256(<8 x i32> %x0, <8 x i32> %x1, <8 x i32> %x2)
46+
ret <8 x i32> %res
47+
}

0 commit comments

Comments
 (0)