Skip to content

Commit 6f9bc73

Browse files
committed
use INT_TYPE_SWITCH_NO_BOOL and if instead of switch in vec_ext handler; consistently useElem
1 parent 0c07c06 commit 6f9bc73

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,22 +2887,22 @@ static bool interp__builtin_vec_ext(InterpState &S, CodePtr OpPC,
28872887
if (!Vec.getFieldDesc()->isPrimitiveArray())
28882888
return false;
28892889

2890-
unsigned NumElts = Vec.getNumElems();
2891-
unsigned Index = static_cast<unsigned>(ImmAPS.getZExtValue() & (NumElts - 1));
2890+
unsigned NumElems = Vec.getNumElems();
2891+
unsigned Index =
2892+
static_cast<unsigned>(ImmAPS.getZExtValue() & (NumElems - 1));
28922893

2893-
switch (ID) {
2894-
case X86::BI__builtin_ia32_vec_ext_v4sf:
2894+
PrimType ElemPT = Vec.getFieldDesc()->getPrimType();
2895+
// FIXME(#161685): Replace float+int split with a numeric-only type switch
2896+
if (ElemPT == PT_Float) {
28952897
S.Stk.push<Floating>(Vec.elem<Floating>(Index));
28962898
return true;
2897-
default: {
2898-
PrimType ElemPT = Vec.getFieldDesc()->getPrimType();
2899-
INT_TYPE_SWITCH_NO_BOOL(ElemPT, {
2900-
APSInt V = Vec.elem<T>(Index).toAPSInt();
2901-
pushInteger(S, V, Call->getType());
2902-
});
2903-
return true;
2904-
}
29052899
}
2900+
INT_TYPE_SWITCH_NO_BOOL(ElemPT, {
2901+
APSInt V = Vec.elem<T>(Index).toAPSInt();
2902+
pushInteger(S, V, Call->getType());
2903+
});
2904+
2905+
return true;
29062906
}
29072907

29082908
static bool interp__builtin_vec_set(InterpState &S, CodePtr OpPC,
@@ -2918,12 +2918,13 @@ static bool interp__builtin_vec_set(InterpState &S, CodePtr OpPC,
29182918

29192919
const Pointer &Dst = S.Stk.peek<Pointer>();
29202920

2921-
unsigned NumElts = Base.getNumElems();
2922-
unsigned Index = static_cast<unsigned>(ImmAPS.getZExtValue() & (NumElts - 1));
2921+
unsigned NumElems = Base.getNumElems();
2922+
unsigned Index =
2923+
static_cast<unsigned>(ImmAPS.getZExtValue() & (NumElems - 1));
29232924

29242925
PrimType ElemPT = Base.getFieldDesc()->getPrimType();
29252926
INT_TYPE_SWITCH_NO_BOOL(ElemPT, {
2926-
for (unsigned I = 0; I != NumElts; ++I)
2927+
for (unsigned I = 0; I != NumElems; ++I)
29272928
Dst.elem<T>(I) = Base.elem<T>(I);
29282929
Dst.elem<T>(Index) = static_cast<T>(ValAPS);
29292930
});

clang/lib/AST/ExprConstant.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12259,16 +12259,16 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1225912259
APSInt ElemAPS = Scalar.extOrTrunc(ElemWidth);
1226012260
APValue ElemAV(ElemAPS);
1226112261

12262-
unsigned NumElts = VecVal.getVectorLength();
12262+
unsigned NumElems = VecVal.getVectorLength();
1226312263
unsigned Index =
12264-
static_cast<unsigned>(IndexAPS.getZExtValue() & (NumElts - 1));
12264+
static_cast<unsigned>(IndexAPS.getZExtValue() & (NumElems - 1));
1226512265

12266-
SmallVector<APValue, 4> Elts;
12267-
Elts.reserve(NumElts);
12268-
for (unsigned EltNum = 0; EltNum != NumElts; ++EltNum)
12269-
Elts.push_back(EltNum == Index ? ElemAV : VecVal.getVectorElt(EltNum));
12266+
SmallVector<APValue, 4> Elems;
12267+
Elems.reserve(NumElems);
12268+
for (unsigned ElemNum = 0; ElemNum != NumElems; ++ElemNum)
12269+
Elems.push_back(ElemNum == Index ? ElemAV : VecVal.getVectorElt(ElemNum));
1227012270

12271-
return Success(APValue(Elts.data(), NumElts), E);
12271+
return Success(APValue(Elems.data(), NumElems), E);
1227212272
}
1227312273
}
1227412274
}

0 commit comments

Comments
 (0)