[clang] [X86][Clang] Add AVX512 kunpck intrinsics to be used in constexp (PR #167683)

via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 16 06:56:55 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions c,h,cpp -- clang/lib/AST/ByteCode/InterpBuiltin.cpp clang/lib/AST/ExprConstant.cpp clang/lib/Headers/avx512bwintrin.h clang/lib/Headers/avx512fintrin.h clang/test/CodeGen/X86/avx512f-builtins.c --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 9ec22b75a..8a2ce31b5 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -4622,28 +4622,22 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
   case X86::BI__builtin_ia32_kunpckhi:
   case X86::BI__builtin_ia32_kunpckdi:
   case X86::BI__builtin_ia32_kunpcksi:
-    return interp__builtin_elementwise_int_binop(S, OpPC, Call,
-                                                 [](const APSInt &A,
-                                                    const APSInt &B) {
-                                                   // Generic kunpack: extract
-                                                   // lower half of each operand
-                                                   // and concatenate Result =
-                                                   // (A[HalfWidth-1:0] <<
-                                                   // HalfWidth) |
-                                                   // B[HalfWidth-1:0]
-                                                   unsigned HalfWidth =
-                                                       A.getBitWidth() / 2;
-                                                   APSInt Result(
-                                                       A.getLoBits(HalfWidth)
-                                                           .zext(A.getBitWidth()),
-                                                       A.isUnsigned());
-                                                   Result <<= HalfWidth;
-                                                   Result |= APSInt(
-                                                       B.getLoBits(HalfWidth)
-                                                           .zext(B.getBitWidth()),
-                                                       B.isUnsigned());
-                                                   return Result;
-                                                 });
+    return interp__builtin_elementwise_int_binop(
+        S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
+          // Generic kunpack: extract
+          // lower half of each operand
+          // and concatenate Result =
+          // (A[HalfWidth-1:0] <<
+          // HalfWidth) |
+          // B[HalfWidth-1:0]
+          unsigned HalfWidth = A.getBitWidth() / 2;
+          APSInt Result(A.getLoBits(HalfWidth).zext(A.getBitWidth()),
+                        A.isUnsigned());
+          Result <<= HalfWidth;
+          Result |= APSInt(B.getLoBits(HalfWidth).zext(B.getBitWidth()),
+                           B.isUnsigned());
+          return Result;
+        });
 
   case X86::BI__builtin_ia32_phminposuw128:
     return interp__builtin_ia32_phminposuw(S, OpPC, Call);
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 10dbe3ea8..37d5eddbd 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -16361,7 +16361,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
     unsigned HalfWidth = A.getBitWidth() / 2;
     APSInt Result(A.getLoBits(HalfWidth).zext(A.getBitWidth()), A.isUnsigned());
     Result <<= HalfWidth;
-    Result |= APSInt(B.getLoBits(HalfWidth).zext(B.getBitWidth()), B.isUnsigned());
+    Result |=
+        APSInt(B.getLoBits(HalfWidth).zext(B.getBitWidth()), B.isUnsigned());
     return Success(Result, E);
   }
 
@@ -16491,7 +16492,6 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
     return Success(APValue(Result), E);
   }
 
-
   case X86::BI__builtin_ia32_kaddqi:
   case X86::BI__builtin_ia32_kaddhi:
   case X86::BI__builtin_ia32_kaddsi:

``````````

</details>


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


More information about the cfe-commits mailing list