Skip to content

Commit 397aa43

Browse files
committed
[Headers][X86] Enable constexpr handling for MMX/SSE/AVX/AVX512 PMADDWD/PMADDUBSW intrinsics
1 parent 542cba8 commit 397aa43

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

clang/include/clang/Basic/BuiltinsX86.td

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,16 @@ let Attributes = [Const, NoThrow, RequiredVectorWidth<128>] in {
123123
def Op#d128 : X86Builtin<"_Vector<4, int>(_Vector<4, int>, _Vector<4, int>)">;
124124
}
125125

126-
def pmaddubsw128 : X86Builtin<"_Vector<8, short>(_Vector<16, char>, _Vector<16, char>)">;
127126
def pmulhrsw128 : X86Builtin<"_Vector<8, short>(_Vector<8, short>, _Vector<8, short>)">;
128127
def pshufb128 : X86Builtin<"_Vector<16, char>(_Vector<16, char>, _Vector<16, char>)">;
129128
def psignb128 : X86Builtin<"_Vector<16, char>(_Vector<16, char>, _Vector<16, char>)">;
130129
def psignw128 : X86Builtin<"_Vector<8, short>(_Vector<8, short>, _Vector<8, short>)">;
131130
def psignd128 : X86Builtin<"_Vector<4, int>(_Vector<4, int>, _Vector<4, int>)">;
132131
}
132+
133+
let Features = "ssse3", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<128>] in {
134+
def pmaddubsw128 : X86Builtin<"_Vector<8, short>(_Vector<16, char>, _Vector<16, char>)">;
135+
}
133136
}
134137

135138
// AVX
@@ -278,13 +281,14 @@ let Features = "sse2", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] i
278281
def psllw128 : X86Builtin<"_Vector<8, short>(_Vector<8, short>, _Vector<8, short>)">;
279282
def pslld128 : X86Builtin<"_Vector<4, int>(_Vector<4, int>, _Vector<4, int>)">;
280283
def psllq128 : X86Builtin<"_Vector<2, long long int>(_Vector<2, long long int>, _Vector<2, long long int>)">;
281-
def pmaddwd128 : X86Builtin<"_Vector<4, int>(_Vector<8, short>, _Vector<8, short>)">;
282284
def pslldqi128_byteshift : X86Builtin<"_Vector<16, char>(_Vector<16, char>, _Constant int)">;
283285
def psrldqi128_byteshift : X86Builtin<"_Vector<16, char>(_Vector<16, char>, _Constant int)">;
284286
}
285287

286288
let Features = "sse2",
287289
Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<128>] in {
290+
def pmaddwd128 : X86Builtin<"_Vector<4, int>(_Vector<8, short>, _Vector<8, short>)">;
291+
288292
def pmuludq128 : X86Builtin<"_Vector<2, long long int>(_Vector<4, int>, _Vector<4, int>)">;
289293

290294
def psllwi128 : X86Builtin<"_Vector<8, short>(_Vector<8, short>, int)">;
@@ -581,8 +585,6 @@ let Features = "avx2", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] i
581585
def phsubw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
582586
def phsubd256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Vector<8, int>)">;
583587
def phsubsw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
584-
def pmaddubsw256 : X86Builtin<"_Vector<16, short>(_Vector<32, char>, _Vector<32, char>)">;
585-
def pmaddwd256 : X86Builtin<"_Vector<8, int>(_Vector<16, short>, _Vector<16, short>)">;
586588
def pmovmskb256 : X86Builtin<"int(_Vector<32, char>)">;
587589
def pmulhrsw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
588590
def psadbw256 : X86Builtin<"_Vector<4, long long int>(_Vector<32, char>, _Vector<32, char>)">;
@@ -619,6 +621,9 @@ let Features = "avx2", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWi
619621

620622
def pblendvb256 : X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Vector<32, char>, _Vector<32, char>)">;
621623

624+
def pmaddubsw256 : X86Builtin<"_Vector<16, short>(_Vector<32, char>, _Vector<32, char>)">;
625+
def pmaddwd256 : X86Builtin<"_Vector<8, int>(_Vector<16, short>, _Vector<16, short>)">;
626+
622627
def pmuldq256 : X86Builtin<"_Vector<4, long long int>(_Vector<8, int>, _Vector<8, int>)">;
623628
def pmuludq256 : X86Builtin<"_Vector<4, long long int>(_Vector<8, int>, _Vector<8, int>)">;
624629

@@ -1378,10 +1383,6 @@ let Features = "avx512f", Attributes = [NoThrow, Const, RequiredVectorWidth<512>
13781383
def subps512 : X86Builtin<"_Vector<16, float>(_Vector<16, float>, _Vector<16, float>, _Constant int)">;
13791384
}
13801385

1381-
let Features = "avx512bw", Attributes = [NoThrow, Const, RequiredVectorWidth<512>] in {
1382-
def pmaddubsw512 : X86Builtin<"_Vector<32, short>(_Vector<64, char>, _Vector<64, char>)">;
1383-
def pmaddwd512 : X86Builtin<"_Vector<16, int>(_Vector<32, short>, _Vector<32, short>)">;
1384-
}
13851386

13861387
let Features = "avx512f", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] in {
13871388
def addss_round_mask : X86Builtin<"_Vector<4, float>(_Vector<4, float>, _Vector<4, float>, _Vector<4, float>, unsigned char, _Constant int)">;
@@ -1999,6 +2000,8 @@ let Features = "avx512bw", Attributes = [NoThrow, Const, RequiredVectorWidth<512
19992000
}
20002001

20012002
let Features = "avx512bw", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<512>] in {
2003+
def pmaddubsw512 : X86Builtin<"_Vector<32, short>(_Vector<64, char>, _Vector<64, char>)">;
2004+
def pmaddwd512 : X86Builtin<"_Vector<16, int>(_Vector<32, short>, _Vector<32, short>)">;
20022005
def psllv32hi : X86Builtin<"_Vector<32, short>(_Vector<32, short>, _Vector<32, short>)">;
20032006
def pshufhw512 : X86Builtin<"_Vector<32, short>(_Vector<32, short>, _Constant int)">;
20042007
def pshuflw512 : X86Builtin<"_Vector<32, short>(_Vector<32, short>, _Constant int)">;

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,6 +2579,12 @@ static bool interp__builtin_elementwise_maxmin(InterpState &S, CodePtr OpPC,
25792579
return true;
25802580
}
25812581

2582+
static bool interp__builtin_ia32_pmadd(InterpState &S, CodePtr OpPC,
2583+
const CallExpr *Call,
2584+
unsigned BuiltinID) {
2585+
return true; // TODO: Implement the builtin.
2586+
}
2587+
25822588
static bool interp__builtin_ia32_pmul(InterpState &S, CodePtr OpPC,
25832589
const CallExpr *Call,
25842590
unsigned BuiltinID) {
@@ -3448,6 +3454,16 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
34483454
return interp__builtin_elementwise_int_binop(S, OpPC, Call,
34493455
llvm::APIntOps::avgCeilU);
34503456

3457+
case clang::X86::BI__builtin_ia32_pmaddubsw128:
3458+
case clang::X86::BI__builtin_ia32_pmaddubsw256:
3459+
case clang::X86::BI__builtin_ia32_pmaddubsw512:
3460+
return true; // TODO: Use interp__builtin_i32_pmadd.
3461+
3462+
case clang::X86::BI__builtin_ia32_pmaddwd128:
3463+
case clang::X86::BI__builtin_ia32_pmaddwd256:
3464+
case clang::X86::BI__builtin_ia32_pmaddwd512:
3465+
return true; // TODO: Use interp__builtin_i32_pmadd.
3466+
34513467
case clang::X86::BI__builtin_ia32_pmulhuw128:
34523468
case clang::X86::BI__builtin_ia32_pmulhuw256:
34533469
case clang::X86::BI__builtin_ia32_pmulhuw512:

clang/lib/AST/ExprConstant.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11778,6 +11778,20 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1177811778
case clang::X86::BI__builtin_ia32_pavgw512:
1177911779
return EvaluateBinOpExpr(llvm::APIntOps::avgCeilU);
1178011780

11781+
case clang::X86::BI__builtin_ia32_pmaddubsw128:
11782+
case clang::X86::BI__builtin_ia32_pmaddwd128:
11783+
case clang::X86::BI__builtin_ia32_pmaddubsw256:
11784+
case clang::X86::BI__builtin_ia32_pmaddwd256:
11785+
case clang::X86::BI__builtin_ia32_pmaddubsw512:
11786+
case clang::X86::BI__builtin_ia32_pmaddwd512:
11787+
return true; // TODO: Handle __builtin_ia32_pmaddub
11788+
11789+
case clang::X86::BI__builtin_ia32_pmaddwd128:
11790+
case clang::X86::BI__builtin_ia32_pmaddwd256:
11791+
case clang::X86::BI__builtin_ia32_pmaddwd512:
11792+
return true; // TODO: Handle __builtin_ia32_pmadd
11793+
});
11794+
1178111795
case clang::X86::BI__builtin_ia32_pmulhuw128:
1178211796
case clang::X86::BI__builtin_ia32_pmulhuw256:
1178311797
case clang::X86::BI__builtin_ia32_pmulhuw512:

0 commit comments

Comments
 (0)