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

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 20 21:54:19 PDT 2025


================
@@ -3119,40 +3152,13 @@ static bool interp__builtin_cmp_mask(InterpState &S, CodePtr OpPC,
 
   for (unsigned ElemNum = 0; ElemNum < VectorLen; ++ElemNum) {
     INT_TYPE_SWITCH_NO_BOOL(ElemT, {
-      const APSInt &A = LHS.elem<T>(ElemNum).toAPSInt();
-      const APSInt &B = RHS.elem<T>(ElemNum).toAPSInt();
-      bool Result = false;
-      switch (Opcode.getExtValue() & 0x7) {
-      case 0x00: // _MM_CMPINT_EQ
-        Result = (A == B);
-        break;
-      case 0x01: // _MM_CMPINT_LT
-        Result = IsUnsigned ? A.ult(B) : A.slt(B);
-        break;
-      case 0x02: // _MM_CMPINT_LE
-        Result = IsUnsigned ? A.ule(B) : A.sle(B);
-        break;
-      case 0x03: // _MM_CMPINT_FALSE
-        Result = false;
-        break;
-      case 0x04: // _MM_CMPINT_NE
-        Result = (A != B);
-        break;
-      case 0x05: // _MM_CMPINT_NLT (>=)
-        Result = IsUnsigned ? A.uge(B) : A.sge(B);
-        break;
-      case 0x06: // _MM_CMPINT_NLE (>)
-        Result = IsUnsigned ? A.ugt(B) : A.sgt(B);
-        break;
-      case 0x07: // _MM_CMPINT_TRUE
-        Result = true;
-        break;
-      }
-
-      RetMask.setBitVal(ElemNum, Mask[ElemNum] && Result);
+      RetMask.setBitVal(ElemNum,
+                        Mask[ElemNum] &&
+                            evalICmpImm(CmpOp, LHS.elem<T>(ElemNum).toAPSInt(),
+                                        RHS.elem<T>(ElemNum).toAPSInt(),
+                                        IsUnsigned));
----------------
sskzakaria wrote:

I thought I should keep A and B const ref and :
```cpp
INT_TYPE_SWITCH_NO_BOOL(ElemT, {
  const APSInt &A = ...;
  const APSInt &B = ...;
})
bool Result = false;
...
```
Woudnt work, do I just remove the const ref and do that?

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


More information about the cfe-commits mailing list