[clang] [X86][Clang] Add AVX512 Integer Comparison Intrinsics for constexpr Evaluation (PR #164026)

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 18 05:04:10 PDT 2025


================
@@ -3101,6 +3101,75 @@ static bool interp__builtin_vec_set(InterpState &S, CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_cmp_mask(InterpState &S, CodePtr OpPC,
+                                     const CallExpr *Call, unsigned ID,
+                                     bool IsUnsigned) {
+  assert(Call->getNumArgs() == 4);
+
+  APSInt Mask = popToAPSInt(S, Call->getArg(3));
+  APSInt Opcode = popToAPSInt(S, Call->getArg(2));
+  const Pointer &RHS = S.Stk.pop<Pointer>();
+  const Pointer &LHS = S.Stk.pop<Pointer>();
+
+  assert(LHS.getNumElems() == RHS.getNumElems());
+
+  APInt RetMask = APInt::getZero(LHS.getNumElems());
+  unsigned VectorLen = LHS.getNumElems();
+  PrimType ElemT = LHS.getFieldDesc()->getPrimType();
+
+    for (unsigned ElemNum = 0; ElemNum < VectorLen; ++ElemNum) {
+      INT_TYPE_SWITCH_NO_BOOL(ElemT, {
+        APSInt B = RHS.elem<T>(ElemNum).toAPSInt();
+        bool Result = false;
+        switch (Opcode.getExtValue() & 0x7) {
+        case 0x00: // _MM_CMPINT_EQ
+          Result = (LHS.elem<T>(ElemNum).toAPSInt() ==
----------------
RKSimon wrote:

Pull out the repeated elem<T>(ElemNum).toAPSInt() calls to top of the loop - that should reduce the size of this code considerably.

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


More information about the cfe-commits mailing list