[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
Wed Sep 24 00:50:41 PDT 2025


================
@@ -3579,6 +3603,133 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
           return ((APInt)C).isNegative() ? T : F;
         });
 
+  case X86::BI__builtin_ia32_ptestz128:
+  case X86::BI__builtin_ia32_ptestz256:
+    return interp__builtin_test_op(
+        S, OpPC, Call,
+        [](const Pointer &LHS, const Pointer &RHS, const OptPrimType ElemPT,
+           const unsigned SourceLen) {
+          INT_TYPE_SWITCH_NO_BOOL(*ElemPT, {
+            for (unsigned I = 0; I < SourceLen; ++I) {
+              const APSInt A = LHS.elem<T>(I).toAPSInt();
+              const APSInt B = RHS.elem<T>(I).toAPSInt();
+              if (!((A & B) == 0)) {
+                return false;
+              }
+            }
+          });
+          return true;
+        });
----------------
RKSimon wrote:

It would be better if we can avoid having to perform the iteration inside the callback - can we not consistently convert the callbacks to any_of patterns? And detect bitcast float types before passing to a bool(APInt,APInt) call?

https://github.com/llvm/llvm-project/pull/160428


More information about the cfe-commits mailing list