Skip to content

Commit 777bc01

Browse files
committed
Edits
1 parent 487266d commit 777bc01

File tree

3 files changed

+42
-43
lines changed

3 files changed

+42
-43
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,6 +2813,7 @@ static bool interp__builtin_select(InterpState &S, CodePtr OpPC,
28132813
}
28142814
}
28152815
Dst.initializeAllElements();
2816+
28162817
return true;
28172818
}
28182819

@@ -2821,20 +2822,19 @@ static bool interp__builtin_elementwise_fsh(InterpState &S, CodePtr OpPC,
28212822
unsigned BuiltinID) {
28222823
assert(Call->getNumArgs() == 3);
28232824

2824-
const QualType Arg1Type = Call->getArg(0)->getType();
2825-
const QualType Arg2Type = Call->getArg(1)->getType();
2826-
const QualType Arg3Type = Call->getArg(2)->getType();
2825+
const QualType &Arg1Type = Call->getArg(0)->getType();
2826+
const QualType &Arg2Type = Call->getArg(1)->getType();
2827+
const QualType &Arg3Type = Call->getArg(2)->getType();
28272828

28282829
// Non-vector integer types.
28292830
if (!Arg1Type->isVectorType()) {
28302831
assert(!Arg2Type->isVectorType());
28312832
assert(!Arg3Type->isVectorType());
2832-
2833-
APSInt Shift = popToAPSInt(
2833+
const APSInt &Shift = popToAPSInt(
28342834
S.Stk, *S.getContext().classify(Call->getArg(2)->getType()));
2835-
APSInt Lo = popToAPSInt(
2835+
const APSInt &Lo = popToAPSInt(
28362836
S.Stk, *S.getContext().classify(Call->getArg(1)->getType()));
2837-
APSInt Hi = popToAPSInt(
2837+
const APSInt &Hi = popToAPSInt(
28382838
S.Stk, *S.getContext().classify(Call->getArg(0)->getType()));
28392839
APSInt Result;
28402840
if (BuiltinID == Builtin::BI__builtin_elementwise_fshl) {
@@ -2849,18 +2849,17 @@ static bool interp__builtin_elementwise_fsh(InterpState &S, CodePtr OpPC,
28492849
}
28502850

28512851
// Vector type.
2852-
assert(Arg1Type->isVectorType() &&
2853-
Arg2Type->isVectorType() &&
2852+
assert(Arg1Type->isVectorType() && Arg2Type->isVectorType() &&
28542853
Arg3Type->isVectorType());
28552854

28562855
const VectorType *VecT = Arg1Type->castAs<VectorType>();
2857-
PrimType ElemT = *S.getContext().classify(VecT->getElementType());
2856+
const PrimType &ElemT = *S.getContext().classify(VecT->getElementType());
28582857
unsigned NumElems = VecT->getNumElements();
28592858

28602859
assert(VecT->getElementType() ==
2861-
Arg2Type->castAs<VectorType>()->getElementType() &&
2860+
Arg2Type->castAs<VectorType>()->getElementType() &&
28622861
VecT->getElementType() ==
2863-
Arg3Type->castAs<VectorType>()->getElementType());
2862+
Arg3Type->castAs<VectorType>()->getElementType());
28642863
assert(NumElems == Arg2Type->castAs<VectorType>()->getNumElements() &&
28652864
NumElems == Arg3Type->castAs<VectorType>()->getNumElements());
28662865
assert(VecT->getElementType()->isIntegralOrEnumerationType());
@@ -2870,26 +2869,27 @@ static bool interp__builtin_elementwise_fsh(InterpState &S, CodePtr OpPC,
28702869
const Pointer &VecHi = S.Stk.pop<Pointer>();
28712870
const Pointer &Dst = S.Stk.peek<Pointer>();
28722871
for (unsigned I = 0; I != NumElems; ++I) {
2873-
APSInt Hi;
2874-
APSInt Lo;
2875-
APSInt Shift;
2876-
INT_TYPE_SWITCH_NO_BOOL(ElemT, {
2877-
Hi = VecHi.elem<T>(I).toAPSInt();
2878-
Lo = VecLo.elem<T>(I).toAPSInt();
2879-
Shift = VecShift.elem<T>(I).toAPSInt();
2880-
});
2881-
APSInt Result;
2882-
if (BuiltinID == Builtin::BI__builtin_elementwise_fshl) {
2883-
Result = APSInt(llvm::APIntOps::fshl(Hi, Lo, Shift), Hi.isUnsigned());
2884-
} else if (BuiltinID == Builtin::BI__builtin_elementwise_fshr) {
2885-
Result = APSInt(llvm::APIntOps::fshr(Hi, Lo, Shift), Hi.isUnsigned());
2886-
} else {
2887-
llvm_unreachable("Wrong builtin ID");
2888-
}
2889-
INT_TYPE_SWITCH_NO_BOOL(ElemT,
2890-
{ Dst.elem<T>(I) = static_cast<T>(Result); });
2872+
APSInt Hi;
2873+
APSInt Lo;
2874+
APSInt Shift;
2875+
INT_TYPE_SWITCH_NO_BOOL(ElemT, {
2876+
Hi = VecHi.elem<T>(I).toAPSInt();
2877+
Lo = VecLo.elem<T>(I).toAPSInt();
2878+
Shift = VecShift.elem<T>(I).toAPSInt();
2879+
});
2880+
APSInt Result;
2881+
if (BuiltinID == Builtin::BI__builtin_elementwise_fshl) {
2882+
Result = APSInt(llvm::APIntOps::fshl(Hi, Lo, Shift), Hi.isUnsigned());
2883+
} else if (BuiltinID == Builtin::BI__builtin_elementwise_fshr) {
2884+
Result = APSInt(llvm::APIntOps::fshr(Hi, Lo, Shift), Hi.isUnsigned());
2885+
} else {
2886+
llvm_unreachable("Wrong builtin ID");
2887+
}
2888+
INT_TYPE_SWITCH_NO_BOOL(ElemT,
2889+
{ Dst.elem<T>(I) = static_cast<T>(Result); });
28912890
}
28922891
Dst.initializeAllElements();
2892+
28932893
return true;
28942894
}
28952895

clang/lib/AST/ExprConstant.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11950,25 +11950,27 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1195011950
!EvaluateAsRValue(Info, E->getArg(2), SourceShift))
1195111951
return false;
1195211952

11953-
QualType DestEltTy = E->getType()->castAs<VectorType>()->getElementType();
11953+
const QualType &DestEltTy =
11954+
E->getType()->castAs<VectorType>()->getElementType();
1195411955

1195511956
if (!DestEltTy->isIntegerType())
1195611957
return false;
1195711958

1195811959
unsigned SourceLen = SourceHi.getVectorLength();
1195911960
SmallVector<APValue> ResultElements;
1196011961
ResultElements.reserve(SourceLen);
11961-
1196211962
for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
11963-
APSInt Hi = SourceHi.getVectorElt(EltNum).getInt();
11964-
APSInt Lo = SourceLo.getVectorElt(EltNum).getInt();
11965-
APSInt Shift = SourceShift.getVectorElt(EltNum).getInt();
11963+
const APSInt &Hi = SourceHi.getVectorElt(EltNum).getInt();
11964+
const APSInt &Lo = SourceLo.getVectorElt(EltNum).getInt();
11965+
const APSInt &Shift = SourceShift.getVectorElt(EltNum).getInt();
1196611966
switch (E->getBuiltinCallee()) {
1196711967
case Builtin::BI__builtin_elementwise_fshl:
11968-
ResultElements.push_back(APValue(APSInt(llvm::APIntOps::fshl(Hi, Lo, Shift), Hi.isUnsigned())));
11968+
ResultElements.push_back(APValue(
11969+
APSInt(llvm::APIntOps::fshl(Hi, Lo, Shift), Hi.isUnsigned())));
1196911970
break;
1197011971
case Builtin::BI__builtin_elementwise_fshr:
11971-
ResultElements.push_back(APValue(APSInt(llvm::APIntOps::fshr(Hi, Lo, Shift), Hi.isUnsigned())));
11972+
ResultElements.push_back(APValue(
11973+
APSInt(llvm::APIntOps::fshr(Hi, Lo, Shift), Hi.isUnsigned())));
1197211974
break;
1197311975
}
1197411976
}
@@ -13915,15 +13917,12 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1391513917
}
1391613918
case Builtin::BI__builtin_elementwise_fshl:
1391713919
case Builtin::BI__builtin_elementwise_fshr: {
13918-
if (!E->getArg(0)->isPRValue() ||
13919-
!E->getArg(1)->isPRValue() ||
13920-
!E->getArg(2)->isPRValue())
13921-
return false;
1392213920
APSInt Hi, Lo, Shift;
1392313921
if (!EvaluateInteger(E->getArg(0), Hi, Info) ||
1392413922
!EvaluateInteger(E->getArg(1), Lo, Info) ||
1392513923
!EvaluateInteger(E->getArg(2), Shift, Info))
1392613924
return false;
13925+
1392713926
switch (BuiltinOp) {
1392813927
case Builtin::BI__builtin_elementwise_fshl: {
1392913928
APSInt Result(llvm::APIntOps::fshl(Hi, Lo, Shift), Hi.isUnsigned());

clang/test/Sema/constant-builtins-vector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,13 +986,11 @@ static_assert(__builtin_elementwise_fshr((unsigned long long)1844674407370955161
986986
static_assert(__builtin_elementwise_fshr((long long)9223372036854775807, (long long)0, (long long)64) == (long long)0);
987987
static_assert(__builtin_elementwise_fshr((unsigned long long)0, (unsigned long long)18446744073709551615ULL, (unsigned long long)64) == (unsigned long long)18446744073709551615ULL);
988988
static_assert(__builtin_elementwise_fshr((long long)0, (long long)9223372036854775807, (long long)64) == (long long)9223372036854775807);
989-
//
990989
static_assert(__builtin_elementwise_fshl((short) 1, (short) 2, (short) 3) == (short)8);
991990
static_assert(__builtin_elementwise_fshl((short) 2, (short) 1, (short) 3) == (short)16);
992991
static_assert(__builtin_elementwise_fshl(1, 2 , 2) == 4);
993992
static_assert(__builtin_elementwise_fshl(2L, 1L , 2L) == 8L);
994993
static_assert(__builtin_elementwise_fshr((unsigned char)1, (unsigned char)2, (unsigned char)3) == (unsigned char)32);
995-
//
996994
constexpr vector4uchar v4s_fshl_var =
997995
__builtin_elementwise_fshl((vector4uchar){255, 15, 0, 2},
998996
(vector4uchar){0, 15, 255, 1},
@@ -1009,3 +1007,5 @@ static_assert(v4s_fshr_var[0] == 254);
10091007
static_assert(v4s_fshr_var[1] == 225);
10101008
static_assert(v4s_fshr_var[2] == 255);
10111009
static_assert(v4s_fshr_var[3] == 32);
1010+
static_assert(__builtin_elementwise_fshl(v4s_fshl_var[0], v4s_fshl_var[1], v4s_fshl_var[2]) == 128);
1011+
static_assert(__builtin_elementwise_fshr(v4s_fshr_var[0], v4s_fshr_var[1], v4s_fshr_var[2]) == 253);

0 commit comments

Comments
 (0)