[clang] [X86][Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - add SSE/AVX VPTEST/VTESTPD/VTESTPS intrinsics to be used in constexpr (PR #160428)
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 2 03:48:54 PDT 2025
================
@@ -2889,6 +2889,66 @@ static bool interp__builtin_blend(InterpState &S, CodePtr OpPC,
return true;
}
+static bool interp__builtin_ia32_test_op(
+ InterpState &S, CodePtr OpPC, const CallExpr *Call,
+ llvm::function_ref<bool(const APInt &A, const APInt &B)> Fn) {
+ const Pointer &RHS = S.Stk.pop<Pointer>();
+ const Pointer &LHS = S.Stk.pop<Pointer>();
+
+ assert(LHS.getNumElems() == RHS.getNumElems());
+ assert(LHS.getFieldDesc()->isPrimitiveArray() &&
+ RHS.getFieldDesc()->isPrimitiveArray());
+
+ if (!S.getASTContext().hasSameUnqualifiedType(getElemType(LHS),
+ getElemType(RHS)))
+ return false;
+
+ const unsigned SourceLen = LHS.getNumElems();
+ const QualType ElemQT = getElemType(LHS);
+ const OptPrimType ElemPT = S.getContext().classify(ElemQT);
+
+ if (ElemQT->isIntegerType()) {
+ APInt FirstElem;
+ INT_TYPE_SWITCH_NO_BOOL(*ElemPT,
+ { FirstElem = LHS.elem<T>(0).toAPSInt(); });
+ const unsigned LaneWidth = FirstElem.getBitWidth();
+
+ APInt AWide(LaneWidth * SourceLen, 0);
+ APInt BWide(LaneWidth * SourceLen, 0);
+
+ for (unsigned I = 0; I != SourceLen; ++I) {
+ APInt ALane;
+ APInt BLane;
+ INT_TYPE_SWITCH_NO_BOOL(*ElemPT, {
+ ALane = LHS.elem<T>(I).toAPSInt();
+ BLane = RHS.elem<T>(I).toAPSInt();
+ });
+ AWide.insertBits(ALane, I * LaneWidth);
+ BWide.insertBits(BLane, I * LaneWidth);
+ }
+ pushInteger(S, Fn(AWide, BWide) ? 1 : 0, Call->getType());
+ return true;
+ } else if (ElemQT->isFloatingType()) {
+ APInt ASignBits(SourceLen, 0);
+ APInt BSignBits(SourceLen, 0);
+
+ for (unsigned I = 0; I != SourceLen; ++I) {
+ using T = PrimConv<PT_Float>::T;
+ APInt ALane = LHS.elem<T>(I).getAPFloat().bitcastToAPInt();
+ APInt BLane = RHS.elem<T>(I).getAPFloat().bitcastToAPInt();
+ const unsigned SignBit = ALane.getBitWidth() - 1;
+ const bool ALaneSign = ALane[SignBit];
+ const bool BLaneSign = BLane[SignBit];
+ ASignBits.setBitVal(I, ALaneSign);
+ BSignBits.setBitVal(I, BLaneSign);
----------------
RKSimon wrote:
this would save a little space:
```
ASignBits.setBitVal(I, ALane.isNegative());
BSignBits.setBitVal(I, BLane.isNegative());
```
https://github.com/llvm/llvm-project/pull/160428
More information about the cfe-commits
mailing list