Skip to content

Commit 79006fe

Browse files
committed
Stash
1 parent 9c118aa commit 79006fe

File tree

7 files changed

+60
-12
lines changed

7 files changed

+60
-12
lines changed

clang/include/clang/Basic/BuiltinsX86.td

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ let Features = "sse", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] in
181181
def cvttss2si : X86Builtin<"int(_Vector<4, float>)">;
182182
}
183183

184-
let Features = "sse", Attributes = [NoThrow, RequiredVectorWidth<128>] in {
184+
let Features = "sse", Attributes = [NoThrow, Constexpr, RequiredVectorWidth<128>] in {
185185
def movmskps : X86Builtin<"int(_Vector<4, float>)">;
186186
}
187187

@@ -207,7 +207,7 @@ let Features = "sse2", Attributes = [NoThrow, RequiredVectorWidth<128>] in {
207207
def maskmovdqu : X86Builtin<"void(_Vector<16, char>, _Vector<16, char>, char *)">;
208208
}
209209

210-
let Features = "sse2", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] in {
210+
let Features = "sse2", Attributes = [NoThrow, Constexpr, RequiredVectorWidth<128>] in {
211211
def movmskpd : X86Builtin<"int(_Vector<2, double>)">;
212212
def pmovmskb128 : X86Builtin<"int(_Vector<16, char>)">;
213213
}
@@ -526,6 +526,11 @@ let Features = "avx", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] in
526526
def vtestnzcps : X86Builtin<"int(_Vector<4, float>, _Vector<4, float>)">;
527527
}
528528

529+
let Features = "avx", Attributes = [NoThrow, Constexpr, RequiredVectorWidth<256>] in {
530+
def movmskpd256 : X86Builtin<"int(_Vector<4, double>)">;
531+
def movmskps256 : X86Builtin<"int(_Vector<8, float>)">;
532+
}
533+
529534
let Features = "avx", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] in {
530535
def vtestzpd256 : X86Builtin<"int(_Vector<4, double>, _Vector<4, double>)">;
531536
def vtestcpd256 : X86Builtin<"int(_Vector<4, double>, _Vector<4, double>)">;
@@ -536,8 +541,6 @@ let Features = "avx", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] in
536541
def ptestz256 : X86Builtin<"int(_Vector<4, long long int>, _Vector<4, long long int>)">;
537542
def ptestc256 : X86Builtin<"int(_Vector<4, long long int>, _Vector<4, long long int>)">;
538543
def ptestnzc256 : X86Builtin<"int(_Vector<4, long long int>, _Vector<4, long long int>)">;
539-
def movmskpd256 : X86Builtin<"int(_Vector<4, double>)">;
540-
def movmskps256 : X86Builtin<"int(_Vector<8, float>)">;
541544
}
542545

543546
let Features = "avx", Attributes = [NoThrow] in {
@@ -572,6 +575,10 @@ let Features = "avx", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWid
572575
def vec_set_v8si : X86Builtin<"_Vector<8, int>(_Vector<8, int>, int, _Constant int)">;
573576
}
574577

578+
let Features = "avx2", Attributes = [NoThrow, Constexpr, RequiredVectorWidth<256>] in {
579+
def pmovmskb256 : X86Builtin<"int(_Vector<32, char>)">;
580+
}
581+
575582
let Features = "avx2", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] in {
576583
def mpsadbw256 : X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Vector<32, char>, _Constant char)">;
577584
def palignr256 : X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Vector<32, char>, _Constant int)">;
@@ -583,7 +590,6 @@ let Features = "avx2", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] i
583590
def phsubsw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
584591
def pmaddubsw256 : X86Builtin<"_Vector<16, short>(_Vector<32, char>, _Vector<32, char>)">;
585592
def pmaddwd256 : X86Builtin<"_Vector<8, int>(_Vector<16, short>, _Vector<16, short>)">;
586-
def pmovmskb256 : X86Builtin<"int(_Vector<32, char>)">;
587593
def pmulhrsw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
588594
def psadbw256 : X86Builtin<"_Vector<4, long long int>(_Vector<32, char>, _Vector<32, char>)">;
589595
def pshufb256 : X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Vector<32, char>)">;

clang/lib/AST/ExprConstant.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13767,6 +13767,38 @@ static bool getBuiltinAlignArguments(const CallExpr *E, EvalInfo &Info,
1376713767
bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1376813768
unsigned BuiltinOp) {
1376913769

13770+
auto EvalMoveMaskOp = [&]() {
13771+
APValue Source;
13772+
if (!Evaluate(Source, Info, E->getArg(0))) return false;
13773+
unsigned SourceLen = Source.getVectorLength();
13774+
const VectorType *VT = E->getArg(0)->getType()->castAs<VectorType>();
13775+
const QualType ElemQT = VT->getElementType();
13776+
unsigned LaneWidth = Info.Ctx.getTypeSize(ElemQT);
13777+
13778+
if (ElemQT->isIntegerType()) { // Get MSB of each byte of every lane
13779+
unsigned ByteLen = 8;
13780+
unsigned ResultLen = (LaneWidth * SourceLen) / ByteLen;
13781+
APInt Result(ResultLen, 0);
13782+
unsigned ResultIdx = 0;
13783+
for (unsigned I = 0; I != SourceLen; ++I) {
13784+
APInt Lane = Source.getVectorElt(I).getInt();
13785+
for (unsigned J = 0; J != LaneWidth; J=J+ByteLen) {
13786+
Result.setBitVal(ResultIdx++, Lane[J]);
13787+
}
13788+
}
13789+
return Success(Result, E);
13790+
}
13791+
if (ElemQT->isFloatingType()) { // Get sign bit of every lane
13792+
APInt Result(SourceLen, 0);
13793+
for (unsigned I = 0; I != SourceLen; ++I) {
13794+
APInt Lane = Source.getVectorElt(I).getFloat().bitcastToAPInt();
13795+
Result.setBitVal(I, Lane[LaneWidth-1]);
13796+
}
13797+
return Success(Result, E);
13798+
}
13799+
return false;
13800+
};
13801+
1377013802
auto HandleMaskBinOp =
1377113803
[&](llvm::function_ref<APSInt(const APSInt &, const APSInt &)> Fn)
1377213804
-> bool {
@@ -14795,6 +14827,15 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1479514827
return Success(CarryOut, E);
1479614828
}
1479714829

14830+
case clang::X86::BI__builtin_ia32_movmskps:
14831+
case clang::X86::BI__builtin_ia32_movmskpd:
14832+
case clang::X86::BI__builtin_ia32_pmovmskb128:
14833+
case clang::X86::BI__builtin_ia32_pmovmskb256:
14834+
case clang::X86::BI__builtin_ia32_movmskps256:
14835+
case clang::X86::BI__builtin_ia32_movmskpd256: {
14836+
return EvalMoveMaskOp();
14837+
}
14838+
1479814839
case clang::X86::BI__builtin_ia32_bextr_u32:
1479914840
case clang::X86::BI__builtin_ia32_bextr_u64:
1480014841
case clang::X86::BI__builtin_ia32_bextri_u32:

clang/lib/Headers/avx2intrin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ _mm256_min_epu32(__m256i __a, __m256i __b) {
13061306
/// \param __a
13071307
/// A 256-bit integer vector containing the source bytes.
13081308
/// \returns The 32-bit integer mask.
1309-
static __inline__ int __DEFAULT_FN_ATTRS256
1309+
static __inline__ int __DEFAULT_FN_ATTRS256_CONSTEXPR
13101310
_mm256_movemask_epi8(__m256i __a)
13111311
{
13121312
return __builtin_ia32_pmovmskb256((__v32qi)__a);

clang/lib/Headers/avxintrin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,7 +2960,7 @@ _mm256_testnzc_si256(__m256i __a, __m256i __b)
29602960
/// A 256-bit vector of [4 x double] containing the double-precision
29612961
/// floating point values with sign bits to be extracted.
29622962
/// \returns The sign bits from the operand, written to bits [3:0].
2963-
static __inline int __DEFAULT_FN_ATTRS
2963+
static __inline int __DEFAULT_FN_ATTRS_CONSTEXPR
29642964
_mm256_movemask_pd(__m256d __a)
29652965
{
29662966
return __builtin_ia32_movmskpd256((__v4df)__a);
@@ -2978,7 +2978,7 @@ _mm256_movemask_pd(__m256d __a)
29782978
/// A 256-bit vector of [8 x float] containing the single-precision floating
29792979
/// point values with sign bits to be extracted.
29802980
/// \returns The sign bits from the operand, written to bits [7:0].
2981-
static __inline int __DEFAULT_FN_ATTRS
2981+
static __inline int __DEFAULT_FN_ATTRS_CONSTEXPR
29822982
_mm256_movemask_ps(__m256 __a)
29832983
{
29842984
return __builtin_ia32_movmskps256((__v8sf)__a);

clang/lib/Headers/emmintrin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4280,7 +4280,7 @@ _mm_packus_epi16(__m128i __a, __m128i __b) {
42804280
/// A 128-bit integer vector containing the values with bits to be extracted.
42814281
/// \returns The most significant bits from each 8-bit element in \a __a,
42824282
/// written to bits [15:0]. The other bits are assigned zeros.
4283-
static __inline__ int __DEFAULT_FN_ATTRS _mm_movemask_epi8(__m128i __a) {
4283+
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR _mm_movemask_epi8(__m128i __a) {
42844284
return __builtin_ia32_pmovmskb128((__v16qi)__a);
42854285
}
42864286

@@ -4699,7 +4699,7 @@ _mm_unpacklo_pd(__m128d __a, __m128d __b) {
46994699
/// be extracted.
47004700
/// \returns The sign bits from each of the double-precision elements in \a __a,
47014701
/// written to bits [1:0]. The remaining bits are assigned values of zero.
4702-
static __inline__ int __DEFAULT_FN_ATTRS _mm_movemask_pd(__m128d __a) {
4702+
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR _mm_movemask_pd(__m128d __a) {
47034703
return __builtin_ia32_movmskpd((__v2df)__a);
47044704
}
47054705

clang/lib/Headers/xmmintrin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,7 @@ _mm_min_pu8(__m64 __a, __m64 __b) {
24162416
/// A 64-bit integer vector containing the values with bits to be extracted.
24172417
/// \returns The most significant bit from each 8-bit element in \a __a,
24182418
/// written to bits [7:0].
2419-
static __inline__ int __DEFAULT_FN_ATTRS_SSE2
2419+
static __inline__ int __DEFAULT_FN_ATTRS_SSE2_CONSTEXPR
24202420
_mm_movemask_pi8(__m64 __a)
24212421
{
24222422
return __builtin_ia32_pmovmskb128((__v16qi)__zext128(__a));
@@ -3015,7 +3015,7 @@ _mm_cvtps_pi8(__m128 __a)
30153015
/// \returns A 32-bit integer value. Bits [3:0] contain the sign bits from each
30163016
/// single-precision floating-point element of the parameter. Bits [31:4] are
30173017
/// set to zero.
3018-
static __inline__ int __DEFAULT_FN_ATTRS
3018+
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
30193019
_mm_movemask_ps(__m128 __a)
30203020
{
30213021
return __builtin_ia32_movmskps((__v4sf)__a);

clang/test/CodeGen/X86/mmx-builtins.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ int test_mm_movemask_pi8(__m64 a) {
402402
return _mm_movemask_pi8(a);
403403
}
404404

405+
405406
__m64 test_mm_mul_su32(__m64 a, __m64 b) {
406407
// CHECK-LABEL: test_mm_mul_su32
407408
// CHECK: and <2 x i64> {{%.*}}, splat (i64 4294967295)

0 commit comments

Comments
 (0)