Skip to content

Commit 92e6208

Browse files
committed
Squash for rebase
1 parent e313bc8 commit 92e6208

File tree

5 files changed

+90
-1
lines changed

5 files changed

+90
-1
lines changed

clang/include/clang/Basic/BuiltinsX86.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ let Features = "sse4.1", Attributes = [NoThrow, Const, Constexpr, RequiredVector
349349

350350
def pmuldq128 : X86Builtin<"_Vector<2, long long int>(_Vector<4, int>, _Vector<4, int>)">;
351351
def packusdw128 : X86Builtin<"_Vector<8, short>(_Vector<4, int>, _Vector<4, int>)">;
352+
def phminposuw128 : X86Builtin<"_Vector<8, short>(_Vector<8, short>)">;
352353

353354
def vec_ext_v16qi : X86Builtin<"char(_Vector<16, char>, _Constant int)">;
354355
def vec_set_v16qi : X86Builtin<"_Vector<16, char>(_Vector<16, char>, char, _Constant int)">;

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,6 +2899,45 @@ static bool interp__builtin_x86_insert_subvector(InterpState &S, CodePtr OpPC,
28992899
return true;
29002900
}
29012901

2902+
static bool interp__builtin_ia32_phminposuw(InterpState &S, CodePtr OpPC,
2903+
const CallExpr *Call) {
2904+
assert(Call->getNumArgs() == 1);
2905+
2906+
const Pointer &Source = S.Stk.pop<Pointer>();
2907+
const Pointer &Dest = S.Stk.peek<Pointer>();
2908+
2909+
unsigned SourceLen = Source.getNumElems();
2910+
QualType ElemQT = getElemType(Source);
2911+
OptPrimType ElemT = S.getContext().classify(ElemQT);
2912+
unsigned LaneBitWidth = S.getASTContext().getTypeSize(ElemQT);
2913+
2914+
bool DestUnsigned = Call->getCallReturnType(S.getASTContext())
2915+
->castAs<VectorType>()
2916+
->getElementType()
2917+
->isUnsignedIntegerOrEnumerationType();
2918+
2919+
INT_TYPE_SWITCH_NO_BOOL(*ElemT, {
2920+
APSInt MinIndex(LaneBitWidth, DestUnsigned);
2921+
APSInt MinVal = Source.elem<T>(0).toAPSInt();
2922+
2923+
for (unsigned I = 1; I != SourceLen; ++I) {
2924+
APSInt Val = Source.elem<T>(I).toAPSInt();
2925+
if (MinVal.ugt(Val)) {
2926+
MinVal = Val;
2927+
MinIndex = I;
2928+
}
2929+
}
2930+
2931+
Dest.elem<T>(0) = static_cast<T>(MinVal);
2932+
Dest.elem<T>(1) = static_cast<T>(MinIndex);
2933+
for (unsigned I = 2; I != SourceLen; ++I) {
2934+
Dest.elem<T>(I) = static_cast<T>(APSInt(LaneBitWidth, DestUnsigned));
2935+
}
2936+
});
2937+
Dest.initializeAllElements();
2938+
return true;
2939+
}
2940+
29022941
static bool interp__builtin_ia32_pternlog(InterpState &S, CodePtr OpPC,
29032942
const CallExpr *Call, bool MaskZ) {
29042943
assert(Call->getNumArgs() == 5);
@@ -3875,6 +3914,10 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
38753914
S, OpPC, Call,
38763915
[](const APSInt &LHS, const APSInt &RHS) { return LHS + RHS; });
38773916

3917+
case X86::BI__builtin_ia32_phminposuw128: {
3918+
return interp__builtin_ia32_phminposuw(S, OpPC, Call);
3919+
}
3920+
38783921
case X86::BI__builtin_ia32_pternlogd128_mask:
38793922
case X86::BI__builtin_ia32_pternlogd256_mask:
38803923
case X86::BI__builtin_ia32_pternlogd512_mask:

clang/lib/AST/ExprConstant.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12220,6 +12220,40 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1222012220
return Success(R, E);
1222112221
}
1222212222

12223+
case X86::BI__builtin_ia32_phminposuw128: {
12224+
APValue Source;
12225+
if (!Evaluate(Source, Info, E->getArg(0)))
12226+
return false;
12227+
unsigned SourceLen = Source.getVectorLength();
12228+
const VectorType *VT = E->getArg(0)->getType()->castAs<VectorType>();
12229+
QualType ElemQT = VT->getElementType();
12230+
unsigned LaneBitWidth = Info.Ctx.getTypeSize(ElemQT);
12231+
12232+
APInt MinIndex(LaneBitWidth, 0);
12233+
APInt MinVal = Source.getVectorElt(0).getInt();
12234+
for (unsigned I = 0; I != SourceLen; ++I) {
12235+
APInt Val = Source.getVectorElt(I).getInt();
12236+
if (MinVal.ugt(Val)) {
12237+
MinVal = Val;
12238+
MinIndex = I;
12239+
}
12240+
}
12241+
12242+
bool ResultUnsigned = E->getCallReturnType(Info.Ctx)
12243+
->castAs<VectorType>()
12244+
->getElementType()
12245+
->isUnsignedIntegerOrEnumerationType();
12246+
12247+
SmallVector<APValue, 8> Result;
12248+
Result.reserve(SourceLen);
12249+
Result.emplace_back(APSInt(MinVal, ResultUnsigned));
12250+
Result.emplace_back(APSInt(MinIndex, ResultUnsigned));
12251+
for (unsigned I = 0; I != SourceLen - 2; ++I) {
12252+
Result.emplace_back(APSInt(APInt(LaneBitWidth, 0), ResultUnsigned));
12253+
}
12254+
return Success(APValue(Result.data(), Result.size()), E);
12255+
}
12256+
1222312257
case X86::BI__builtin_ia32_pternlogd128_mask:
1222412258
case X86::BI__builtin_ia32_pternlogd256_mask:
1222512259
case X86::BI__builtin_ia32_pternlogd512_mask:

clang/lib/Headers/smmintrin.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,8 @@ _mm_packus_epi32(__m128i __V1, __m128i __V2) {
15241524
/// \returns A 128-bit value where bits [15:0] contain the minimum value found
15251525
/// in parameter \a __V, bits [18:16] contain the index of the minimum value
15261526
/// and the remaining bits are set to 0.
1527-
static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_minpos_epu16(__m128i __V) {
1527+
static __inline__ __m128i __DEFAULT_FN_ATTRS_CONSTEXPR
1528+
_mm_minpos_epu16(__m128i __V) {
15281529
return (__m128i)__builtin_ia32_phminposuw128((__v8hi)__V);
15291530
}
15301531

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,16 @@ __m128i test_mm_minpos_epu16(__m128i x) {
376376
// CHECK: call <8 x i16> @llvm.x86.sse41.phminposuw(<8 x i16> %{{.*}})
377377
return _mm_minpos_epu16(x);
378378
}
379+
TEST_CONSTEXPR(match_v8hu(_mm_minpos_epu16((__m128i)(__v8hu){0,0,0,0, 0,0,0,0}), 0,0,0,0, 0,0,0,0));
380+
TEST_CONSTEXPR(match_v8hu(_mm_minpos_epu16((__m128i)(__v8hu){1,0,0,0, 0,0,0,0}), 0,1,0,0, 0,0,0,0));
381+
TEST_CONSTEXPR(match_v8hu(_mm_minpos_epu16((__m128i)(__v8hu){65535,65535,65535,65535,65535,65535,65535,65535}), 65535,0,0,0, 0,0,0,0));
382+
TEST_CONSTEXPR(match_v8hu(_mm_minpos_epu16((__m128i)(__v8hu){9,8,7,6,5,4,3,2}), 2,7,0,0, 0,0,0,0));
383+
TEST_CONSTEXPR(match_v8hu(_mm_minpos_epu16((__m128i)(__v8hu){5,5,5,5,5,5,5,5}), 5,0,0,0, 0,0,0,0));
384+
TEST_CONSTEXPR(match_v8hu(_mm_minpos_epu16((__m128i)(__v8hu){5,7,9,4,10,4,11,12}), 4,3,0,0, 0,0,0,0));
385+
TEST_CONSTEXPR(match_v8hu(_mm_minpos_epu16((__m128i)(__v8hu){6,0,0,0,0,0,0,0}), 0,1,0,0, 0,0,0,0));
386+
TEST_CONSTEXPR(match_v8hu(_mm_minpos_epu16((__m128i)(__v8hu){1000,2000,3000,4000,5000,6000,7000,1}), 1,7,0,0, 0,0,0,0));
387+
TEST_CONSTEXPR(match_v8hu(_mm_minpos_epu16((__m128i)(__v8hu){1234,5678,42,9999,65535,0,4242,42}), 0,5,0,0, 0,0,0,0));
388+
TEST_CONSTEXPR(match_v8hu(_mm_minpos_epu16((__m128i)(__v8hu){400,500,12,600,12,700,800,900}), 12,2,0,0, 0,0,0,0));
379389

380390
__m128i test_mm_mpsadbw_epu8(__m128i x, __m128i y) {
381391
// CHECK-LABEL: test_mm_mpsadbw_epu8

0 commit comments

Comments
 (0)