Skip to content

Commit de0da09

Browse files
committed
Apply feedback from Simon and Timm
1 parent 4da5617 commit de0da09

File tree

2 files changed

+43
-65
lines changed

2 files changed

+43
-65
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,57 +2824,44 @@ static bool interp__builtin_ia32_test_op(
28242824
const Pointer &LHS = S.Stk.pop<Pointer>();
28252825

28262826
assert(LHS.getNumElems() == RHS.getNumElems());
2827+
28272828
assert(LHS.getFieldDesc()->isPrimitiveArray() &&
28282829
RHS.getFieldDesc()->isPrimitiveArray());
28292830

28302831
if (!S.getASTContext().hasSameUnqualifiedType(getElemType(LHS),
28312832
getElemType(RHS)))
28322833
return false;
28332834

2834-
const unsigned SourceLen = LHS.getNumElems();
2835+
unsigned SourceLen = LHS.getNumElems();
28352836
const QualType ElemQT = getElemType(LHS);
28362837
const OptPrimType ElemPT = S.getContext().classify(ElemQT);
2838+
unsigned LaneWidth = S.getASTContext().getTypeSize(ElemQT);
2839+
APInt SignMask = APInt::getSignMask(LaneWidth);
28372840

2838-
if (ElemQT->isIntegerType()) {
2839-
APInt FirstElem;
2840-
INT_TYPE_SWITCH_NO_BOOL(*ElemPT,
2841-
{ FirstElem = LHS.elem<T>(0).toAPSInt(); });
2842-
const unsigned LaneWidth = FirstElem.getBitWidth();
2841+
APInt AWide(LaneWidth * SourceLen, 0);
2842+
APInt BWide(LaneWidth * SourceLen, 0);
28432843

2844-
APInt AWide(LaneWidth * SourceLen, 0);
2845-
APInt BWide(LaneWidth * SourceLen, 0);
2844+
for (unsigned I = 0; I != SourceLen; ++I) {
2845+
APInt ALane;
2846+
APInt BLane;
28462847

2847-
for (unsigned I = 0; I != SourceLen; ++I) {
2848-
APInt ALane;
2849-
APInt BLane;
2848+
if (ElemQT->isIntegerType()) { // Get value
28502849
INT_TYPE_SWITCH_NO_BOOL(*ElemPT, {
28512850
ALane = LHS.elem<T>(I).toAPSInt();
28522851
BLane = RHS.elem<T>(I).toAPSInt();
28532852
});
2854-
AWide.insertBits(ALane, I * LaneWidth);
2855-
BWide.insertBits(BLane, I * LaneWidth);
2856-
}
2857-
pushInteger(S, Fn(AWide, BWide) ? 1 : 0, Call->getType());
2858-
return true;
2859-
} else if (ElemQT->isFloatingType()) {
2860-
APInt ASignBits(SourceLen, 0);
2861-
APInt BSignBits(SourceLen, 0);
2862-
2863-
for (unsigned I = 0; I != SourceLen; ++I) {
2853+
} else if (ElemQT->isFloatingType()) { // Get only sign bit
28642854
using T = PrimConv<PT_Float>::T;
2865-
APInt ALane = LHS.elem<T>(I).getAPFloat().bitcastToAPInt();
2866-
APInt BLane = RHS.elem<T>(I).getAPFloat().bitcastToAPInt();
2867-
const unsigned SignBit = ALane.getBitWidth() - 1;
2868-
const bool ALaneSign = ALane[SignBit];
2869-
const bool BLaneSign = BLane[SignBit];
2870-
ASignBits.setBitVal(I, ALaneSign);
2871-
BSignBits.setBitVal(I, BLaneSign);
2855+
ALane = LHS.elem<T>(I).getAPFloat().bitcastToAPInt() & SignMask;
2856+
BLane = RHS.elem<T>(I).getAPFloat().bitcastToAPInt() & SignMask;
2857+
} else { // Must be integer or floating type
2858+
return false;
28722859
}
2873-
pushInteger(S, Fn(ASignBits, BSignBits) ? 1 : 0, Call->getType());
2874-
return true;
2875-
} else { // Must be integer or float type
2876-
return false;
2860+
AWide.insertBits(ALane, I * LaneWidth);
2861+
BWide.insertBits(BLane, I * LaneWidth);
28772862
}
2863+
pushInteger(S, Fn(AWide, BWide), Call->getType());
2864+
return true;
28782865
}
28792866

28802867
static bool interp__builtin_elementwise_triop(

clang/lib/AST/ExprConstant.cpp

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13774,42 +13774,33 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1377413774
return false;
1377513775

1377613776
unsigned SourceLen = SourceLHS.getVectorLength();
13777-
1377813777
const VectorType *VT = E->getArg(0)->getType()->castAs<VectorType>();
13779-
QualType ElemQT = VT->getElementType();
13780-
13781-
if (ElemQT->isIntegerType()) {
13782-
const unsigned LaneWidth =
13783-
SourceLHS.getVectorElt(0).getInt().getBitWidth();
13784-
APInt AWide(LaneWidth * SourceLen, 0);
13785-
APInt BWide(LaneWidth * SourceLen, 0);
13786-
13787-
for (unsigned I = 0; I != SourceLen; ++I) {
13788-
APInt ALane = SourceLHS.getVectorElt(I).getInt();
13789-
APInt BLane = SourceRHS.getVectorElt(I).getInt();
13790-
AWide.insertBits(ALane, I * LaneWidth);
13791-
BWide.insertBits(BLane, I * LaneWidth);
13792-
}
13793-
return Success(Fn(AWide, BWide), E);
13794-
13795-
} else if (ElemQT->isFloatingType()) {
13796-
APInt ASignBits(SourceLen, 0);
13797-
APInt BSignBits(SourceLen, 0);
13798-
13799-
for (unsigned I = 0; I != SourceLen; ++I) {
13800-
APInt ALane = SourceLHS.getVectorElt(I).getFloat().bitcastToAPInt();
13801-
APInt BLane = SourceRHS.getVectorElt(I).getFloat().bitcastToAPInt();
13802-
const unsigned SignBit = ALane.getBitWidth() - 1;
13803-
const bool ALaneSign = ALane[SignBit];
13804-
const bool BLaneSign = BLane[SignBit];
13805-
ASignBits.setBitVal(I, ALaneSign);
13806-
BSignBits.setBitVal(I, BLaneSign);
13778+
const QualType ElemQT = VT->getElementType();
13779+
unsigned LaneWidth = Info.Ctx.getTypeSize(ElemQT);
13780+
APInt SignMask = APInt::getSignMask(LaneWidth);
13781+
13782+
APInt AWide(LaneWidth * SourceLen, 0);
13783+
APInt BWide(LaneWidth * SourceLen, 0);
13784+
13785+
for (unsigned I = 0; I != SourceLen; ++I) {
13786+
APInt ALane;
13787+
APInt BLane;
13788+
13789+
if (ElemQT->isIntegerType()) { // Get value
13790+
ALane = SourceLHS.getVectorElt(I).getInt();
13791+
BLane = SourceRHS.getVectorElt(I).getInt();
13792+
} else if (ElemQT->isFloatingType()) { // Get only sign bit
13793+
ALane = SourceLHS.getVectorElt(I).getFloat().bitcastToAPInt() &
13794+
SignMask;
13795+
BLane = SourceRHS.getVectorElt(I).getFloat().bitcastToAPInt() &
13796+
SignMask;
13797+
} else { // Must be integer or floating type
13798+
return false;
1380713799
}
13808-
return Success(Fn(ASignBits, BSignBits), E);
13809-
13810-
} else { // Must be integer or float type
13811-
return false;
13800+
AWide.insertBits(ALane, I * LaneWidth);
13801+
BWide.insertBits(BLane, I * LaneWidth);
1381213802
}
13803+
return Success(Fn(AWide, BWide), E);
1381313804
};
1381413805

1381513806
auto HandleMaskBinOp =

0 commit comments

Comments
 (0)