Skip to content

Commit 9ada542

Browse files
committed
[Headers][X86] Enable constexpr handling for MMX/SSE/AVX/AVX512 PMADDWD/PMADDUBSW intrinsics
1 parent 2d6e7ef commit 9ada542

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
@@ -124,13 +124,16 @@ let Attributes = [Const, NoThrow, RequiredVectorWidth<128>] in {
124124
def Op#d128 : X86Builtin<"_Vector<4, int>(_Vector<4, int>, _Vector<4, int>)">;
125125
}
126126

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

136139
// AVX
@@ -276,13 +279,14 @@ let Features = "sse2", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] i
276279
def psllw128 : X86Builtin<"_Vector<8, short>(_Vector<8, short>, _Vector<8, short>)">;
277280
def pslld128 : X86Builtin<"_Vector<4, int>(_Vector<4, int>, _Vector<4, int>)">;
278281
def psllq128 : X86Builtin<"_Vector<2, long long int>(_Vector<2, long long int>, _Vector<2, long long int>)">;
279-
def pmaddwd128 : X86Builtin<"_Vector<4, int>(_Vector<8, short>, _Vector<8, short>)">;
280282
def pslldqi128_byteshift : X86Builtin<"_Vector<16, char>(_Vector<16, char>, _Constant int)">;
281283
def psrldqi128_byteshift : X86Builtin<"_Vector<16, char>(_Vector<16, char>, _Constant int)">;
282284
}
283285

284286
let Features = "sse2",
285287
Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<128>] in {
288+
def pmaddwd128 : X86Builtin<"_Vector<4, int>(_Vector<8, short>, _Vector<8, short>)">;
289+
286290
def pmuludq128 : X86Builtin<"_Vector<2, long long int>(_Vector<4, int>, _Vector<4, int>)">;
287291

288292
def psllwi128 : X86Builtin<"_Vector<8, short>(_Vector<8, short>, int)">;
@@ -578,8 +582,6 @@ let Features = "avx2", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] i
578582
def phsubw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
579583
def phsubd256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Vector<8, int>)">;
580584
def phsubsw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
581-
def pmaddubsw256 : X86Builtin<"_Vector<16, short>(_Vector<32, char>, _Vector<32, char>)">;
582-
def pmaddwd256 : X86Builtin<"_Vector<8, int>(_Vector<16, short>, _Vector<16, short>)">;
583585
def pmovmskb256 : X86Builtin<"int(_Vector<32, char>)">;
584586
def pmulhrsw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
585587
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

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

1376-
let Features = "avx512bw", Attributes = [NoThrow, Const, RequiredVectorWidth<512>] in {
1377-
def pmaddubsw512 : X86Builtin<"_Vector<32, short>(_Vector<64, char>, _Vector<64, char>)">;
1378-
def pmaddwd512 : X86Builtin<"_Vector<16, int>(_Vector<32, short>, _Vector<32, short>)">;
1379-
}
13801381

13811382
let Features = "avx512f", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] in {
13821383
def addss_round_mask : X86Builtin<"_Vector<4, float>(_Vector<4, float>, _Vector<4, float>, _Vector<4, float>, unsigned char, _Constant int)">;
@@ -1996,6 +1997,8 @@ let Features = "avx512bw", Attributes = [NoThrow, Const, RequiredVectorWidth<512
19961997
}
19971998

19981999
let Features = "avx512bw", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<512>] in {
2000+
def pmaddubsw512 : X86Builtin<"_Vector<32, short>(_Vector<64, char>, _Vector<64, char>)">;
2001+
def pmaddwd512 : X86Builtin<"_Vector<16, int>(_Vector<32, short>, _Vector<32, short>)">;
19992002
def psllv32hi : X86Builtin<"_Vector<32, short>(_Vector<32, short>, _Vector<32, short>)">;
20002003
}
20012004

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,6 +2598,12 @@ static bool interp__builtin_elementwise_maxmin(InterpState &S, CodePtr OpPC,
25982598
return true;
25992599
}
26002600

2601+
static bool interp__builtin_ia32_pmadd(InterpState &S, CodePtr OpPC,
2602+
const CallExpr *Call,
2603+
unsigned BuiltinID) {
2604+
return true; // TODO: Implement the builtin.
2605+
}
2606+
26012607
static bool interp__builtin_ia32_pmul(InterpState &S, CodePtr OpPC,
26022608
const CallExpr *Call,
26032609
unsigned BuiltinID) {
@@ -3364,6 +3370,16 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
33643370
return interp__builtin_elementwise_int_binop(S, OpPC, Call,
33653371
llvm::APIntOps::avgCeilU);
33663372

3373+
case clang::X86::BI__builtin_ia32_pmaddubsw128:
3374+
case clang::X86::BI__builtin_ia32_pmaddubsw256:
3375+
case clang::X86::BI__builtin_ia32_pmaddubsw512:
3376+
return true; // TODO: Use interp__builtin_i32_pmadd.
3377+
3378+
case clang::X86::BI__builtin_ia32_pmaddwd128:
3379+
case clang::X86::BI__builtin_ia32_pmaddwd256:
3380+
case clang::X86::BI__builtin_ia32_pmaddwd512:
3381+
return true; // TODO: Use interp__builtin_i32_pmadd.
3382+
33673383
case clang::X86::BI__builtin_ia32_pmulhuw128:
33683384
case clang::X86::BI__builtin_ia32_pmulhuw256:
33693385
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
@@ -11724,6 +11724,20 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1172411724
case clang::X86::BI__builtin_ia32_pavgw512:
1172511725
return EvaluateBinOpExpr(llvm::APIntOps::avgCeilU);
1172611726

11727+
case clang::X86::BI__builtin_ia32_pmaddubsw128:
11728+
case clang::X86::BI__builtin_ia32_pmaddwd128:
11729+
case clang::X86::BI__builtin_ia32_pmaddubsw256:
11730+
case clang::X86::BI__builtin_ia32_pmaddwd256:
11731+
case clang::X86::BI__builtin_ia32_pmaddubsw512:
11732+
case clang::X86::BI__builtin_ia32_pmaddwd512:
11733+
return true; // TODO: Handle __builtin_ia32_pmaddub
11734+
11735+
case clang::X86::BI__builtin_ia32_pmaddwd128:
11736+
case clang::X86::BI__builtin_ia32_pmaddwd256:
11737+
case clang::X86::BI__builtin_ia32_pmaddwd512:
11738+
return true; // TODO: Handle __builtin_ia32_pmadd
11739+
});
11740+
1172711741
case clang::X86::BI__builtin_ia32_pmulhuw128:
1172811742
case clang::X86::BI__builtin_ia32_pmulhuw256:
1172911743
case clang::X86::BI__builtin_ia32_pmulhuw512:

0 commit comments

Comments
 (0)