[clang] [X86][Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow SSE/AVX COMI/UCOMI/CMPS/CMPP fp comparison intrinsics to be used in constexpr (PR #182589)

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 14 03:02:47 PDT 2026


================
@@ -4378,6 +4379,69 @@ static bool interp__builtin_ia32_gfni_mul(InterpState &S, CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_x86_comi(InterpState &S, CodePtr OpPC,
+                                     const InterpFrame *Frame,
+                                     const CallExpr *Call, unsigned ID,
+                                     uint64_t Predicate) {
+  const Pointer &VectorB = S.Stk.pop<Pointer>();
+  const Pointer &VectorA = S.Stk.pop<Pointer>();
+
+  if (VectorA.getNumElems() == 0 ||
+      VectorA.getNumElems() != VectorB.getNumElems())
+    return false;
+
+  llvm::APFloat A = VectorA.elem<Floating>(0).getAPFloat();
+  llvm::APFloat B = VectorB.elem<Floating>(0).getAPFloat();
+  bool Matches = MatchesPredicate(Predicate, A.compare(B));
+  pushInteger(S, Matches, Call->getType());
+  return true;
+}
+
+static bool interp__builtin_x86_cmp(InterpState &S, CodePtr OpPC,
+                                    const InterpFrame *Frame,
+                                    const CallExpr *Call, unsigned ID,
+                                    uint64_t Predicate, bool IsScalar) {
+  const Pointer &VectorB = S.Stk.pop<Pointer>();
+  const Pointer &VectorA = S.Stk.pop<Pointer>();
+  Pointer &Dst = S.Stk.peek<Pointer>();
+
+  unsigned NumLanes = VectorA.getNumElems();
----------------
RKSimon wrote:

we normally use NumElems

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


More information about the cfe-commits mailing list