[clang] [clang] Implement `__builtin_elementwise_clmul` (PR #196633)

2026-05-25 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/196633
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement `__builtin_elementwise_clmul` (PR #196633)

2026-05-25 Thread Corentin Jabot via cfe-commits

https://github.com/cor3ntin closed 
https://github.com/llvm/llvm-project/pull/196633
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement `__builtin_elementwise_clmul` (PR #196633)

2026-05-21 Thread Jan Schultke via cfe-commits

eisenwave wrote:

I think I got everything now

@cor3ntin @ojhunt @RKSimon 

https://github.com/llvm/llvm-project/pull/196633
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement `__builtin_elementwise_clmul` (PR #196633)

2026-05-13 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon requested changes to this pull request.

Waiting on tests (Sema / IR / constexpr)

https://github.com/llvm/llvm-project/pull/196633
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement `__builtin_elementwise_clmul` (PR #196633)

2026-05-13 Thread Oliver Hunt via cfe-commits

ojhunt wrote:

LGTM, obviously needs tests, and maybe worth looking into the complexity of 
supporting it in the bytecode interpreter (@tbaederr is worth talking to if 
it's non-obvious)

https://github.com/llvm/llvm-project/pull/196633
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement `__builtin_elementwise_clmul` (PR #196633)

2026-05-09 Thread Jan Schultke via cfe-commits

https://github.com/eisenwave edited 
https://github.com/llvm/llvm-project/pull/196633
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement `__builtin_elementwise_clmul` (PR #196633)

2026-05-09 Thread Jan Schultke via cfe-commits

https://github.com/eisenwave updated 
https://github.com/llvm/llvm-project/pull/196633

>From 508d1f79bde93d8ece110641b3b2e2909f7e3307 Mon Sep 17 00:00:00 2001
From: Eisenwave 
Date: Fri, 8 May 2026 22:21:33 +0200
Subject: [PATCH 1/2] Start work on __builtin_elementwise_clmul

---
 clang/include/clang/Basic/Builtins.td|  6 ++
 clang/lib/AST/ByteCode/InterpBuiltin.cpp |  3 +++
 clang/lib/AST/ExprConstant.cpp   | 12 
 clang/lib/CodeGen/CGBuiltin.cpp  |  3 +++
 clang/lib/Sema/SemaChecking.cpp  |  1 +
 5 files changed, 25 insertions(+)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 4a7eaeb3d353e..50e4e34da69b3 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1879,6 +1879,12 @@ def ElementwiseCttz : Builtin {
   let Prototype = "void(...)";
 }
 
+def ElementwiseClmul : Builtin {
+  let Spellings = ["__builtin_elementwise_clmul"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
+  let Prototype = "void(...)";
+}
+
 def ReduceMax : Builtin {
   let Spellings = ["__builtin_reduce_max"];
   let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 11ca93c251380..cef15e41e357c 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -5531,6 +5531,9 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
CallExpr *Call,
   case clang::X86::BI__builtin_ia32_pclmulqdq256:
   case clang::X86::BI__builtin_ia32_pclmulqdq512:
 return interp__builtin_ia32_pclmulqdq(S, OpPC, Call);
+  case Builtin::BI__builtin_elementwise_clmul:
+  return interp__builtin_elementwise_int_binop(
+  S, OpPC, Call, llvm::APIntOps::clmul);
 
   case Builtin::BI__builtin_elementwise_fma:
 return interp__builtin_elementwise_triop_fp(
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 3f3a80f5b77a3..7b7ca39dbcdfe 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14071,6 +14071,18 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
 
 return Success(APValue(ResultElements.data(), ResultElements.size()), E);
   }
+  case Builtin::BI__builtin_elementwise_clmul: {
+APValue LHS, RHS;
+if (!EvaluateAsRValue(Info, E->getArg(0), LHS) ||
+!EvaluateAsRValue(Info, E->getArg(1), RHS))
+  return false;
+  
+const APSInt& LHSInt = LHS.getInt();
+const APSInt& RHSInt = RHS.getInt();
+APInt Result = llvm::APIntOps::clmul(LHSInt, RHSInt);
+
+return Success(APValue(APSInt(Result, LHSInt.isUnsigned())), E);
+  }
   case Builtin::BI__builtin_elementwise_fshl:
   case Builtin::BI__builtin_elementwise_fshr: {
 APValue SourceHi, SourceLo, SourceShift;
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 67de2a34f44ea..02f46b949c84d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -4279,6 +4279,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_elementwise_fshr:
 return RValue::get(
 emitBuiltinWithOneOverloadedType<3>(*this, E, Intrinsic::fshr));
+  case Builtin::BI__builtin_elementwise_clmul:
+return RValue::get(
+emitBuiltinWithOneOverloadedType<2>(*this, E, Intrinsic::clmul));
 
   case Builtin::BI__builtin_elementwise_add_sat:
   case Builtin::BI__builtin_elementwise_sub_sat: {
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4706fa5d3cde0..c79a773fe4e1f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3615,6 +3615,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
   // types only.
   case Builtin::BI__builtin_elementwise_add_sat:
   case Builtin::BI__builtin_elementwise_sub_sat:
+  case Builtin::BI__builtin_elementwise_clmul:
 if (BuiltinElementwiseMath(TheCall,
EltwiseBuiltinArgTyRestriction::IntegerTy))
   return ExprError();

>From 4ead0e223070232b4d737d6092b2a0466cda1470 Mon Sep 17 00:00:00 2001
From: Eisenwave 
Date: Sat, 9 May 2026 06:44:55 +0200
Subject: [PATCH 2/2] Fix formatting, add docs

---
 clang/docs/LanguageExtensions.rst| 2 ++
 clang/docs/ReleaseNotes.rst  | 4 
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 4 ++--
 clang/lib/AST/ExprConstant.cpp   | 8 
 4 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 03cb02deb5e7f..fbb9947f39d3e 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -903,6 +903,8 @@ T __builtin_elementwise_fshr(T x, T y, T z) perform a 
funnel shift right. Co
 the