[clang] [X86][Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - add AVX512 KTEST/KORTEST intrinsics to be used in constexpr (PR #166103)
Roberto Turrado Camblor via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 6 08:52:52 PST 2025
https://github.com/rturrado updated https://github.com/llvm/llvm-project/pull/166103
>From 084f456a91a2bcb921f84a19c367ccd9d5e05700 Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Sat, 1 Nov 2025 19:53:19 +0100
Subject: [PATCH 01/15] Mark instructions as _CONSTEXPR
---
clang/lib/Headers/avx512bwintrin.h | 24 ++++++++++++------------
clang/lib/Headers/avx512dqintrin.h | 18 +++++++++---------
clang/lib/Headers/avx512fintrin.h | 10 +++++-----
3 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/clang/lib/Headers/avx512bwintrin.h b/clang/lib/Headers/avx512bwintrin.h
index ac75b6ccde735..73e2679a908db 100644
--- a/clang/lib/Headers/avx512bwintrin.h
+++ b/clang/lib/Headers/avx512bwintrin.h
@@ -92,69 +92,69 @@ _kxor_mask64(__mmask64 __A, __mmask64 __B) {
return (__mmask64)__builtin_ia32_kxordi((__mmask64)__A, (__mmask64)__B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_kortestc_mask32_u8(__mmask32 __A, __mmask32 __B)
{
return (unsigned char)__builtin_ia32_kortestcsi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_kortestz_mask32_u8(__mmask32 __A, __mmask32 __B)
{
return (unsigned char)__builtin_ia32_kortestzsi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_kortest_mask32_u8(__mmask32 __A, __mmask32 __B, unsigned char *__C) {
*__C = (unsigned char)__builtin_ia32_kortestcsi(__A, __B);
return (unsigned char)__builtin_ia32_kortestzsi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_kortestc_mask64_u8(__mmask64 __A, __mmask64 __B) {
return (unsigned char)__builtin_ia32_kortestcdi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_kortestz_mask64_u8(__mmask64 __A, __mmask64 __B) {
return (unsigned char)__builtin_ia32_kortestzdi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_kortest_mask64_u8(__mmask64 __A, __mmask64 __B, unsigned char *__C) {
*__C = (unsigned char)__builtin_ia32_kortestcdi(__A, __B);
return (unsigned char)__builtin_ia32_kortestzdi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_ktestc_mask32_u8(__mmask32 __A, __mmask32 __B)
{
return (unsigned char)__builtin_ia32_ktestcsi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_ktestz_mask32_u8(__mmask32 __A, __mmask32 __B)
{
return (unsigned char)__builtin_ia32_ktestzsi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_ktest_mask32_u8(__mmask32 __A, __mmask32 __B, unsigned char *__C) {
*__C = (unsigned char)__builtin_ia32_ktestcsi(__A, __B);
return (unsigned char)__builtin_ia32_ktestzsi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_ktestc_mask64_u8(__mmask64 __A, __mmask64 __B) {
return (unsigned char)__builtin_ia32_ktestcdi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_ktestz_mask64_u8(__mmask64 __A, __mmask64 __B) {
return (unsigned char)__builtin_ia32_ktestzdi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_ktest_mask64_u8(__mmask64 __A, __mmask64 __B, unsigned char *__C) {
*__C = (unsigned char)__builtin_ia32_ktestcdi(__A, __B);
return (unsigned char)__builtin_ia32_ktestzdi(__A, __B);
diff --git a/clang/lib/Headers/avx512dqintrin.h b/clang/lib/Headers/avx512dqintrin.h
index fef1a2d64d538..92ffcc54cdf92 100644
--- a/clang/lib/Headers/avx512dqintrin.h
+++ b/clang/lib/Headers/avx512dqintrin.h
@@ -59,55 +59,55 @@ _kxor_mask8(__mmask8 __A, __mmask8 __B) {
return (__mmask8)__builtin_ia32_kxorqi((__mmask8)__A, (__mmask8)__B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_kortestc_mask8_u8(__mmask8 __A, __mmask8 __B)
{
return (unsigned char)__builtin_ia32_kortestcqi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_kortestz_mask8_u8(__mmask8 __A, __mmask8 __B)
{
return (unsigned char)__builtin_ia32_kortestzqi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_kortest_mask8_u8(__mmask8 __A, __mmask8 __B, unsigned char *__C) {
*__C = (unsigned char)__builtin_ia32_kortestcqi(__A, __B);
return (unsigned char)__builtin_ia32_kortestzqi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_ktestc_mask8_u8(__mmask8 __A, __mmask8 __B)
{
return (unsigned char)__builtin_ia32_ktestcqi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_ktestz_mask8_u8(__mmask8 __A, __mmask8 __B)
{
return (unsigned char)__builtin_ia32_ktestzqi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_ktest_mask8_u8(__mmask8 __A, __mmask8 __B, unsigned char *__C) {
*__C = (unsigned char)__builtin_ia32_ktestcqi(__A, __B);
return (unsigned char)__builtin_ia32_ktestzqi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_ktestc_mask16_u8(__mmask16 __A, __mmask16 __B)
{
return (unsigned char)__builtin_ia32_ktestchi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_ktestz_mask16_u8(__mmask16 __A, __mmask16 __B)
{
return (unsigned char)__builtin_ia32_ktestzhi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_ktest_mask16_u8(__mmask16 __A, __mmask16 __B, unsigned char *__C) {
*__C = (unsigned char)__builtin_ia32_ktestchi(__A, __B);
return (unsigned char)__builtin_ia32_ktestzhi(__A, __B);
diff --git a/clang/lib/Headers/avx512fintrin.h b/clang/lib/Headers/avx512fintrin.h
index 18c4a44a4c76e..0f9c712b200ba 100644
--- a/clang/lib/Headers/avx512fintrin.h
+++ b/clang/lib/Headers/avx512fintrin.h
@@ -8081,31 +8081,31 @@ _mm512_kor(__mmask16 __A, __mmask16 __B) {
return (__mmask16) __builtin_ia32_korhi ((__mmask16) __A, (__mmask16) __B);
}
-static __inline__ int __DEFAULT_FN_ATTRS
+static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
_mm512_kortestc (__mmask16 __A, __mmask16 __B)
{
return __builtin_ia32_kortestchi ((__mmask16) __A, (__mmask16) __B);
}
-static __inline__ int __DEFAULT_FN_ATTRS
+static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
_mm512_kortestz (__mmask16 __A, __mmask16 __B)
{
return __builtin_ia32_kortestzhi ((__mmask16) __A, (__mmask16) __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_kortestc_mask16_u8(__mmask16 __A, __mmask16 __B)
{
return (unsigned char)__builtin_ia32_kortestchi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_kortestz_mask16_u8(__mmask16 __A, __mmask16 __B)
{
return (unsigned char)__builtin_ia32_kortestzhi(__A, __B);
}
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
+static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
_kortest_mask16_u8(__mmask16 __A, __mmask16 __B, unsigned char *__C) {
*__C = (unsigned char)__builtin_ia32_kortestchi(__A, __B);
return (unsigned char)__builtin_ia32_kortestzhi(__A, __B);
>From f81db1a818357d0c2e80edd595a44041a70ea10f Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Sat, 1 Nov 2025 20:42:36 +0100
Subject: [PATCH 02/15] Mark builtin instructions as ConstExpr
---
clang/include/clang/Basic/BuiltinsX86.td | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/clang/include/clang/Basic/BuiltinsX86.td b/clang/include/clang/Basic/BuiltinsX86.td
index 500aa85fe5356..0b1c9b3dbfdc3 100644
--- a/clang/include/clang/Basic/BuiltinsX86.td
+++ b/clang/include/clang/Basic/BuiltinsX86.td
@@ -3193,31 +3193,31 @@ let Features = "avx512bw", Attributes = [NoThrow, Const, Constexpr] in {
def kordi : X86Builtin<"unsigned long long int(unsigned long long int, unsigned long long int)">;
}
-let Features = "avx512dq", Attributes = [NoThrow, Const] in {
+let Features = "avx512dq", Attributes = [NoThrow, Const, Constexpr] in {
def kortestcqi : X86Builtin<"int(unsigned char, unsigned char)">;
def kortestzqi : X86Builtin<"int(unsigned char, unsigned char)">;
}
-let Features = "avx512f", Attributes = [NoThrow, Const] in {
+let Features = "avx512f", Attributes = [NoThrow, Const, Constexpr] in {
def kortestchi : X86Builtin<"int(unsigned short, unsigned short)">;
def kortestzhi : X86Builtin<"int(unsigned short, unsigned short)">;
}
-let Features = "avx512bw", Attributes = [NoThrow, Const] in {
+let Features = "avx512bw", Attributes = [NoThrow, Const, Constexpr] in {
def kortestcsi : X86Builtin<"int(unsigned int, unsigned int)">;
def kortestzsi : X86Builtin<"int(unsigned int, unsigned int)">;
def kortestcdi : X86Builtin<"int(unsigned long long int, unsigned long long int)">;
def kortestzdi : X86Builtin<"int(unsigned long long int, unsigned long long int)">;
}
-let Features = "avx512dq", Attributes = [NoThrow, Const] in {
+let Features = "avx512dq", Attributes = [NoThrow, Const, Constexpr] in {
def ktestcqi : X86Builtin<"int(unsigned char, unsigned char)">;
def ktestzqi : X86Builtin<"int(unsigned char, unsigned char)">;
def ktestchi : X86Builtin<"int(unsigned short, unsigned short)">;
def ktestzhi : X86Builtin<"int(unsigned short, unsigned short)">;
}
-let Features = "avx512bw", Attributes = [NoThrow, Const] in {
+let Features = "avx512bw", Attributes = [NoThrow, Const, Constexpr] in {
def ktestcsi : X86Builtin<"int(unsigned int, unsigned int)">;
def ktestzsi : X86Builtin<"int(unsigned int, unsigned int)">;
def ktestcdi : X86Builtin<"int(unsigned long long int, unsigned long long int)">;
>From 59b7e414c2bb7d68bfd321fcfcec304a2413051a Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Sun, 2 Nov 2025 00:00:29 +0100
Subject: [PATCH 03/15] Update InterpretBuiltin function
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 32 ++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index ab6b3ed1be0aa..8a5dd13cc438c 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -3792,6 +3792,38 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
return Result;
});
+ case clang::X86::BI__builtin_ia32_ktestcsi:
+ case clang::X86::BI__builtin_ia32_ktestcdi:
+ return interp__builtin_elementwise_int_binop(
+ S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
+ return (!A & B) == 0;
+ });
+
+ case clang::X86::BI__builtin_ia32_ktestzsi:
+ case clang::X86::BI__builtin_ia32_ktestzsi:
+ return interp__builtin_elementwise_int_binop(
+ S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
+ return (A & B) == 0;
+ });
+
+ case clang::X86::BI__builtin_ia32_kortestchi:
+ case clang::X86::BI__builtin_ia32_kortestcsi:
+ case clang::X86::BI__builtin_ia32_kortestcdi:
+ case clang::X86::BI__builtin_ia32_kortestcqi:
+ return interp__builtin_elementwise_int_binop(
+ S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
+ return ~(A | B) == 0;
+ });
+
+ case clang::X86::BI__builtin_ia32_kortestzhi:
+ case clang::X86::BI__builtin_ia32_kortestzsi:
+ case clang::X86::BI__builtin_ia32_kortestzdi:
+ case clang::X86::BI__builtin_ia32_kortestzqi:
+ return interp__builtin_elementwise_int_binop(
+ S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
+ return (A | B) == 0);
+ });
+
case clang::X86::BI__builtin_ia32_lzcnt_u16:
case clang::X86::BI__builtin_ia32_lzcnt_u32:
case clang::X86::BI__builtin_ia32_lzcnt_u64:
>From 02dd3b771053f471d7c410a27b9cd7e73a70d108 Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Sun, 2 Nov 2025 22:23:29 +0100
Subject: [PATCH 04/15] Add constexpr tests
---
clang/test/CodeGen/X86/avx512bw-builtins.c | 78 ++++++++++++++++++++++
clang/test/CodeGen/X86/avx512dq-builtins.c | 60 +++++++++++++++++
clang/test/CodeGen/X86/avx512f-builtins.c | 38 +++++++++++
3 files changed, 176 insertions(+)
diff --git a/clang/test/CodeGen/X86/avx512bw-builtins.c b/clang/test/CodeGen/X86/avx512bw-builtins.c
index be2cd480f7558..d00cb33824e61 100644
--- a/clang/test/CodeGen/X86/avx512bw-builtins.c
+++ b/clang/test/CodeGen/X86/avx512bw-builtins.c
@@ -209,6 +209,10 @@ unsigned char test_kortestz_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m
_mm512_cmpneq_epu16_mask(__C, __D));
}
+TEST_CONSTEXPR(_kortestz_mask32_u8(0x0000'0000, 0x0000'0000) == 1);
+TEST_CONSTEXPR(_kortestz_mask32_u8(0x0000'0000, 0x8000'0000) == 0);
+TEST_CONSTEXPR(_kortestz_mask32_u8(0x0123'4567, 0xFEDC'BA98) == 0);
+
unsigned char test_kortestc_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_kortestc_mask32_u8
// CHECK: [[LHS:%.*]] = bitcast i32 %{{.*}} to <32 x i1>
@@ -222,6 +226,10 @@ unsigned char test_kortestc_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m
_mm512_cmpneq_epu16_mask(__C, __D));
}
+TEST_CONSTEXPR(_kortestc_mask32_u8(0x0000'0000, 0x0000'0000) == 0);
+TEST_CONSTEXPR(_kortestc_mask32_u8(0x0000'0000, 0x8000'0000) == 0);
+TEST_CONSTEXPR(_kortestc_mask32_u8(0x0123'4567, 0xFEDC'BA98) == 1);
+
unsigned char test_kortest_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D, unsigned char *CF) {
// CHECK-LABEL: test_kortest_mask32_u8
// CHECK: [[LHS:%.*]] = bitcast i32 %{{.*}} to <32 x i1>
@@ -242,6 +250,16 @@ unsigned char test_kortest_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m5
_mm512_cmpneq_epu16_mask(__C, __D), CF);
}
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_kortest_mask32_u8() {
+ unsigned char all_ones = 0;
+ return (_kortest_mask32_u8(0x0000'0000, 0x0000'0000, &all_ones) == 1) && (all_ones == 0)
+ && (_kortest_mask32_u8(0x0000'0000, 0x8000'0000, &all_ones) == 0) && (all_ones == 0)
+ && (_kortest_mask32_u8(0x0123'4567, 0xFEDC'BA98, &all_ones) == 0) && (all_ones == 1)
+ ;
+}
+#endif
+
unsigned char test_kortestz_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_kortestz_mask64_u8
// CHECK: [[LHS:%.*]] = bitcast i64 %{{.*}} to <64 x i1>
@@ -255,6 +273,10 @@ unsigned char test_kortestz_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m
_mm512_cmpneq_epu8_mask(__C, __D));
}
+TEST_CONSTEXPR(_kortestz_mask64_u8(0x0000'0000'0000'0000, 0x0000'0000'0000'0000) == 1);
+TEST_CONSTEXPR(_kortestz_mask64_u8(0x0000'0000'0000'0000, 0x8000'0000'0000'0000) == 0);
+TEST_CONSTEXPR(_kortestz_mask64_u8(0x0123'4567'89AB'CDEF, 0xFEDC'BA98'7654'3210) == 0);
+
unsigned char test_kortestc_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_kortestc_mask64_u8
// CHECK: [[LHS:%.*]] = bitcast i64 %{{.*}} to <64 x i1>
@@ -268,6 +290,10 @@ unsigned char test_kortestc_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m
_mm512_cmpneq_epu8_mask(__C, __D));
}
+TEST_CONSTEXPR(_kortestc_mask64_u8(0x0000'0000'0000'0000, 0x0000'0000'0000'0000) == 0);
+TEST_CONSTEXPR(_kortestc_mask64_u8(0x0023'4567'89AB'CDEF, 0xFEDC'BA98'7654'3210) == 0);
+TEST_CONSTEXPR(_kortestc_mask64_u8(0x0123'4567'89AB'CDEF, 0xFEDC'BA98'7654'3210) == 1);
+
unsigned char test_kortest_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D, unsigned char *CF) {
// CHECK-LABEL: test_kortest_mask64_u8
// CHECK: [[LHS:%.*]] = bitcast i64 %{{.*}} to <64 x i1>
@@ -288,6 +314,16 @@ unsigned char test_kortest_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m5
_mm512_cmpneq_epu8_mask(__C, __D), CF);
}
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_kortest_mask64_u8() {
+ unsigned char all_ones = 0;
+ return (_kortest_mask64_u8(0x0000'0000'0000'0000, 0x0000'0000'0000'0000, &all_ones) == 1) && (all_ones == 0)
+ && (_kortest_mask64_u8(0x0000'0000'0000'0000, 0x8000'0000'0000'0000, &all_ones) == 0) && (all_ones == 0)
+ && (_kortest_mask64_u8(0x0123'4567'89AB'CDEF, 0xFEDC'BA98'7654'3210, &all_ones) == 0) && (all_ones == 1)
+ ;
+}
+#endif
+
unsigned char test_ktestz_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_ktestz_mask32_u8
// CHECK: [[LHS:%.*]] = bitcast i32 %{{.*}} to <32 x i1>
@@ -298,6 +334,11 @@ unsigned char test_ktestz_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m51
_mm512_cmpneq_epu16_mask(__C, __D));
}
+TEST_CONSTEXPR(_ktestz_mask32_u8(0x0000'0000, 0x0000'0000) == 1);
+TEST_CONSTEXPR(_ktestz_mask32_u8(0x0000'0000, 0x8000'0000) == 1);
+TEST_CONSTEXPR(_ktestz_mask32_u8(0xF000'0000, 0x8000'0000) == 0);
+TEST_CONSTEXPR(_ktestz_mask32_u8(0x0123'4567, 0x0123'4567) == 0);
+
unsigned char test_ktestc_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_ktestc_mask32_u8
// CHECK: [[LHS:%.*]] = bitcast i32 %{{.*}} to <32 x i1>
@@ -308,6 +349,11 @@ unsigned char test_ktestc_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m51
_mm512_cmpneq_epu16_mask(__C, __D));
}
+TEST_CONSTEXPR(_ktestc_mask32_u8(0x0000'0000, 0x0000'0000) == 1);
+TEST_CONSTEXPR(_ktestc_mask32_u8(0x0000'0000, 0x8000'0000) == 0);
+TEST_CONSTEXPR(_ktestc_mask32_u8(0xF000'0000, 0x8000'0000) == 1);
+TEST_CONSTEXPR(_ktestc_mask32_u8(0x0123'4567, 0x0123'4567) == 1);
+
unsigned char test_ktest_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D, unsigned char *CF) {
// CHECK-LABEL: test_ktest_mask32_u8
// CHECK: [[LHS:%.*]] = bitcast i32 %{{.*}} to <32 x i1>
@@ -322,6 +368,17 @@ unsigned char test_ktest_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m512
_mm512_cmpneq_epu16_mask(__C, __D), CF);
}
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_ktest_mask32_u8() {
+ unsigned char and_not = 0;
+ return (_ktest_mask32_u8(0x0000'0000, 0x0000'0000, &and_not) == 1) && (and_not == 1)
+ && (_ktest_mask32_u8(0x0000'0000, 0x8000'0000, &and_not) == 1) && (and_not == 0)
+ && (_ktest_mask32_u8(0xF000'0000, 0x8000'0000, &and_not) == 0) && (and_not == 1)
+ && (_ktest_mask32_u8(0x0123'4567, 0x0123'4567, &and_not) == 0) && (and_not == 1)
+ ;
+}
+#endif
+
unsigned char test_ktestz_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_ktestz_mask64_u8
// CHECK: [[LHS:%.*]] = bitcast i64 %{{.*}} to <64 x i1>
@@ -332,6 +389,11 @@ unsigned char test_ktestz_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m51
_mm512_cmpneq_epu8_mask(__C, __D));
}
+TEST_CONSTEXPR(_ktestz_mask64_u8(0x0000'0000'0000'0000, 0x0000'0000'0000'0000) == 1);
+TEST_CONSTEXPR(_ktestz_mask64_u8(0x0000'0000'0000'0000, 0x8000'0000'0000'0000) == 1);
+TEST_CONSTEXPR(_ktestz_mask64_u8(0xF000'0000'0000'0000, 0x8000'0000'0000'0000) == 0);
+TEST_CONSTEXPR(_ktestz_mask64_u8(0x0123'4567'89AB'CDEF, 0x0123'4567'89AB'CDEF) == 0);
+
unsigned char test_ktestc_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_ktestc_mask64_u8
// CHECK: [[LHS:%.*]] = bitcast i64 %{{.*}} to <64 x i1>
@@ -342,6 +404,11 @@ unsigned char test_ktestc_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m51
_mm512_cmpneq_epu8_mask(__C, __D));
}
+TEST_CONSTEXPR(_ktestc_mask64_u8(0x0000'0000'0000'0000, 0x0000'0000'0000'0000) == 1);
+TEST_CONSTEXPR(_ktestc_mask64_u8(0x0000'0000'0000'0000, 0x8000'0000'0000'0000) == 0);
+TEST_CONSTEXPR(_ktestc_mask64_u8(0xF000'0000'0000'0000, 0x8000'0000'0000'0000) == 1);
+TEST_CONSTEXPR(_ktestc_mask64_u8(0x0123'4567'89AB'CDEF, 0x0123'4567'89AB'CDEF) == 1);
+
unsigned char test_ktest_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D, unsigned char *CF) {
// CHECK-LABEL: test_ktest_mask64_u8
// CHECK: [[LHS:%.*]] = bitcast i64 %{{.*}} to <64 x i1>
@@ -356,6 +423,17 @@ unsigned char test_ktest_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m512
_mm512_cmpneq_epu8_mask(__C, __D), CF);
}
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_ktest_mask64_u8() {
+ unsigned char and_not = 0;
+ return (_ktest_mask64_u8(0x0000'0000'0000'0000, 0x0000'0000'0000'0000, &and_not) == 1) && (and_not == 1)
+ && (_ktest_mask64_u8(0x0000'0000'0000'0000, 0x8000'0000'0000'0000, &and_not) == 1) && (and_not == 0)
+ && (_ktest_mask64_u8(0xF000'0000'0000'0000, 0x8000'0000'0000'0000, &and_not) == 0) && (and_not == 1)
+ && (_ktest_mask64_u8(0x0123'4567'89AB'CDEF, 0x0123'4567'89AB'CDEF, &and_not) == 0) && (and_not == 1)
+ ;
+}
+#endif
+
__mmask32 test_kadd_mask32(__m512i __A, __m512i __B, __m512i __C, __m512i __D, __m512i __E, __m512i __F) {
// CHECK-LABEL: test_kadd_mask32
// CHECK: [[LHS:%.*]] = bitcast i32 %{{.*}} to <32 x i1>
diff --git a/clang/test/CodeGen/X86/avx512dq-builtins.c b/clang/test/CodeGen/X86/avx512dq-builtins.c
index 9c4ada3a2b7b8..32ee13023dbd4 100644
--- a/clang/test/CodeGen/X86/avx512dq-builtins.c
+++ b/clang/test/CodeGen/X86/avx512dq-builtins.c
@@ -117,6 +117,10 @@ unsigned char test_kortestz_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m5
_mm512_cmpneq_epu64_mask(__C, __D));
}
+TEST_CONSTEXPR(_kortestz_mask8_u8(0x00, 0x00) == 1);
+TEST_CONSTEXPR(_kortestz_mask8_u8(0x00, 0x80) == 0);
+TEST_CONSTEXPR(_kortestz_mask8_u8(0x01, 0xFE) == 0);
+
unsigned char test_kortestc_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_kortestc_mask8_u8
// CHECK: [[LHS:%.*]] = bitcast i8 %{{.*}} to <8 x i1>
@@ -130,6 +134,10 @@ unsigned char test_kortestc_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m5
_mm512_cmpneq_epu64_mask(__C, __D));
}
+TEST_CONSTEXPR(_kortestc_mask8_u8(0x00, 0x00) == 0);
+TEST_CONSTEXPR(_kortestc_mask8_u8(0x00, 0x80) == 0);
+TEST_CONSTEXPR(_kortestc_mask8_u8(0x01, 0xFE) == 1);
+
unsigned char test_kortest_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D, unsigned char *CF) {
// CHECK-LABEL: test_kortest_mask8_u8
// CHECK: [[LHS:%.*]] = bitcast i8 %{{.*}} to <8 x i1>
@@ -150,6 +158,16 @@ unsigned char test_kortest_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m51
_mm512_cmpneq_epu64_mask(__C, __D), CF);
}
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_kortest_mask8_u8() {
+ unsigned char all_ones = 0;
+ return (_kortest_mask8_u8(0x00, 0x00, &all_ones) == 1) && (all_ones == 0)
+ && (_kortest_mask8_u8(0x00, 0x80, &all_ones) == 0) && (all_ones == 0)
+ && (_kortest_mask8_u8(0x01, 0xFE, &all_ones) == 0) && (all_ones == 1)
+ ;
+}
+#endif
+
unsigned char test_ktestz_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_ktestz_mask8_u8
// CHECK: [[LHS:%.*]] = bitcast i8 %{{.*}} to <8 x i1>
@@ -160,6 +178,11 @@ unsigned char test_ktestz_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m512
_mm512_cmpneq_epu64_mask(__C, __D));
}
+TEST_CONSTEXPR(_ktestz_mask8_u8(0x00, 0x00) == 1);
+TEST_CONSTEXPR(_ktestz_mask8_u8(0x00, 0x80) == 1);
+TEST_CONSTEXPR(_ktestz_mask8_u8(0xF0, 0x80) == 0);
+TEST_CONSTEXPR(_ktestz_mask8_u8(0x01, 0x01) == 0);
+
unsigned char test_ktestc_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_ktestc_mask8_u8
// CHECK: [[LHS:%.*]] = bitcast i8 %{{.*}} to <8 x i1>
@@ -170,6 +193,11 @@ unsigned char test_ktestc_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m512
_mm512_cmpneq_epu64_mask(__C, __D));
}
+TEST_CONSTEXPR(_ktestc_mask8_u8(0x00, 0x00) == 1);
+TEST_CONSTEXPR(_ktestc_mask8_u8(0x00, 0x80) == 0);
+TEST_CONSTEXPR(_ktestc_mask8_u8(0xF0, 0x80) == 1);
+TEST_CONSTEXPR(_ktestc_mask8_u8(0x01, 0x01) == 1);
+
unsigned char test_ktest_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D, unsigned char *CF) {
// CHECK-LABEL: test_ktest_mask8_u8
// CHECK: [[LHS:%.*]] = bitcast i8 %{{.*}} to <8 x i1>
@@ -184,6 +212,17 @@ unsigned char test_ktest_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m512i
_mm512_cmpneq_epu64_mask(__C, __D), CF);
}
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_ktest_mask8_u8() {
+ unsigned char and_not = 0;
+ return (_ktest_mask8_u8(0x00, 0x00, &and_not) == 1) && (and_not == 1)
+ && (_ktest_mask8_u8(0x00, 0x80, &and_not) == 1) && (and_not == 0)
+ && (_ktest_mask8_u8(0xF0, 0x80, &and_not) == 0) && (and_not == 1)
+ && (_ktest_mask8_u8(0x01, 0x01, &and_not) == 0) && (and_not == 1)
+ ;
+}
+#endif
+
unsigned char test_ktestz_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_ktestz_mask16_u8
// CHECK: [[LHS:%.*]] = bitcast i16 %{{.*}} to <16 x i1>
@@ -194,6 +233,11 @@ unsigned char test_ktestz_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m51
_mm512_cmpneq_epu32_mask(__C, __D));
}
+TEST_CONSTEXPR(_ktestz_mask16_u8(0x0000, 0x0000) == 1);
+TEST_CONSTEXPR(_ktestz_mask16_u8(0x0000, 0x8000) == 1);
+TEST_CONSTEXPR(_ktestz_mask16_u8(0xF000, 0x8000) == 0);
+TEST_CONSTEXPR(_ktestz_mask16_u8(0x0123, 0x0123) == 0);
+
unsigned char test_ktestc_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_ktestc_mask16_u8
// CHECK: [[LHS:%.*]] = bitcast i16 %{{.*}} to <16 x i1>
@@ -204,6 +248,11 @@ unsigned char test_ktestc_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m51
_mm512_cmpneq_epu32_mask(__C, __D));
}
+TEST_CONSTEXPR(_ktestc_mask16_u8(0x0000, 0x0000) == 1);
+TEST_CONSTEXPR(_ktestc_mask16_u8(0x0000, 0x8000) == 0);
+TEST_CONSTEXPR(_ktestc_mask16_u8(0xF000, 0x8000) == 1);
+TEST_CONSTEXPR(_ktestc_mask16_u8(0x0123, 0x0123) == 1);
+
unsigned char test_ktest_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D, unsigned char *CF) {
// CHECK-LABEL: test_ktest_mask16_u8
// CHECK: [[LHS:%.*]] = bitcast i16 %{{.*}} to <16 x i1>
@@ -218,6 +267,17 @@ unsigned char test_ktest_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m512
_mm512_cmpneq_epu32_mask(__C, __D), CF);
}
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_ktest_mask16_u8() {
+ unsigned char and_not = 0;
+ return (_ktest_mask16_u8(0x0000, 0x0000, &and_not) == 1) && (and_not == 1)
+ && (_ktest_mask16_u8(0x0000, 0x8000, &and_not) == 1) && (and_not == 0)
+ && (_ktest_mask16_u8(0xF000, 0x8000, &and_not) == 0) && (and_not == 1)
+ && (_ktest_mask16_u8(0x0123, 0x0123, &and_not) == 0) && (and_not == 1)
+ ;
+}
+#endif
+
__mmask8 test_kadd_mask8(__m512i __A, __m512i __B, __m512i __C, __m512i __D, __m512i __E, __m512i __F) {
// CHECK-LABEL: test_kadd_mask8
// CHECK: [[LHS:%.*]] = bitcast i8 %{{.*}} to <8 x i1>
diff --git a/clang/test/CodeGen/X86/avx512f-builtins.c b/clang/test/CodeGen/X86/avx512f-builtins.c
index 69599379b6b3d..582f2cbbf2dd5 100644
--- a/clang/test/CodeGen/X86/avx512f-builtins.c
+++ b/clang/test/CodeGen/X86/avx512f-builtins.c
@@ -8965,6 +8965,16 @@ int test_mm512_kortestc(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
_mm512_cmpneq_epu32_mask(__C, __D));
}
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_mm512_kortestc() {
+ // TODO: should I check for carry flag set/unset here, and if so, how?
+ return (_mm512_kortestc(0x0000, 0x0000) == 0x0000)
+ && (_mm512_kortestc(0x0000, 0x8000) == 0x8000)
+ && (_mm512_kortestc(0x0123, 0xFEDC) == 0xFFFF)
+ ;
+}
+#endif
+
int test_mm512_kortestz(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_mm512_kortestz
// CHECK: [[LHS:%.*]] = bitcast i16 %{{.*}} to <16 x i1>
@@ -8977,6 +8987,16 @@ int test_mm512_kortestz(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
_mm512_cmpneq_epu32_mask(__C, __D));
}
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_mm512_kortestz() {
+ // TODO: should I check for zero flag set/unset here, and if so, how?
+ return (_mm512_kortestz(0x0000, 0x0000) == 0x0000)
+ && (_mm512_kortestz(0x0000, 0x8000) == 0x8000)
+ && (_mm512_kortestz(0x0123, 0xFEDC) == 0xFFFF)
+ ;
+}
+#endif
+
unsigned char test_kortestz_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_kortestz_mask16_u8
// CHECK: [[LHS:%.*]] = bitcast i16 %{{.*}} to <16 x i1>
@@ -8990,6 +9010,10 @@ unsigned char test_kortestz_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m
_mm512_cmpneq_epu32_mask(__C, __D));
}
+TEST_CONSTEXPR(_kortestz_mask16_u8(0x0000, 0x0000) == 1);
+TEST_CONSTEXPR(_kortestz_mask16_u8(0x0000, 0x8000) == 0);
+TEST_CONSTEXPR(_kortestz_mask16_u8(0x0123, 0xFEDC) == 0);
+
unsigned char test_kortestc_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_kortestc_mask16_u8
// CHECK: [[LHS:%.*]] = bitcast i16 %{{.*}} to <16 x i1>
@@ -9003,6 +9027,10 @@ unsigned char test_kortestc_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m
_mm512_cmpneq_epu32_mask(__C, __D));
}
+TEST_CONSTEXPR(_kortestc_mask16_u8(0x0000, 0x0000) == 0);
+TEST_CONSTEXPR(_kortestc_mask16_u8(0x0000, 0x8000) == 0);
+TEST_CONSTEXPR(_kortestc_mask16_u8(0x0123, 0xFEDC) == 1);
+
unsigned char test_kortest_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D, unsigned char *CF) {
// CHECK-LABEL: test_kortest_mask16_u8
// CHECK: [[LHS:%.*]] = bitcast i16 %{{.*}} to <16 x i1>
@@ -9023,6 +9051,16 @@ unsigned char test_kortest_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m5
_mm512_cmpneq_epu32_mask(__C, __D), CF);
}
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_kortest_mask16_u8() {
+ unsigned char all_ones = 0;
+ return (_kortest_mask16_u8(0x0000, 0x0000, &all_ones) == 1) && (all_ones == 0)
+ && (_kortest_mask16_u8(0x0000, 0x8000, &all_ones) == 0) && (all_ones == 0)
+ && (_kortest_mask16_u8(0x0123, 0xFEDC, &all_ones) == 0) && (all_ones == 1)
+ ;
+}
+#endif
+
__mmask16 test_mm512_kunpackb(__m512i __A, __m512i __B, __m512i __C, __m512i __D, __m512i __E, __m512i __F) {
// CHECK-LABEL: test_mm512_kunpackb
// CHECK: [[LHS:%.*]] = bitcast i16 %{{.*}} to <16 x i1>
>From f704119a117ded6047774da38f1a8d5767160326 Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Sun, 2 Nov 2025 22:35:26 +0100
Subject: [PATCH 05/15] Run git-clang-format
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 20 ++++++++------------
clang/lib/Headers/avx512bwintrin.h | 12 ++++--------
clang/lib/Headers/avx512dqintrin.h | 18 ++++++------------
clang/lib/Headers/avx512fintrin.h | 12 ++++--------
4 files changed, 22 insertions(+), 40 deletions(-)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 8a5dd13cc438c..077f263a1bcb3 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -3795,34 +3795,30 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case clang::X86::BI__builtin_ia32_ktestcsi:
case clang::X86::BI__builtin_ia32_ktestcdi:
return interp__builtin_elementwise_int_binop(
- S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return (!A & B) == 0;
- });
+ S, OpPC, Call,
+ [](const APSInt &A, const APSInt &B) { return (!A & B) == 0; });
case clang::X86::BI__builtin_ia32_ktestzsi:
case clang::X86::BI__builtin_ia32_ktestzsi:
return interp__builtin_elementwise_int_binop(
- S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return (A & B) == 0;
- });
+ S, OpPC, Call,
+ [](const APSInt &A, const APSInt &B) { return (A & B) == 0; });
case clang::X86::BI__builtin_ia32_kortestchi:
case clang::X86::BI__builtin_ia32_kortestcsi:
case clang::X86::BI__builtin_ia32_kortestcdi:
case clang::X86::BI__builtin_ia32_kortestcqi:
return interp__builtin_elementwise_int_binop(
- S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return ~(A | B) == 0;
- });
+ S, OpPC, Call,
+ [](const APSInt &A, const APSInt &B) { return ~(A | B) == 0; });
case clang::X86::BI__builtin_ia32_kortestzhi:
case clang::X86::BI__builtin_ia32_kortestzsi:
case clang::X86::BI__builtin_ia32_kortestzdi:
case clang::X86::BI__builtin_ia32_kortestzqi:
return interp__builtin_elementwise_int_binop(
- S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return (A | B) == 0);
- });
+ S, OpPC, Call,
+ [](const APSInt &A, const APSInt &B) { return (A | B) == 0); });
case clang::X86::BI__builtin_ia32_lzcnt_u16:
case clang::X86::BI__builtin_ia32_lzcnt_u32:
diff --git a/clang/lib/Headers/avx512bwintrin.h b/clang/lib/Headers/avx512bwintrin.h
index 73e2679a908db..21915a4ec2934 100644
--- a/clang/lib/Headers/avx512bwintrin.h
+++ b/clang/lib/Headers/avx512bwintrin.h
@@ -93,14 +93,12 @@ _kxor_mask64(__mmask64 __A, __mmask64 __B) {
}
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
-_kortestc_mask32_u8(__mmask32 __A, __mmask32 __B)
-{
+_kortestc_mask32_u8(__mmask32 __A, __mmask32 __B) {
return (unsigned char)__builtin_ia32_kortestcsi(__A, __B);
}
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
-_kortestz_mask32_u8(__mmask32 __A, __mmask32 __B)
-{
+_kortestz_mask32_u8(__mmask32 __A, __mmask32 __B) {
return (unsigned char)__builtin_ia32_kortestzsi(__A, __B);
}
@@ -127,14 +125,12 @@ _kortest_mask64_u8(__mmask64 __A, __mmask64 __B, unsigned char *__C) {
}
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
-_ktestc_mask32_u8(__mmask32 __A, __mmask32 __B)
-{
+_ktestc_mask32_u8(__mmask32 __A, __mmask32 __B) {
return (unsigned char)__builtin_ia32_ktestcsi(__A, __B);
}
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
-_ktestz_mask32_u8(__mmask32 __A, __mmask32 __B)
-{
+_ktestz_mask32_u8(__mmask32 __A, __mmask32 __B) {
return (unsigned char)__builtin_ia32_ktestzsi(__A, __B);
}
diff --git a/clang/lib/Headers/avx512dqintrin.h b/clang/lib/Headers/avx512dqintrin.h
index 92ffcc54cdf92..29156e7e96434 100644
--- a/clang/lib/Headers/avx512dqintrin.h
+++ b/clang/lib/Headers/avx512dqintrin.h
@@ -60,14 +60,12 @@ _kxor_mask8(__mmask8 __A, __mmask8 __B) {
}
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
-_kortestc_mask8_u8(__mmask8 __A, __mmask8 __B)
-{
+_kortestc_mask8_u8(__mmask8 __A, __mmask8 __B) {
return (unsigned char)__builtin_ia32_kortestcqi(__A, __B);
}
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
-_kortestz_mask8_u8(__mmask8 __A, __mmask8 __B)
-{
+_kortestz_mask8_u8(__mmask8 __A, __mmask8 __B) {
return (unsigned char)__builtin_ia32_kortestzqi(__A, __B);
}
@@ -78,14 +76,12 @@ _kortest_mask8_u8(__mmask8 __A, __mmask8 __B, unsigned char *__C) {
}
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
-_ktestc_mask8_u8(__mmask8 __A, __mmask8 __B)
-{
+_ktestc_mask8_u8(__mmask8 __A, __mmask8 __B) {
return (unsigned char)__builtin_ia32_ktestcqi(__A, __B);
}
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
-_ktestz_mask8_u8(__mmask8 __A, __mmask8 __B)
-{
+_ktestz_mask8_u8(__mmask8 __A, __mmask8 __B) {
return (unsigned char)__builtin_ia32_ktestzqi(__A, __B);
}
@@ -96,14 +92,12 @@ _ktest_mask8_u8(__mmask8 __A, __mmask8 __B, unsigned char *__C) {
}
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
-_ktestc_mask16_u8(__mmask16 __A, __mmask16 __B)
-{
+_ktestc_mask16_u8(__mmask16 __A, __mmask16 __B) {
return (unsigned char)__builtin_ia32_ktestchi(__A, __B);
}
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
-_ktestz_mask16_u8(__mmask16 __A, __mmask16 __B)
-{
+_ktestz_mask16_u8(__mmask16 __A, __mmask16 __B) {
return (unsigned char)__builtin_ia32_ktestzhi(__A, __B);
}
diff --git a/clang/lib/Headers/avx512fintrin.h b/clang/lib/Headers/avx512fintrin.h
index 0f9c712b200ba..aa77e270f99a1 100644
--- a/clang/lib/Headers/avx512fintrin.h
+++ b/clang/lib/Headers/avx512fintrin.h
@@ -8082,26 +8082,22 @@ _mm512_kor(__mmask16 __A, __mmask16 __B) {
}
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
-_mm512_kortestc (__mmask16 __A, __mmask16 __B)
-{
+_mm512_kortestc(__mmask16 __A, __mmask16 __B) {
return __builtin_ia32_kortestchi ((__mmask16) __A, (__mmask16) __B);
}
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
-_mm512_kortestz (__mmask16 __A, __mmask16 __B)
-{
+_mm512_kortestz(__mmask16 __A, __mmask16 __B) {
return __builtin_ia32_kortestzhi ((__mmask16) __A, (__mmask16) __B);
}
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
-_kortestc_mask16_u8(__mmask16 __A, __mmask16 __B)
-{
+_kortestc_mask16_u8(__mmask16 __A, __mmask16 __B) {
return (unsigned char)__builtin_ia32_kortestchi(__A, __B);
}
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
-_kortestz_mask16_u8(__mmask16 __A, __mmask16 __B)
-{
+_kortestz_mask16_u8(__mmask16 __A, __mmask16 __B) {
return (unsigned char)__builtin_ia32_kortestzhi(__A, __B);
}
>From 08e45cf0709e8ab9cc4c002f82cf2b38008207b5 Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Mon, 3 Nov 2025 20:57:52 +0100
Subject: [PATCH 06/15] Fix build errors
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 077f263a1bcb3..82c8b0a567d14 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -3796,13 +3796,17 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case clang::X86::BI__builtin_ia32_ktestcdi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call,
- [](const APSInt &A, const APSInt &B) { return (!A & B) == 0; });
+ [](const APSInt &A, const APSInt &B) {
+ return APInt(sizeof(unsigned char) * 8, (!A & B) == 0);
+ });
case clang::X86::BI__builtin_ia32_ktestzsi:
- case clang::X86::BI__builtin_ia32_ktestzsi:
+ case clang::X86::BI__builtin_ia32_ktestzdi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call,
- [](const APSInt &A, const APSInt &B) { return (A & B) == 0; });
+ [](const APSInt &A, const APSInt &B) {
+ return APInt(sizeof(unsigned char) * 8, (A & B) == 0);
+ });
case clang::X86::BI__builtin_ia32_kortestchi:
case clang::X86::BI__builtin_ia32_kortestcsi:
@@ -3810,7 +3814,9 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case clang::X86::BI__builtin_ia32_kortestcqi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call,
- [](const APSInt &A, const APSInt &B) { return ~(A | B) == 0; });
+ [](const APSInt &A, const APSInt &B) {
+ return APInt(sizeof(unsigned char) * 8, ~(A | B) == 0);
+ });
case clang::X86::BI__builtin_ia32_kortestzhi:
case clang::X86::BI__builtin_ia32_kortestzsi:
@@ -3818,7 +3824,9 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case clang::X86::BI__builtin_ia32_kortestzqi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call,
- [](const APSInt &A, const APSInt &B) { return (A | B) == 0); });
+ [](const APSInt &A, const APSInt &B) {
+ return APInt(sizeof(unsigned char) * 8, (A | B) == 0);
+ });
case clang::X86::BI__builtin_ia32_lzcnt_u16:
case clang::X86::BI__builtin_ia32_lzcnt_u32:
>From 3e6650d9cf574561b0eab3bfb69b4d166a3c420f Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Mon, 3 Nov 2025 20:59:13 +0100
Subject: [PATCH 07/15] Address comments from RKSimon review
---
clang/test/CodeGen/X86/avx512bw-builtins.c | 127 ++++++++++++++++-----
clang/test/CodeGen/X86/avx512dq-builtins.c | 98 ++++++++++++----
clang/test/CodeGen/X86/avx512f-builtins.c | 36 +++---
3 files changed, 190 insertions(+), 71 deletions(-)
diff --git a/clang/test/CodeGen/X86/avx512bw-builtins.c b/clang/test/CodeGen/X86/avx512bw-builtins.c
index d00cb33824e61..92befe0efce74 100644
--- a/clang/test/CodeGen/X86/avx512bw-builtins.c
+++ b/clang/test/CodeGen/X86/avx512bw-builtins.c
@@ -10,6 +10,7 @@
#include <immintrin.h>
+#include <utility>
#include "builtin_test_helpers.h"
__mmask32 test_knot_mask32(__mmask32 a) {
@@ -250,13 +251,28 @@ unsigned char test_kortest_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m5
_mm512_cmpneq_epu16_mask(__C, __D), CF);
}
-#if TEST_STD_VER > 17
-TEST_CONSTEXPR bool test_kortest_mask32_u8() {
- unsigned char all_ones = 0;
- return (_kortest_mask32_u8(0x0000'0000, 0x0000'0000, &all_ones) == 1) && (all_ones == 0)
- && (_kortest_mask32_u8(0x0000'0000, 0x8000'0000, &all_ones) == 0) && (all_ones == 0)
- && (_kortest_mask32_u8(0x0123'4567, 0xFEDC'BA98, &all_ones) == 0) && (all_ones == 1)
- ;
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201402L)
+constexpr std::pair<unsigned char, unsigned char>
+test_kortest_mask32_u8(unsigned int A, unsigned int B) {
+ unsigned char all_ones{};
+ unsigned char result = _kortest_mask32_u8(A, B, &all_ones);
+ return {result, all_ones};
+}
+
+void _kortest_mask32_u8() {
+ constexpr unsigned int A1 = 0x0000'0000;
+ constexpr unsigned int B1 = 0x0000'0000;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_1{1, 0};
+ static_assert(test_kortest_mask32_u8(A1, B1) == expected_result_1);
+ constexpr unsigned int A2 = 0x0000'0000;
+ constexpr unsigned int B2 = 0x8000'0000;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_2{0, 0};
+ static_assert(test_kortest_mask32_u8(A2, B2) == expected_result_2);
+ constexpr unsigned int A3 = 0x0123'4567;
+ constexpr unsigned int B3 = 0xFEDC'BA98;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_3{0, 1};
+ static_assert(test_kortest_mask32_u8(A3, B3) == expected_result_3);
}
#endif
@@ -314,13 +330,28 @@ unsigned char test_kortest_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m5
_mm512_cmpneq_epu8_mask(__C, __D), CF);
}
-#if TEST_STD_VER > 17
-TEST_CONSTEXPR bool test_kortest_mask64_u8() {
- unsigned char all_ones = 0;
- return (_kortest_mask64_u8(0x0000'0000'0000'0000, 0x0000'0000'0000'0000, &all_ones) == 1) && (all_ones == 0)
- && (_kortest_mask64_u8(0x0000'0000'0000'0000, 0x8000'0000'0000'0000, &all_ones) == 0) && (all_ones == 0)
- && (_kortest_mask64_u8(0x0123'4567'89AB'CDEF, 0xFEDC'BA98'7654'3210, &all_ones) == 0) && (all_ones == 1)
- ;
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201402L)
+constexpr std::pair<unsigned char, unsigned char>
+test_kortest_mask64_u8(unsigned long long A, unsigned long long B) {
+ unsigned char all_ones{};
+ unsigned char result = _kortest_mask64_u8(A, B, &all_ones);
+ return {result, all_ones};
+}
+
+void _kortest_mask64_u8() {
+ constexpr unsigned long long A1 = 0x0000'0000'0000'0000;
+ constexpr unsigned long long B1 = 0x0000'0000'0000'0000;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_1{1, 0};
+ static_assert(test_kortest_mask64_u8(A1, B1) == expected_result_1);
+ constexpr unsigned long long A2 = 0x0000'0000'0000'0000;
+ constexpr unsigned long long B2 = 0x8000'0000'0000'0000;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_2{0, 0};
+ static_assert(test_kortest_mask64_u8(A2, B2) == expected_result_2);
+ constexpr unsigned long long A3 = 0x0123'4567'89AB'CDEF;
+ constexpr unsigned long long B3 = 0xFEDC'BA98'7654'3210;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_3{0, 1};
+ static_assert(test_kortest_mask64_u8(A3, B3) == expected_result_3);
}
#endif
@@ -368,14 +399,32 @@ unsigned char test_ktest_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m512
_mm512_cmpneq_epu16_mask(__C, __D), CF);
}
-#if TEST_STD_VER > 17
-TEST_CONSTEXPR bool test_ktest_mask32_u8() {
- unsigned char and_not = 0;
- return (_ktest_mask32_u8(0x0000'0000, 0x0000'0000, &and_not) == 1) && (and_not == 1)
- && (_ktest_mask32_u8(0x0000'0000, 0x8000'0000, &and_not) == 1) && (and_not == 0)
- && (_ktest_mask32_u8(0xF000'0000, 0x8000'0000, &and_not) == 0) && (and_not == 1)
- && (_ktest_mask32_u8(0x0123'4567, 0x0123'4567, &and_not) == 0) && (and_not == 1)
- ;
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201402L)
+constexpr std::pair<unsigned char, unsigned char>
+test_ktest_mask32_u8(unsigned int A, unsigned int B) {
+ unsigned char and_not{};
+ unsigned char result = _ktest_mask32_u8(A, B, &and_not);
+ return {result, and_not};
+}
+
+void _ktest_mask32_u8() {
+ constexpr unsigned int A1 = 0x0000'0000;
+ constexpr unsigned int B1 = 0x0000'0000;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_1{1, 1};
+ static_assert(test_ktest_mask32_u8(A1, B1) == expected_result_1);
+ constexpr unsigned int A2 = 0x0000'0000;
+ constexpr unsigned int B2 = 0x8000'0000;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_2{1, 0};
+ static_assert(test_ktest_mask32_u8(A2, B2) == expected_result_2);
+ constexpr unsigned int A3 = 0xF000'0000;
+ constexpr unsigned int B3 = 0x8000'0000;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_3{0, 1};
+ static_assert(test_ktest_mask32_u8(A3, B3) == expected_result_3);
+ constexpr unsigned int A4 = 0x0123'4567;
+ constexpr unsigned int B4 = 0x0123'4567;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_4{0, 1};
+ static_assert(test_ktest_mask32_u8(A4, B4) == expected_result_4);
}
#endif
@@ -423,14 +472,32 @@ unsigned char test_ktest_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m512
_mm512_cmpneq_epu8_mask(__C, __D), CF);
}
-#if TEST_STD_VER > 17
-TEST_CONSTEXPR bool test_ktest_mask64_u8() {
- unsigned char and_not = 0;
- return (_ktest_mask64_u8(0x0000'0000'0000'0000, 0x0000'0000'0000'0000, &and_not) == 1) && (and_not == 1)
- && (_ktest_mask64_u8(0x0000'0000'0000'0000, 0x8000'0000'0000'0000, &and_not) == 1) && (and_not == 0)
- && (_ktest_mask64_u8(0xF000'0000'0000'0000, 0x8000'0000'0000'0000, &and_not) == 0) && (and_not == 1)
- && (_ktest_mask64_u8(0x0123'4567'89AB'CDEF, 0x0123'4567'89AB'CDEF, &and_not) == 0) && (and_not == 1)
- ;
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201402L)
+constexpr std::pair<unsigned char, unsigned char>
+test_ktest_mask64_u8(unsigned long long A, unsigned long long B) {
+ unsigned char and_not{};
+ unsigned char result = _ktest_mask64_u8(A, B, &and_not);
+ return {result, and_not};
+}
+
+void _ktest_mask64_u8() {
+ constexpr unsigned long long A1 = 0x0000'0000'0000'0000;
+ constexpr unsigned long long B1 = 0x0000'0000'0000'0000;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_1{1, 1};
+ static_assert(test_ktest_mask64_u8(A1, B1) == expected_result_1);
+ constexpr unsigned long long A2 = 0x0000'0000'0000'0000;
+ constexpr unsigned long long B2 = 0x8000'0000'0000'0000;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_2{1, 0};
+ static_assert(test_ktest_mask64_u8(A2, B2) == expected_result_2);
+ constexpr unsigned long long A3 = 0xF000'0000'0000'0000;
+ constexpr unsigned long long B3 = 0x8000'0000'0000'0000;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_3{0, 1};
+ static_assert(test_ktest_mask64_u8(A3, B3) == expected_result_3);
+ constexpr unsigned long long A4 = 0x0123'4567'89AB'CDEF;
+ constexpr unsigned long long B4 = 0x0123'4567'89AB'CDEF;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_4{0, 1};
+ static_assert(test_ktest_mask64_u8(A4, B4) == expected_result_4);
}
#endif
diff --git a/clang/test/CodeGen/X86/avx512dq-builtins.c b/clang/test/CodeGen/X86/avx512dq-builtins.c
index 32ee13023dbd4..3c8d0d1b73a13 100644
--- a/clang/test/CodeGen/X86/avx512dq-builtins.c
+++ b/clang/test/CodeGen/X86/avx512dq-builtins.c
@@ -10,6 +10,7 @@
#include <immintrin.h>
+#include <utility>
#include "builtin_test_helpers.h"
__mmask8 test_knot_mask8(__mmask8 a) {
@@ -158,13 +159,28 @@ unsigned char test_kortest_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m51
_mm512_cmpneq_epu64_mask(__C, __D), CF);
}
-#if TEST_STD_VER > 17
-TEST_CONSTEXPR bool test_kortest_mask8_u8() {
- unsigned char all_ones = 0;
- return (_kortest_mask8_u8(0x00, 0x00, &all_ones) == 1) && (all_ones == 0)
- && (_kortest_mask8_u8(0x00, 0x80, &all_ones) == 0) && (all_ones == 0)
- && (_kortest_mask8_u8(0x01, 0xFE, &all_ones) == 0) && (all_ones == 1)
- ;
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201402L)
+constexpr std::pair<unsigned char, unsigned char>
+test_kortest_mask8_u8(unsigned char A, unsigned char B) {
+ unsigned char all_ones{};
+ unsigned char result = _kortest_mask8_u8(A, B, &all_ones);
+ return {result, all_ones};
+}
+
+void _kortest_mask8_u8() {
+ constexpr unsigned char A1 = 0x00;
+ constexpr unsigned char B1 = 0x00;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_1{1, 0};
+ static_assert(test_kortest_mask8_u8(A1, B1) == expected_result_1);
+ constexpr unsigned char A2 = 0x00;
+ constexpr unsigned char B2 = 0x80;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_2{0, 0};
+ static_assert(test_kortest_mask8_u8(A2, B2) == expected_result_2);
+ constexpr unsigned char A3 = 0x01;
+ constexpr unsigned char B3 = 0xFE;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_3{0, 1};
+ static_assert(test_kortest_mask8_u8(A3, B3) == expected_result_3);
}
#endif
@@ -212,14 +228,32 @@ unsigned char test_ktest_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m512i
_mm512_cmpneq_epu64_mask(__C, __D), CF);
}
-#if TEST_STD_VER > 17
-TEST_CONSTEXPR bool test_ktest_mask8_u8() {
- unsigned char and_not = 0;
- return (_ktest_mask8_u8(0x00, 0x00, &and_not) == 1) && (and_not == 1)
- && (_ktest_mask8_u8(0x00, 0x80, &and_not) == 1) && (and_not == 0)
- && (_ktest_mask8_u8(0xF0, 0x80, &and_not) == 0) && (and_not == 1)
- && (_ktest_mask8_u8(0x01, 0x01, &and_not) == 0) && (and_not == 1)
- ;
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201402L)
+constexpr std::pair<unsigned char, unsigned char>
+test_ktest_mask8_u8(unsigned char A, unsigned char B) {
+ unsigned char all_ones{};
+ unsigned char result = _ktest_mask8_u8(A, B, &all_ones);
+ return {result, all_ones};
+}
+
+void _ktest_mask8_u8() {
+ constexpr unsigned char A1 = 0x00;
+ constexpr unsigned char B1 = 0x00;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_1{1, 1};
+ static_assert(test_ktest_mask8_u8(A1, B1) == expected_result_1);
+ constexpr unsigned char A2 = 0x00;
+ constexpr unsigned char B2 = 0x80;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_2{1, 0};
+ static_assert(test_ktest_mask8_u8(A2, B2) == expected_result_2);
+ constexpr unsigned char A3 = 0xF0;
+ constexpr unsigned char B3 = 0x80;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_3{0, 1};
+ static_assert(test_ktest_mask8_u8(A3, B3) == expected_result_3);
+ constexpr unsigned char A4 = 0x01;
+ constexpr unsigned char B4 = 0x01;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_4{0, 1};
+ static_assert(test_ktest_mask8_u8(A4, B4) == expected_result_4);
}
#endif
@@ -267,14 +301,32 @@ unsigned char test_ktest_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m512
_mm512_cmpneq_epu32_mask(__C, __D), CF);
}
-#if TEST_STD_VER > 17
-TEST_CONSTEXPR bool test_ktest_mask16_u8() {
- unsigned char and_not = 0;
- return (_ktest_mask16_u8(0x0000, 0x0000, &and_not) == 1) && (and_not == 1)
- && (_ktest_mask16_u8(0x0000, 0x8000, &and_not) == 1) && (and_not == 0)
- && (_ktest_mask16_u8(0xF000, 0x8000, &and_not) == 0) && (and_not == 1)
- && (_ktest_mask16_u8(0x0123, 0x0123, &and_not) == 0) && (and_not == 1)
- ;
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201402L)
+constexpr std::pair<unsigned char, unsigned char>
+test_ktest_mask16_u8(unsigned int A, unsigned int B) {
+ unsigned char all_ones{};
+ unsigned char result = _ktest_mask16_u8(A, B, &all_ones);
+ return {result, all_ones};
+}
+
+void _ktest_mask16_u8() {
+ constexpr unsigned int A1 = 0x0000;
+ constexpr unsigned int B1 = 0x0000;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_1{1, 1};
+ static_assert(test_ktest_mask16_u8(A1, B1) == expected_result_1);
+ constexpr unsigned int A2 = 0x0000;
+ constexpr unsigned int B2 = 0x8000;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_2{1, 0};
+ static_assert(test_ktest_mask16_u8(A2, B2) == expected_result_2);
+ constexpr unsigned int A3 = 0xF000;
+ constexpr unsigned int B3 = 0x8000;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_3{0, 1};
+ static_assert(test_ktest_mask16_u8(A3, B3) == expected_result_3);
+ constexpr unsigned int A4 = 0x0123;
+ constexpr unsigned int B4 = 0x0123;
+ constexpr std::pair<unsigned char, unsigned char> expected_result_4{0, 1};
+ static_assert(test_ktest_mask16_u8(A4, B4) == expected_result_4);
}
#endif
diff --git a/clang/test/CodeGen/X86/avx512f-builtins.c b/clang/test/CodeGen/X86/avx512f-builtins.c
index 582f2cbbf2dd5..2865b1ca98b41 100644
--- a/clang/test/CodeGen/X86/avx512f-builtins.c
+++ b/clang/test/CodeGen/X86/avx512f-builtins.c
@@ -8965,13 +8965,13 @@ int test_mm512_kortestc(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
_mm512_cmpneq_epu32_mask(__C, __D));
}
-#if TEST_STD_VER > 17
-TEST_CONSTEXPR bool test_mm512_kortestc() {
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+void _mm512_kortestc() {
// TODO: should I check for carry flag set/unset here, and if so, how?
- return (_mm512_kortestc(0x0000, 0x0000) == 0x0000)
- && (_mm512_kortestc(0x0000, 0x8000) == 0x8000)
- && (_mm512_kortestc(0x0123, 0xFEDC) == 0xFFFF)
- ;
+ static_assert(_mm512_kortestc(0x0000, 0x0000) == 0x0000);
+ static_assert(_mm512_kortestc(0x0000, 0x8000) == 0x8000);
+ static_assert(_mm512_kortestc(0x0123, 0xFEDC) == 0xFFFF);
}
#endif
@@ -8987,13 +8987,13 @@ int test_mm512_kortestz(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
_mm512_cmpneq_epu32_mask(__C, __D));
}
-#if TEST_STD_VER > 17
-TEST_CONSTEXPR bool test_mm512_kortestz() {
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+void _mm512_kortestz() {
// TODO: should I check for zero flag set/unset here, and if so, how?
- return (_mm512_kortestz(0x0000, 0x0000) == 0x0000)
- && (_mm512_kortestz(0x0000, 0x8000) == 0x8000)
- && (_mm512_kortestz(0x0123, 0xFEDC) == 0xFFFF)
- ;
+ static_assert(_mm512_kortestz(0x0000, 0x0000) == 0x0000);
+ static_assert(_mm512_kortestz(0x0000, 0x8000) == 0x8000);
+ static_assert(_mm512_kortestz(0x0123, 0xFEDC) == 0xFFFF);
}
#endif
@@ -9051,13 +9051,13 @@ unsigned char test_kortest_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m5
_mm512_cmpneq_epu32_mask(__C, __D), CF);
}
-#if TEST_STD_VER > 17
-TEST_CONSTEXPR bool test_kortest_mask16_u8() {
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+constexpr void test_kortest_mask16_u8() {
unsigned char all_ones = 0;
- return (_kortest_mask16_u8(0x0000, 0x0000, &all_ones) == 1) && (all_ones == 0)
- && (_kortest_mask16_u8(0x0000, 0x8000, &all_ones) == 0) && (all_ones == 0)
- && (_kortest_mask16_u8(0x0123, 0xFEDC, &all_ones) == 0) && (all_ones == 1)
- ;
+ static_assert((_kortest_mask16_u8(0x0000, 0x0000, &all_ones) == 1) && (all_ones == 0));
+ static_assert((_kortest_mask16_u8(0x0000, 0x8000, &all_ones) == 0) && (all_ones == 0));
+ static_assert((_kortest_mask16_u8(0x0123, 0xFEDC, &all_ones) == 0) && (all_ones == 1));
}
#endif
>From b26627c68244047f07e1c32d516f7056c7bb240f Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Mon, 3 Nov 2025 21:00:06 +0100
Subject: [PATCH 08/15] Run git-clang-format
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 82c8b0a567d14..affd3c8747911 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -3795,38 +3795,34 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case clang::X86::BI__builtin_ia32_ktestcsi:
case clang::X86::BI__builtin_ia32_ktestcdi:
return interp__builtin_elementwise_int_binop(
- S, OpPC, Call,
- [](const APSInt &A, const APSInt &B) {
+ S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
return APInt(sizeof(unsigned char) * 8, (!A & B) == 0);
- });
+ });
case clang::X86::BI__builtin_ia32_ktestzsi:
case clang::X86::BI__builtin_ia32_ktestzdi:
return interp__builtin_elementwise_int_binop(
- S, OpPC, Call,
- [](const APSInt &A, const APSInt &B) {
+ S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
return APInt(sizeof(unsigned char) * 8, (A & B) == 0);
- });
+ });
case clang::X86::BI__builtin_ia32_kortestchi:
case clang::X86::BI__builtin_ia32_kortestcsi:
case clang::X86::BI__builtin_ia32_kortestcdi:
case clang::X86::BI__builtin_ia32_kortestcqi:
return interp__builtin_elementwise_int_binop(
- S, OpPC, Call,
- [](const APSInt &A, const APSInt &B) {
+ S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
return APInt(sizeof(unsigned char) * 8, ~(A | B) == 0);
- });
+ });
case clang::X86::BI__builtin_ia32_kortestzhi:
case clang::X86::BI__builtin_ia32_kortestzsi:
case clang::X86::BI__builtin_ia32_kortestzdi:
case clang::X86::BI__builtin_ia32_kortestzqi:
return interp__builtin_elementwise_int_binop(
- S, OpPC, Call,
- [](const APSInt &A, const APSInt &B) {
+ S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
return APInt(sizeof(unsigned char) * 8, (A | B) == 0);
- });
+ });
case clang::X86::BI__builtin_ia32_lzcnt_u16:
case clang::X86::BI__builtin_ia32_lzcnt_u32:
>From a273d11cd2481def9dcee487377c6dfd17fa7e84 Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Tue, 4 Nov 2025 19:28:33 +0100
Subject: [PATCH 09/15] Trying to fix Linux and Windows builds
Rewrite test_kortest_mask16_u8.
Replace std::pair with kortest/ktest_result structs.
---
clang/test/CodeGen/X86/avx512-builtins.h | 14 ++++++
clang/test/CodeGen/X86/avx512bw-builtins.c | 44 +++++++++----------
clang/test/CodeGen/X86/avx512dq-builtins.c | 36 ++++++++--------
clang/test/CodeGen/X86/avx512f-builtins.c | 50 ++++++++++++----------
4 files changed, 81 insertions(+), 63 deletions(-)
create mode 100644 clang/test/CodeGen/X86/avx512-builtins.h
diff --git a/clang/test/CodeGen/X86/avx512-builtins.h b/clang/test/CodeGen/X86/avx512-builtins.h
new file mode 100644
index 0000000000000..1fc7035f308d3
--- /dev/null
+++ b/clang/test/CodeGen/X86/avx512-builtins.h
@@ -0,0 +1,14 @@
+#ifndef __AVX512_BUILTINS_H
+#define __AVX512_BUILTINS_H
+
+struct kortest_result {
+ unsigned char result;
+ unsigned char all_ones;
+};
+
+struct ktest_result {
+ unsigned char result;
+ unsigned char and_not;
+};
+
+#endif /* __AVX512_BUILTINS_H */
diff --git a/clang/test/CodeGen/X86/avx512bw-builtins.c b/clang/test/CodeGen/X86/avx512bw-builtins.c
index 92befe0efce74..27e08ea4c3fb4 100644
--- a/clang/test/CodeGen/X86/avx512bw-builtins.c
+++ b/clang/test/CodeGen/X86/avx512bw-builtins.c
@@ -10,7 +10,7 @@
#include <immintrin.h>
-#include <utility>
+#include "avx512-builtins.h"
#include "builtin_test_helpers.h"
__mmask32 test_knot_mask32(__mmask32 a) {
@@ -252,8 +252,8 @@ unsigned char test_kortest_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m5
}
// Test constexpr handling.
-#if defined(__cplusplus) && (__cplusplus >= 201402L)
-constexpr std::pair<unsigned char, unsigned char>
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+constexpr kortest_result
test_kortest_mask32_u8(unsigned int A, unsigned int B) {
unsigned char all_ones{};
unsigned char result = _kortest_mask32_u8(A, B, &all_ones);
@@ -263,15 +263,15 @@ test_kortest_mask32_u8(unsigned int A, unsigned int B) {
void _kortest_mask32_u8() {
constexpr unsigned int A1 = 0x0000'0000;
constexpr unsigned int B1 = 0x0000'0000;
- constexpr std::pair<unsigned char, unsigned char> expected_result_1{1, 0};
+ constexpr kortest_result expected_result_1{1, 0};
static_assert(test_kortest_mask32_u8(A1, B1) == expected_result_1);
constexpr unsigned int A2 = 0x0000'0000;
constexpr unsigned int B2 = 0x8000'0000;
- constexpr std::pair<unsigned char, unsigned char> expected_result_2{0, 0};
+ constexpr kortest_result expected_result_2{0, 0};
static_assert(test_kortest_mask32_u8(A2, B2) == expected_result_2);
constexpr unsigned int A3 = 0x0123'4567;
constexpr unsigned int B3 = 0xFEDC'BA98;
- constexpr std::pair<unsigned char, unsigned char> expected_result_3{0, 1};
+ constexpr kortest_result expected_result_3{0, 1};
static_assert(test_kortest_mask32_u8(A3, B3) == expected_result_3);
}
#endif
@@ -331,8 +331,8 @@ unsigned char test_kortest_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m5
}
// Test constexpr handling.
-#if defined(__cplusplus) && (__cplusplus >= 201402L)
-constexpr std::pair<unsigned char, unsigned char>
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+constexpr kortest_result
test_kortest_mask64_u8(unsigned long long A, unsigned long long B) {
unsigned char all_ones{};
unsigned char result = _kortest_mask64_u8(A, B, &all_ones);
@@ -342,15 +342,15 @@ test_kortest_mask64_u8(unsigned long long A, unsigned long long B) {
void _kortest_mask64_u8() {
constexpr unsigned long long A1 = 0x0000'0000'0000'0000;
constexpr unsigned long long B1 = 0x0000'0000'0000'0000;
- constexpr std::pair<unsigned char, unsigned char> expected_result_1{1, 0};
+ constexpr kortest_result expected_result_1{1, 0};
static_assert(test_kortest_mask64_u8(A1, B1) == expected_result_1);
constexpr unsigned long long A2 = 0x0000'0000'0000'0000;
constexpr unsigned long long B2 = 0x8000'0000'0000'0000;
- constexpr std::pair<unsigned char, unsigned char> expected_result_2{0, 0};
+ constexpr kortest_result expected_result_2{0, 0};
static_assert(test_kortest_mask64_u8(A2, B2) == expected_result_2);
constexpr unsigned long long A3 = 0x0123'4567'89AB'CDEF;
constexpr unsigned long long B3 = 0xFEDC'BA98'7654'3210;
- constexpr std::pair<unsigned char, unsigned char> expected_result_3{0, 1};
+ constexpr kortest_result expected_result_3{0, 1};
static_assert(test_kortest_mask64_u8(A3, B3) == expected_result_3);
}
#endif
@@ -400,8 +400,8 @@ unsigned char test_ktest_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m512
}
// Test constexpr handling.
-#if defined(__cplusplus) && (__cplusplus >= 201402L)
-constexpr std::pair<unsigned char, unsigned char>
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+constexpr ktest_result
test_ktest_mask32_u8(unsigned int A, unsigned int B) {
unsigned char and_not{};
unsigned char result = _ktest_mask32_u8(A, B, &and_not);
@@ -411,19 +411,19 @@ test_ktest_mask32_u8(unsigned int A, unsigned int B) {
void _ktest_mask32_u8() {
constexpr unsigned int A1 = 0x0000'0000;
constexpr unsigned int B1 = 0x0000'0000;
- constexpr std::pair<unsigned char, unsigned char> expected_result_1{1, 1};
+ constexpr ktest_result expected_result_1{1, 1};
static_assert(test_ktest_mask32_u8(A1, B1) == expected_result_1);
constexpr unsigned int A2 = 0x0000'0000;
constexpr unsigned int B2 = 0x8000'0000;
- constexpr std::pair<unsigned char, unsigned char> expected_result_2{1, 0};
+ constexpr ktest_result expected_result_2{1, 0};
static_assert(test_ktest_mask32_u8(A2, B2) == expected_result_2);
constexpr unsigned int A3 = 0xF000'0000;
constexpr unsigned int B3 = 0x8000'0000;
- constexpr std::pair<unsigned char, unsigned char> expected_result_3{0, 1};
+ constexpr ktest_result expected_result_3{0, 1};
static_assert(test_ktest_mask32_u8(A3, B3) == expected_result_3);
constexpr unsigned int A4 = 0x0123'4567;
constexpr unsigned int B4 = 0x0123'4567;
- constexpr std::pair<unsigned char, unsigned char> expected_result_4{0, 1};
+ constexpr ktest_result expected_result_4{0, 1};
static_assert(test_ktest_mask32_u8(A4, B4) == expected_result_4);
}
#endif
@@ -474,7 +474,7 @@ unsigned char test_ktest_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m512
// Test constexpr handling.
#if defined(__cplusplus) && (__cplusplus >= 201402L)
-constexpr std::pair<unsigned char, unsigned char>
+constexpr ktest_result
test_ktest_mask64_u8(unsigned long long A, unsigned long long B) {
unsigned char and_not{};
unsigned char result = _ktest_mask64_u8(A, B, &and_not);
@@ -484,19 +484,19 @@ test_ktest_mask64_u8(unsigned long long A, unsigned long long B) {
void _ktest_mask64_u8() {
constexpr unsigned long long A1 = 0x0000'0000'0000'0000;
constexpr unsigned long long B1 = 0x0000'0000'0000'0000;
- constexpr std::pair<unsigned char, unsigned char> expected_result_1{1, 1};
+ constexpr ktest_result expected_result_1{1, 1};
static_assert(test_ktest_mask64_u8(A1, B1) == expected_result_1);
constexpr unsigned long long A2 = 0x0000'0000'0000'0000;
constexpr unsigned long long B2 = 0x8000'0000'0000'0000;
- constexpr std::pair<unsigned char, unsigned char> expected_result_2{1, 0};
+ constexpr ktest_result expected_result_2{1, 0};
static_assert(test_ktest_mask64_u8(A2, B2) == expected_result_2);
constexpr unsigned long long A3 = 0xF000'0000'0000'0000;
constexpr unsigned long long B3 = 0x8000'0000'0000'0000;
- constexpr std::pair<unsigned char, unsigned char> expected_result_3{0, 1};
+ constexpr ktest_result expected_result_3{0, 1};
static_assert(test_ktest_mask64_u8(A3, B3) == expected_result_3);
constexpr unsigned long long A4 = 0x0123'4567'89AB'CDEF;
constexpr unsigned long long B4 = 0x0123'4567'89AB'CDEF;
- constexpr std::pair<unsigned char, unsigned char> expected_result_4{0, 1};
+ constexpr ktest_result expected_result_4{0, 1};
static_assert(test_ktest_mask64_u8(A4, B4) == expected_result_4);
}
#endif
diff --git a/clang/test/CodeGen/X86/avx512dq-builtins.c b/clang/test/CodeGen/X86/avx512dq-builtins.c
index 3c8d0d1b73a13..7ccee88d575ad 100644
--- a/clang/test/CodeGen/X86/avx512dq-builtins.c
+++ b/clang/test/CodeGen/X86/avx512dq-builtins.c
@@ -10,7 +10,7 @@
#include <immintrin.h>
-#include <utility>
+#include "avx512-builtins.h"
#include "builtin_test_helpers.h"
__mmask8 test_knot_mask8(__mmask8 a) {
@@ -160,8 +160,8 @@ unsigned char test_kortest_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m51
}
// Test constexpr handling.
-#if defined(__cplusplus) && (__cplusplus >= 201402L)
-constexpr std::pair<unsigned char, unsigned char>
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+constexpr kortest_result
test_kortest_mask8_u8(unsigned char A, unsigned char B) {
unsigned char all_ones{};
unsigned char result = _kortest_mask8_u8(A, B, &all_ones);
@@ -171,15 +171,15 @@ test_kortest_mask8_u8(unsigned char A, unsigned char B) {
void _kortest_mask8_u8() {
constexpr unsigned char A1 = 0x00;
constexpr unsigned char B1 = 0x00;
- constexpr std::pair<unsigned char, unsigned char> expected_result_1{1, 0};
+ constexpr kortest_result expected_result_1{1, 0};
static_assert(test_kortest_mask8_u8(A1, B1) == expected_result_1);
constexpr unsigned char A2 = 0x00;
constexpr unsigned char B2 = 0x80;
- constexpr std::pair<unsigned char, unsigned char> expected_result_2{0, 0};
+ constexpr kortest_result expected_result_2{0, 0};
static_assert(test_kortest_mask8_u8(A2, B2) == expected_result_2);
constexpr unsigned char A3 = 0x01;
constexpr unsigned char B3 = 0xFE;
- constexpr std::pair<unsigned char, unsigned char> expected_result_3{0, 1};
+ constexpr kortest_result expected_result_3{0, 1};
static_assert(test_kortest_mask8_u8(A3, B3) == expected_result_3);
}
#endif
@@ -229,8 +229,8 @@ unsigned char test_ktest_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m512i
}
// Test constexpr handling.
-#if defined(__cplusplus) && (__cplusplus >= 201402L)
-constexpr std::pair<unsigned char, unsigned char>
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+constexpr ktest_result
test_ktest_mask8_u8(unsigned char A, unsigned char B) {
unsigned char all_ones{};
unsigned char result = _ktest_mask8_u8(A, B, &all_ones);
@@ -240,19 +240,19 @@ test_ktest_mask8_u8(unsigned char A, unsigned char B) {
void _ktest_mask8_u8() {
constexpr unsigned char A1 = 0x00;
constexpr unsigned char B1 = 0x00;
- constexpr std::pair<unsigned char, unsigned char> expected_result_1{1, 1};
+ constexpr ktest_result expected_result_1{1, 1};
static_assert(test_ktest_mask8_u8(A1, B1) == expected_result_1);
constexpr unsigned char A2 = 0x00;
constexpr unsigned char B2 = 0x80;
- constexpr std::pair<unsigned char, unsigned char> expected_result_2{1, 0};
+ constexpr ktest_result expected_result_2{1, 0};
static_assert(test_ktest_mask8_u8(A2, B2) == expected_result_2);
constexpr unsigned char A3 = 0xF0;
constexpr unsigned char B3 = 0x80;
- constexpr std::pair<unsigned char, unsigned char> expected_result_3{0, 1};
+ constexpr ktest_result expected_result_3{0, 1};
static_assert(test_ktest_mask8_u8(A3, B3) == expected_result_3);
constexpr unsigned char A4 = 0x01;
constexpr unsigned char B4 = 0x01;
- constexpr std::pair<unsigned char, unsigned char> expected_result_4{0, 1};
+ constexpr ktest_result expected_result_4{0, 1};
static_assert(test_ktest_mask8_u8(A4, B4) == expected_result_4);
}
#endif
@@ -302,8 +302,8 @@ unsigned char test_ktest_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m512
}
// Test constexpr handling.
-#if defined(__cplusplus) && (__cplusplus >= 201402L)
-constexpr std::pair<unsigned char, unsigned char>
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+constexpr ktest_result
test_ktest_mask16_u8(unsigned int A, unsigned int B) {
unsigned char all_ones{};
unsigned char result = _ktest_mask16_u8(A, B, &all_ones);
@@ -313,19 +313,19 @@ test_ktest_mask16_u8(unsigned int A, unsigned int B) {
void _ktest_mask16_u8() {
constexpr unsigned int A1 = 0x0000;
constexpr unsigned int B1 = 0x0000;
- constexpr std::pair<unsigned char, unsigned char> expected_result_1{1, 1};
+ constexpr ktest_result expected_result_1{1, 1};
static_assert(test_ktest_mask16_u8(A1, B1) == expected_result_1);
constexpr unsigned int A2 = 0x0000;
constexpr unsigned int B2 = 0x8000;
- constexpr std::pair<unsigned char, unsigned char> expected_result_2{1, 0};
+ constexpr ktest_result expected_result_2{1, 0};
static_assert(test_ktest_mask16_u8(A2, B2) == expected_result_2);
constexpr unsigned int A3 = 0xF000;
constexpr unsigned int B3 = 0x8000;
- constexpr std::pair<unsigned char, unsigned char> expected_result_3{0, 1};
+ constexpr ktest_result expected_result_3{0, 1};
static_assert(test_ktest_mask16_u8(A3, B3) == expected_result_3);
constexpr unsigned int A4 = 0x0123;
constexpr unsigned int B4 = 0x0123;
- constexpr std::pair<unsigned char, unsigned char> expected_result_4{0, 1};
+ constexpr ktest_result expected_result_4{0, 1};
static_assert(test_ktest_mask16_u8(A4, B4) == expected_result_4);
}
#endif
diff --git a/clang/test/CodeGen/X86/avx512f-builtins.c b/clang/test/CodeGen/X86/avx512f-builtins.c
index 2865b1ca98b41..289df8e3cc610 100644
--- a/clang/test/CodeGen/X86/avx512f-builtins.c
+++ b/clang/test/CodeGen/X86/avx512f-builtins.c
@@ -9,6 +9,7 @@
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +avx512f -emit-llvm -o - -Wall -Werror -Wsign-conversion -fexperimental-new-constant-interpreter | FileCheck %s
#include <immintrin.h>
+#include "avx512-builtins.h"
#include "builtin_test_helpers.h"
__m512d test_mm512_sqrt_pd(__m512d a)
@@ -8965,15 +8966,9 @@ int test_mm512_kortestc(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
_mm512_cmpneq_epu32_mask(__C, __D));
}
-// Test constexpr handling.
-#if defined(__cplusplus) && (__cplusplus >= 201103L)
-void _mm512_kortestc() {
- // TODO: should I check for carry flag set/unset here, and if so, how?
- static_assert(_mm512_kortestc(0x0000, 0x0000) == 0x0000);
- static_assert(_mm512_kortestc(0x0000, 0x8000) == 0x8000);
- static_assert(_mm512_kortestc(0x0123, 0xFEDC) == 0xFFFF);
-}
-#endif
+TEST_CONSTEXPR(_mm512_kortestc(0x0000, 0x0000) == 0x0000);
+TEST_CONSTEXPR(_mm512_kortestc(0x0000, 0x8000) == 0x8000);
+TEST_CONSTEXPR(_mm512_kortestc(0x0123, 0xFEDC) == 0xFFFF);
int test_mm512_kortestz(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_mm512_kortestz
@@ -8987,15 +8982,9 @@ int test_mm512_kortestz(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
_mm512_cmpneq_epu32_mask(__C, __D));
}
-// Test constexpr handling.
-#if defined(__cplusplus) && (__cplusplus >= 201103L)
-void _mm512_kortestz() {
- // TODO: should I check for zero flag set/unset here, and if so, how?
- static_assert(_mm512_kortestz(0x0000, 0x0000) == 0x0000);
- static_assert(_mm512_kortestz(0x0000, 0x8000) == 0x8000);
- static_assert(_mm512_kortestz(0x0123, 0xFEDC) == 0xFFFF);
-}
-#endif
+TEST_CONSTEXPR(_mm512_kortestz(0x0000, 0x0000) == 0x0000);
+TEST_CONSTEXPR(_mm512_kortestz(0x0000, 0x8000) == 0x8000);
+TEST_CONSTEXPR(_mm512_kortestz(0x0123, 0xFEDC) == 0xFFFF);
unsigned char test_kortestz_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_kortestz_mask16_u8
@@ -9053,11 +9042,26 @@ unsigned char test_kortest_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m5
// Test constexpr handling.
#if defined(__cplusplus) && (__cplusplus >= 201103L)
-constexpr void test_kortest_mask16_u8() {
- unsigned char all_ones = 0;
- static_assert((_kortest_mask16_u8(0x0000, 0x0000, &all_ones) == 1) && (all_ones == 0));
- static_assert((_kortest_mask16_u8(0x0000, 0x8000, &all_ones) == 0) && (all_ones == 0));
- static_assert((_kortest_mask16_u8(0x0123, 0xFEDC, &all_ones) == 0) && (all_ones == 1));
+constexpr kortest_result
+test_kortest_mask16_u8(unsigned short A, unsigned short B) {
+ unsigned char all_ones{};
+ unsigned char result = _kortest_mask16_u8(A, B, &all_ones);
+ return {result, all_ones};
+}
+
+void _kortest_mask16_u8() {
+ constexpr unsigned short A1 = 0x0000;
+ constexpr unsigned short B1 = 0x0000;
+ constexpr kortest_result expected_result_1{1, 0};
+ static_assert(test_kortest_mask16_u8(A1, B1) == expected_result_1);
+ constexpr unsigned short A2 = 0x0000;
+ constexpr unsigned short B2 = 0x8000;
+ constexpr kortest_result expected_result_2{0, 0};
+ static_assert(test_kortest_mask16_u8(A2, B2) == expected_result_2);
+ constexpr unsigned short A3 = 0x0123;
+ constexpr unsigned short B3 = 0xFEDC;
+ constexpr kortest_result expected_result_3{0, 1};
+ static_assert(test_kortest_mask16_u8(A3, B3) == expected_result_3);
}
#endif
>From 35445a678ac1fe359150030685fa1e81bb2fc7f4 Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Tue, 4 Nov 2025 20:27:19 +0100
Subject: [PATCH 10/15] Mimic bmi2-builtins.c implementation
Rewrite test_kortest_mask16_u8.
Remove avx512-builtins.h.
Remove kortest/ktest_result structs.
---
clang/test/CodeGen/X86/avx512-builtins.h | 14 -------
clang/test/CodeGen/X86/avx512bw-builtins.c | 49 ++++++++++------------
clang/test/CodeGen/X86/avx512dq-builtins.c | 38 ++++++++---------
clang/test/CodeGen/X86/avx512f-builtins.c | 12 +++---
4 files changed, 44 insertions(+), 69 deletions(-)
delete mode 100644 clang/test/CodeGen/X86/avx512-builtins.h
diff --git a/clang/test/CodeGen/X86/avx512-builtins.h b/clang/test/CodeGen/X86/avx512-builtins.h
deleted file mode 100644
index 1fc7035f308d3..0000000000000
--- a/clang/test/CodeGen/X86/avx512-builtins.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef __AVX512_BUILTINS_H
-#define __AVX512_BUILTINS_H
-
-struct kortest_result {
- unsigned char result;
- unsigned char all_ones;
-};
-
-struct ktest_result {
- unsigned char result;
- unsigned char and_not;
-};
-
-#endif /* __AVX512_BUILTINS_H */
diff --git a/clang/test/CodeGen/X86/avx512bw-builtins.c b/clang/test/CodeGen/X86/avx512bw-builtins.c
index 27e08ea4c3fb4..d2f5da22cd07c 100644
--- a/clang/test/CodeGen/X86/avx512bw-builtins.c
+++ b/clang/test/CodeGen/X86/avx512bw-builtins.c
@@ -10,7 +10,6 @@
#include <immintrin.h>
-#include "avx512-builtins.h"
#include "builtin_test_helpers.h"
__mmask32 test_knot_mask32(__mmask32 a) {
@@ -253,25 +252,24 @@ unsigned char test_kortest_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m5
// Test constexpr handling.
#if defined(__cplusplus) && (__cplusplus >= 201103L)
-constexpr kortest_result
+constexpr unsigned char
test_kortest_mask32_u8(unsigned int A, unsigned int B) {
unsigned char all_ones{};
- unsigned char result = _kortest_mask32_u8(A, B, &all_ones);
- return {result, all_ones};
+ return (_kortest_mask32_u8(A, B, &all_ones) << 4) | all_ones;
}
void _kortest_mask32_u8() {
constexpr unsigned int A1 = 0x0000'0000;
constexpr unsigned int B1 = 0x0000'0000;
- constexpr kortest_result expected_result_1{1, 0};
+ constexpr unsigned char expected_result_1 = 0x10;
static_assert(test_kortest_mask32_u8(A1, B1) == expected_result_1);
constexpr unsigned int A2 = 0x0000'0000;
constexpr unsigned int B2 = 0x8000'0000;
- constexpr kortest_result expected_result_2{0, 0};
+ constexpr unsigned char expected_result_2 = 0x00;
static_assert(test_kortest_mask32_u8(A2, B2) == expected_result_2);
constexpr unsigned int A3 = 0x0123'4567;
constexpr unsigned int B3 = 0xFEDC'BA98;
- constexpr kortest_result expected_result_3{0, 1};
+ constexpr unsigned char expected_result_3 = 0x01;
static_assert(test_kortest_mask32_u8(A3, B3) == expected_result_3);
}
#endif
@@ -332,25 +330,24 @@ unsigned char test_kortest_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m5
// Test constexpr handling.
#if defined(__cplusplus) && (__cplusplus >= 201103L)
-constexpr kortest_result
+constexpr unsigned char
test_kortest_mask64_u8(unsigned long long A, unsigned long long B) {
unsigned char all_ones{};
- unsigned char result = _kortest_mask64_u8(A, B, &all_ones);
- return {result, all_ones};
+ return (_kortest_mask64_u8(A, B, &all_ones) << 4) | all_ones;
}
void _kortest_mask64_u8() {
constexpr unsigned long long A1 = 0x0000'0000'0000'0000;
constexpr unsigned long long B1 = 0x0000'0000'0000'0000;
- constexpr kortest_result expected_result_1{1, 0};
+ constexpr unsigned char expected_result_1 = 0x10;
static_assert(test_kortest_mask64_u8(A1, B1) == expected_result_1);
constexpr unsigned long long A2 = 0x0000'0000'0000'0000;
constexpr unsigned long long B2 = 0x8000'0000'0000'0000;
- constexpr kortest_result expected_result_2{0, 0};
+ constexpr unsigned char expected_result_2 = 0x00;
static_assert(test_kortest_mask64_u8(A2, B2) == expected_result_2);
constexpr unsigned long long A3 = 0x0123'4567'89AB'CDEF;
constexpr unsigned long long B3 = 0xFEDC'BA98'7654'3210;
- constexpr kortest_result expected_result_3{0, 1};
+ constexpr unsigned char expected_result_3 = 0x01;
static_assert(test_kortest_mask64_u8(A3, B3) == expected_result_3);
}
#endif
@@ -401,29 +398,28 @@ unsigned char test_ktest_mask32_u8(__m512i __A, __m512i __B, __m512i __C, __m512
// Test constexpr handling.
#if defined(__cplusplus) && (__cplusplus >= 201103L)
-constexpr ktest_result
+constexpr unsigned char
test_ktest_mask32_u8(unsigned int A, unsigned int B) {
unsigned char and_not{};
- unsigned char result = _ktest_mask32_u8(A, B, &and_not);
- return {result, and_not};
+ return (_ktest_mask32_u8(A, B, &and_not) << 4) | and_not;
}
void _ktest_mask32_u8() {
constexpr unsigned int A1 = 0x0000'0000;
constexpr unsigned int B1 = 0x0000'0000;
- constexpr ktest_result expected_result_1{1, 1};
+ constexpr unsigned char expected_result_1 = 0x11;
static_assert(test_ktest_mask32_u8(A1, B1) == expected_result_1);
constexpr unsigned int A2 = 0x0000'0000;
constexpr unsigned int B2 = 0x8000'0000;
- constexpr ktest_result expected_result_2{1, 0};
+ constexpr unsigned char expected_result_2 = 0x10;
static_assert(test_ktest_mask32_u8(A2, B2) == expected_result_2);
constexpr unsigned int A3 = 0xF000'0000;
constexpr unsigned int B3 = 0x8000'0000;
- constexpr ktest_result expected_result_3{0, 1};
+ constexpr unsigned char expected_result_3 = 0x01;
static_assert(test_ktest_mask32_u8(A3, B3) == expected_result_3);
constexpr unsigned int A4 = 0x0123'4567;
constexpr unsigned int B4 = 0x0123'4567;
- constexpr ktest_result expected_result_4{0, 1};
+ constexpr unsigned char expected_result_4 = 0x01;
static_assert(test_ktest_mask32_u8(A4, B4) == expected_result_4);
}
#endif
@@ -474,29 +470,28 @@ unsigned char test_ktest_mask64_u8(__m512i __A, __m512i __B, __m512i __C, __m512
// Test constexpr handling.
#if defined(__cplusplus) && (__cplusplus >= 201402L)
-constexpr ktest_result
+constexpr unsigned char
test_ktest_mask64_u8(unsigned long long A, unsigned long long B) {
unsigned char and_not{};
- unsigned char result = _ktest_mask64_u8(A, B, &and_not);
- return {result, and_not};
+ return (_ktest_mask64_u8(A, B, &and_not) << 4) | and_not;
}
void _ktest_mask64_u8() {
constexpr unsigned long long A1 = 0x0000'0000'0000'0000;
constexpr unsigned long long B1 = 0x0000'0000'0000'0000;
- constexpr ktest_result expected_result_1{1, 1};
+ constexpr unsigned char expected_result_1 = 0x11;
static_assert(test_ktest_mask64_u8(A1, B1) == expected_result_1);
constexpr unsigned long long A2 = 0x0000'0000'0000'0000;
constexpr unsigned long long B2 = 0x8000'0000'0000'0000;
- constexpr ktest_result expected_result_2{1, 0};
+ constexpr unsigned char expected_result_2 = 0x10;
static_assert(test_ktest_mask64_u8(A2, B2) == expected_result_2);
constexpr unsigned long long A3 = 0xF000'0000'0000'0000;
constexpr unsigned long long B3 = 0x8000'0000'0000'0000;
- constexpr ktest_result expected_result_3{0, 1};
+ constexpr unsigned char expected_result_3 = 0x01;
static_assert(test_ktest_mask64_u8(A3, B3) == expected_result_3);
constexpr unsigned long long A4 = 0x0123'4567'89AB'CDEF;
constexpr unsigned long long B4 = 0x0123'4567'89AB'CDEF;
- constexpr ktest_result expected_result_4{0, 1};
+ constexpr unsigned char expected_result_4 = 0x01;
static_assert(test_ktest_mask64_u8(A4, B4) == expected_result_4);
}
#endif
diff --git a/clang/test/CodeGen/X86/avx512dq-builtins.c b/clang/test/CodeGen/X86/avx512dq-builtins.c
index 7ccee88d575ad..efe983ce5b10c 100644
--- a/clang/test/CodeGen/X86/avx512dq-builtins.c
+++ b/clang/test/CodeGen/X86/avx512dq-builtins.c
@@ -10,7 +10,6 @@
#include <immintrin.h>
-#include "avx512-builtins.h"
#include "builtin_test_helpers.h"
__mmask8 test_knot_mask8(__mmask8 a) {
@@ -161,25 +160,24 @@ unsigned char test_kortest_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m51
// Test constexpr handling.
#if defined(__cplusplus) && (__cplusplus >= 201103L)
-constexpr kortest_result
+constexpr unsigned char
test_kortest_mask8_u8(unsigned char A, unsigned char B) {
unsigned char all_ones{};
- unsigned char result = _kortest_mask8_u8(A, B, &all_ones);
- return {result, all_ones};
+ return (_kortest_mask8_u8(A, B, &all_ones) << 4) | all_ones;
}
void _kortest_mask8_u8() {
constexpr unsigned char A1 = 0x00;
constexpr unsigned char B1 = 0x00;
- constexpr kortest_result expected_result_1{1, 0};
+ constexpr unsigned char expected_result_1 = 0x10;
static_assert(test_kortest_mask8_u8(A1, B1) == expected_result_1);
constexpr unsigned char A2 = 0x00;
constexpr unsigned char B2 = 0x80;
- constexpr kortest_result expected_result_2{0, 0};
+ constexpr unsigned char expected_result_2 = 0x00;
static_assert(test_kortest_mask8_u8(A2, B2) == expected_result_2);
constexpr unsigned char A3 = 0x01;
constexpr unsigned char B3 = 0xFE;
- constexpr kortest_result expected_result_3{0, 1};
+ constexpr unsigned char expected_result_3 = 0x01;
static_assert(test_kortest_mask8_u8(A3, B3) == expected_result_3);
}
#endif
@@ -230,29 +228,28 @@ unsigned char test_ktest_mask8_u8(__m512i __A, __m512i __B, __m512i __C, __m512i
// Test constexpr handling.
#if defined(__cplusplus) && (__cplusplus >= 201103L)
-constexpr ktest_result
+constexpr unsigned char
test_ktest_mask8_u8(unsigned char A, unsigned char B) {
unsigned char all_ones{};
- unsigned char result = _ktest_mask8_u8(A, B, &all_ones);
- return {result, all_ones};
+ return (_ktest_mask8_u8(A, B, &all_ones) << 4) | all_ones;
}
void _ktest_mask8_u8() {
constexpr unsigned char A1 = 0x00;
constexpr unsigned char B1 = 0x00;
- constexpr ktest_result expected_result_1{1, 1};
+ constexpr unsigned char expected_result_1 = 0x11;
static_assert(test_ktest_mask8_u8(A1, B1) == expected_result_1);
constexpr unsigned char A2 = 0x00;
constexpr unsigned char B2 = 0x80;
- constexpr ktest_result expected_result_2{1, 0};
+ constexpr unsigned char expected_result_2 = 0x10;
static_assert(test_ktest_mask8_u8(A2, B2) == expected_result_2);
constexpr unsigned char A3 = 0xF0;
constexpr unsigned char B3 = 0x80;
- constexpr ktest_result expected_result_3{0, 1};
+ constexpr unsigned char expected_result_3 = 0x01;
static_assert(test_ktest_mask8_u8(A3, B3) == expected_result_3);
constexpr unsigned char A4 = 0x01;
constexpr unsigned char B4 = 0x01;
- constexpr ktest_result expected_result_4{0, 1};
+ constexpr unsigned char expected_result_4 = 0x01;
static_assert(test_ktest_mask8_u8(A4, B4) == expected_result_4);
}
#endif
@@ -303,29 +300,28 @@ unsigned char test_ktest_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m512
// Test constexpr handling.
#if defined(__cplusplus) && (__cplusplus >= 201103L)
-constexpr ktest_result
+constexpr unsigned char
test_ktest_mask16_u8(unsigned int A, unsigned int B) {
unsigned char all_ones{};
- unsigned char result = _ktest_mask16_u8(A, B, &all_ones);
- return {result, all_ones};
+ return (_ktest_mask16_u8(A, B, &all_ones) << 4) | all_ones;
}
void _ktest_mask16_u8() {
constexpr unsigned int A1 = 0x0000;
constexpr unsigned int B1 = 0x0000;
- constexpr ktest_result expected_result_1{1, 1};
+ constexpr unsigned char expected_result_1 = 0x11;
static_assert(test_ktest_mask16_u8(A1, B1) == expected_result_1);
constexpr unsigned int A2 = 0x0000;
constexpr unsigned int B2 = 0x8000;
- constexpr ktest_result expected_result_2{1, 0};
+ constexpr unsigned char expected_result_2 = 0x10;
static_assert(test_ktest_mask16_u8(A2, B2) == expected_result_2);
constexpr unsigned int A3 = 0xF000;
constexpr unsigned int B3 = 0x8000;
- constexpr ktest_result expected_result_3{0, 1};
+ constexpr unsigned char expected_result_3 = 0x01;
static_assert(test_ktest_mask16_u8(A3, B3) == expected_result_3);
constexpr unsigned int A4 = 0x0123;
constexpr unsigned int B4 = 0x0123;
- constexpr ktest_result expected_result_4{0, 1};
+ constexpr unsigned char expected_result_4 = 0x01;
static_assert(test_ktest_mask16_u8(A4, B4) == expected_result_4);
}
#endif
diff --git a/clang/test/CodeGen/X86/avx512f-builtins.c b/clang/test/CodeGen/X86/avx512f-builtins.c
index 289df8e3cc610..092425c4ac864 100644
--- a/clang/test/CodeGen/X86/avx512f-builtins.c
+++ b/clang/test/CodeGen/X86/avx512f-builtins.c
@@ -9,7 +9,6 @@
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +avx512f -emit-llvm -o - -Wall -Werror -Wsign-conversion -fexperimental-new-constant-interpreter | FileCheck %s
#include <immintrin.h>
-#include "avx512-builtins.h"
#include "builtin_test_helpers.h"
__m512d test_mm512_sqrt_pd(__m512d a)
@@ -9042,25 +9041,24 @@ unsigned char test_kortest_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m5
// Test constexpr handling.
#if defined(__cplusplus) && (__cplusplus >= 201103L)
-constexpr kortest_result
+constexpr unsigned char
test_kortest_mask16_u8(unsigned short A, unsigned short B) {
unsigned char all_ones{};
- unsigned char result = _kortest_mask16_u8(A, B, &all_ones);
- return {result, all_ones};
+ return (_kortest_mask16_u8(A, B, &all_ones) << 4) | all_ones;
}
void _kortest_mask16_u8() {
constexpr unsigned short A1 = 0x0000;
constexpr unsigned short B1 = 0x0000;
- constexpr kortest_result expected_result_1{1, 0};
+ constexpr unsigned char expected_result_1 = 0x10;
static_assert(test_kortest_mask16_u8(A1, B1) == expected_result_1);
constexpr unsigned short A2 = 0x0000;
constexpr unsigned short B2 = 0x8000;
- constexpr kortest_result expected_result_2{0, 0};
+ constexpr unsigned char expected_result_2 = 0x00;
static_assert(test_kortest_mask16_u8(A2, B2) == expected_result_2);
constexpr unsigned short A3 = 0x0123;
constexpr unsigned short B3 = 0xFEDC;
- constexpr kortest_result expected_result_3{0, 1};
+ constexpr unsigned char expected_result_3 = 0x01;
static_assert(test_kortest_mask16_u8(A3, B3) == expected_result_3);
}
#endif
>From 8384231dc02a12725ae332cda5bbd6d6b0c41680 Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Wed, 5 Nov 2025 19:48:11 +0100
Subject: [PATCH 11/15] Update IntExprEvaluator::VisitBuiltinCallExpr at
ExprConstant.cpp
Add ktest/kortest cases.
Change !A&B to ~A&B in InterpretBuiltin at InterpBuiltin.cpp.
Add more ktest cases to InterpretBuiltin.
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 16 +++++---
clang/lib/AST/ExprConstant.cpp | 48 ++++++++++++++++++++++++
2 files changed, 58 insertions(+), 6 deletions(-)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index affd3c8747911..a3fef299b51e2 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -3792,36 +3792,40 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
return Result;
});
+ case clang::X86::BI__builtin_ia32_ktestcqi:
+ case clang::X86::BI__builtin_ia32_ktestchi:
case clang::X86::BI__builtin_ia32_ktestcsi:
case clang::X86::BI__builtin_ia32_ktestcdi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return APInt(sizeof(unsigned char) * 8, (!A & B) == 0);
+ return APInt(sizeof(unsigned char) * 8, (~A & B) == 0);
});
+ case clang::X86::BI__builtin_ia32_ktestzqi:
+ case clang::X86::BI__builtin_ia32_ktestzhi:
case clang::X86::BI__builtin_ia32_ktestzsi:
case clang::X86::BI__builtin_ia32_ktestzdi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return APInt(sizeof(unsigned char) * 8, (A & B) == 0);
+ return APInt(8, (A & B) == 0);
});
+ case clang::X86::BI__builtin_ia32_kortestcqi:
case clang::X86::BI__builtin_ia32_kortestchi:
case clang::X86::BI__builtin_ia32_kortestcsi:
case clang::X86::BI__builtin_ia32_kortestcdi:
- case clang::X86::BI__builtin_ia32_kortestcqi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return APInt(sizeof(unsigned char) * 8, ~(A | B) == 0);
+ return APInt(8, ~(A | B) == 0);
});
+ case clang::X86::BI__builtin_ia32_kortestzqi:
case clang::X86::BI__builtin_ia32_kortestzhi:
case clang::X86::BI__builtin_ia32_kortestzsi:
case clang::X86::BI__builtin_ia32_kortestzdi:
- case clang::X86::BI__builtin_ia32_kortestzqi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return APInt(sizeof(unsigned char) * 8, (A | B) == 0);
+ return APInt(8, (A | B) == 0);
});
case clang::X86::BI__builtin_ia32_lzcnt_u16:
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d0404b957ab03..628f8d231523c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15614,6 +15614,54 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
return Success(Val, E);
}
+ case clang::X86::BI__builtin_ia32_ktestcqi:
+ case clang::X86::BI__builtin_ia32_ktestchi:
+ case clang::X86::BI__builtin_ia32_ktestcsi:
+ case clang::X86::BI__builtin_ia32_ktestcdi: {
+ APSInt A, B;
+ if (!EvaluateInteger(E->getArg(0), A, Info) ||
+ !EvaluateInteger(E->getArg(1), B, Info))
+ return false;
+
+ return Success(APInt(sizeof(unsigned char) * 8, (~A & B) == 0), E);
+ }
+
+ case clang::X86::BI__builtin_ia32_ktestzqi:
+ case clang::X86::BI__builtin_ia32_ktestzhi:
+ case clang::X86::BI__builtin_ia32_ktestzsi:
+ case clang::X86::BI__builtin_ia32_ktestzdi: {
+ APSInt A, B;
+ if (!EvaluateInteger(E->getArg(0), A, Info) ||
+ !EvaluateInteger(E->getArg(1), B, Info))
+ return false;
+
+ return Success(APInt(sizeof(unsigned char) * 8, (A & B) == 0), E);
+ }
+
+ case clang::X86::BI__builtin_ia32_kortestcqi:
+ case clang::X86::BI__builtin_ia32_kortestchi:
+ case clang::X86::BI__builtin_ia32_kortestcsi:
+ case clang::X86::BI__builtin_ia32_kortestcdi: {
+ APSInt A, B;
+ if (!EvaluateInteger(E->getArg(0), A, Info) ||
+ !EvaluateInteger(E->getArg(1), B, Info))
+ return false;
+
+ return Success(APInt(sizeof(unsigned char) * 8, ~(A | B) == 0), E);
+ }
+
+ case clang::X86::BI__builtin_ia32_kortestzqi:
+ case clang::X86::BI__builtin_ia32_kortestzhi:
+ case clang::X86::BI__builtin_ia32_kortestzsi:
+ case clang::X86::BI__builtin_ia32_kortestzdi: {
+ APSInt A, B;
+ if (!EvaluateInteger(E->getArg(0), A, Info) ||
+ !EvaluateInteger(E->getArg(1), B, Info))
+ return false;
+
+ return Success(APInt(sizeof(unsigned char) * 8, (A | B) == 0), E);
+ }
+
case clang::X86::BI__builtin_ia32_lzcnt_u16:
case clang::X86::BI__builtin_ia32_lzcnt_u32:
case clang::X86::BI__builtin_ia32_lzcnt_u64: {
>From c7758063aa1c4e81ffbfd8f639486a56cc473b11 Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Wed, 5 Nov 2025 19:48:48 +0100
Subject: [PATCH 12/15] Run git-clang-format
---
clang/lib/AST/ExprConstant.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 628f8d231523c..4649bfe5861a4 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15653,7 +15653,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
case clang::X86::BI__builtin_ia32_kortestzqi:
case clang::X86::BI__builtin_ia32_kortestzhi:
case clang::X86::BI__builtin_ia32_kortestzsi:
- case clang::X86::BI__builtin_ia32_kortestzdi: {
+ case clang::X86::BI__builtin_ia32_kortestzdi: {
APSInt A, B;
if (!EvaluateInteger(E->getArg(0), A, Info) ||
!EvaluateInteger(E->getArg(1), B, Info))
>From a70c31361b228ec93622fb0c5af306a3a0ea12a4 Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Thu, 6 Nov 2025 16:29:17 +0100
Subject: [PATCH 13/15] Fix _m512_kortest tests
---
clang/test/CodeGen/X86/avx512f-builtins.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/clang/test/CodeGen/X86/avx512f-builtins.c b/clang/test/CodeGen/X86/avx512f-builtins.c
index 092425c4ac864..be55d5b42dc02 100644
--- a/clang/test/CodeGen/X86/avx512f-builtins.c
+++ b/clang/test/CodeGen/X86/avx512f-builtins.c
@@ -8965,9 +8965,9 @@ int test_mm512_kortestc(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
_mm512_cmpneq_epu32_mask(__C, __D));
}
-TEST_CONSTEXPR(_mm512_kortestc(0x0000, 0x0000) == 0x0000);
-TEST_CONSTEXPR(_mm512_kortestc(0x0000, 0x8000) == 0x8000);
-TEST_CONSTEXPR(_mm512_kortestc(0x0123, 0xFEDC) == 0xFFFF);
+TEST_CONSTEXPR(_mm512_kortestc(0x0000, 0x0000) == 0);
+TEST_CONSTEXPR(_mm512_kortestc(0x0000, 0x8000) == 0);
+TEST_CONSTEXPR(_mm512_kortestc(0x0123, 0xFEDC) == 1);
int test_mm512_kortestz(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_mm512_kortestz
@@ -8981,9 +8981,9 @@ int test_mm512_kortestz(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
_mm512_cmpneq_epu32_mask(__C, __D));
}
-TEST_CONSTEXPR(_mm512_kortestz(0x0000, 0x0000) == 0x0000);
-TEST_CONSTEXPR(_mm512_kortestz(0x0000, 0x8000) == 0x8000);
-TEST_CONSTEXPR(_mm512_kortestz(0x0123, 0xFEDC) == 0xFFFF);
+TEST_CONSTEXPR(_mm512_kortestz(0x0000, 0x0000) == 1);
+TEST_CONSTEXPR(_mm512_kortestz(0x0000, 0x8000) == 0);
+TEST_CONSTEXPR(_mm512_kortestz(0x0123, 0xFEDC) == 0);
unsigned char test_kortestz_mask16_u8(__m512i __A, __m512i __B, __m512i __C, __m512i __D) {
// CHECK-LABEL: test_kortestz_mask16_u8
>From d75eb39c0a8b0fc99377a7df3fe1240432448125 Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Thu, 6 Nov 2025 17:50:50 +0100
Subject: [PATCH 14/15] Fix -Wfree-nonheap-object warnings
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 8 ++++----
clang/lib/AST/ExprConstant.cpp | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index a3fef299b51e2..3b586a8327c02 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -3798,7 +3798,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case clang::X86::BI__builtin_ia32_ktestcdi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return APInt(sizeof(unsigned char) * 8, (~A & B) == 0);
+ return APInt(sizeof(unsigned char) * 8, (unsigned char)((~A & B) == 0));
});
case clang::X86::BI__builtin_ia32_ktestzqi:
@@ -3807,7 +3807,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case clang::X86::BI__builtin_ia32_ktestzdi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return APInt(8, (A & B) == 0);
+ return APInt(sizeof(unsigned char) * 8, (unsigned char)((A & B) == 0));
});
case clang::X86::BI__builtin_ia32_kortestcqi:
@@ -3816,7 +3816,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case clang::X86::BI__builtin_ia32_kortestcdi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return APInt(8, ~(A | B) == 0);
+ return APInt(sizeof(unsigned char) * 8, (unsigned char)(~(A | B) == 0));
});
case clang::X86::BI__builtin_ia32_kortestzqi:
@@ -3825,7 +3825,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case clang::X86::BI__builtin_ia32_kortestzdi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return APInt(8, (A | B) == 0);
+ return APInt(sizeof(unsigned char) * 8, (unsigned char)((A | B) == 0));
});
case clang::X86::BI__builtin_ia32_lzcnt_u16:
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 4649bfe5861a4..e06f2138c4055 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15623,7 +15623,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
!EvaluateInteger(E->getArg(1), B, Info))
return false;
- return Success(APInt(sizeof(unsigned char) * 8, (~A & B) == 0), E);
+ return Success(APInt(sizeof(unsigned char) * 8, (unsigned char)((~A & B) == 0)), E);
}
case clang::X86::BI__builtin_ia32_ktestzqi:
@@ -15635,7 +15635,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
!EvaluateInteger(E->getArg(1), B, Info))
return false;
- return Success(APInt(sizeof(unsigned char) * 8, (A & B) == 0), E);
+ return Success(APInt(sizeof(unsigned char) * 8, (unsigned char)((A & B) == 0)), E);
}
case clang::X86::BI__builtin_ia32_kortestcqi:
@@ -15647,7 +15647,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
!EvaluateInteger(E->getArg(1), B, Info))
return false;
- return Success(APInt(sizeof(unsigned char) * 8, ~(A | B) == 0), E);
+ return Success(APInt(sizeof(unsigned char) * 8, (unsigned char)(~(A | B) == 0)), E);
}
case clang::X86::BI__builtin_ia32_kortestzqi:
@@ -15659,7 +15659,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
!EvaluateInteger(E->getArg(1), B, Info))
return false;
- return Success(APInt(sizeof(unsigned char) * 8, (A | B) == 0), E);
+ return Success(APInt(sizeof(unsigned char) * 8, (unsigned char)((A | B) == 0)), E);
}
case clang::X86::BI__builtin_ia32_lzcnt_u16:
>From 4b51b6ccfff2887e78866853bb9e1be7fd4bf515 Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Thu, 6 Nov 2025 17:52:30 +0100
Subject: [PATCH 15/15] Run git-clang-format
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 12 ++++++++----
clang/lib/AST/ExprConstant.cpp | 12 ++++++++----
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 3b586a8327c02..2df938a64e4c1 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -3798,7 +3798,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case clang::X86::BI__builtin_ia32_ktestcdi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return APInt(sizeof(unsigned char) * 8, (unsigned char)((~A & B) == 0));
+ return APInt(sizeof(unsigned char) * 8,
+ (unsigned char)((~A & B) == 0));
});
case clang::X86::BI__builtin_ia32_ktestzqi:
@@ -3807,7 +3808,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case clang::X86::BI__builtin_ia32_ktestzdi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return APInt(sizeof(unsigned char) * 8, (unsigned char)((A & B) == 0));
+ return APInt(sizeof(unsigned char) * 8,
+ (unsigned char)((A & B) == 0));
});
case clang::X86::BI__builtin_ia32_kortestcqi:
@@ -3816,7 +3818,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case clang::X86::BI__builtin_ia32_kortestcdi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return APInt(sizeof(unsigned char) * 8, (unsigned char)(~(A | B) == 0));
+ return APInt(sizeof(unsigned char) * 8,
+ (unsigned char)(~(A | B) == 0));
});
case clang::X86::BI__builtin_ia32_kortestzqi:
@@ -3825,7 +3828,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case clang::X86::BI__builtin_ia32_kortestzdi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
- return APInt(sizeof(unsigned char) * 8, (unsigned char)((A | B) == 0));
+ return APInt(sizeof(unsigned char) * 8,
+ (unsigned char)((A | B) == 0));
});
case clang::X86::BI__builtin_ia32_lzcnt_u16:
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e06f2138c4055..c95e276670375 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15623,7 +15623,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
!EvaluateInteger(E->getArg(1), B, Info))
return false;
- return Success(APInt(sizeof(unsigned char) * 8, (unsigned char)((~A & B) == 0)), E);
+ return Success(
+ APInt(sizeof(unsigned char) * 8, (unsigned char)((~A & B) == 0)), E);
}
case clang::X86::BI__builtin_ia32_ktestzqi:
@@ -15635,7 +15636,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
!EvaluateInteger(E->getArg(1), B, Info))
return false;
- return Success(APInt(sizeof(unsigned char) * 8, (unsigned char)((A & B) == 0)), E);
+ return Success(
+ APInt(sizeof(unsigned char) * 8, (unsigned char)((A & B) == 0)), E);
}
case clang::X86::BI__builtin_ia32_kortestcqi:
@@ -15647,7 +15649,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
!EvaluateInteger(E->getArg(1), B, Info))
return false;
- return Success(APInt(sizeof(unsigned char) * 8, (unsigned char)(~(A | B) == 0)), E);
+ return Success(
+ APInt(sizeof(unsigned char) * 8, (unsigned char)(~(A | B) == 0)), E);
}
case clang::X86::BI__builtin_ia32_kortestzqi:
@@ -15659,7 +15662,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
!EvaluateInteger(E->getArg(1), B, Info))
return false;
- return Success(APInt(sizeof(unsigned char) * 8, (unsigned char)((A | B) == 0)), E);
+ return Success(
+ APInt(sizeof(unsigned char) * 8, (unsigned char)((A | B) == 0)), E);
}
case clang::X86::BI__builtin_ia32_lzcnt_u16:
More information about the cfe-commits
mailing list