https://github.com/suriaharon1 updated https://github.com/llvm/llvm-project/pull/243757
>From 5fe6983cbda5e0e85de67e584abbd5098d441ec8 Mon Sep 17 00:00:00 2001 From: suriaharon1 <[email protected]> Date: Wed, 18 Nov 2026 00:38:44 -0600 Subject: [PATCH 1/5] [clang] Implement __builtin_elementwise_mulh The builtin returns the high half of integer multiplication. It lowers to `llvm.smulh` when input is signed and `llvm.umulh` when the input is unsigned. Input supports integer scalars, vectors and `_BitInt`. Constexpr support will be a follow-up. Fixes #243467 --- clang/docs/LanguageExtensions.md | 1 + clang/docs/ReleaseNotes.md | 4 ++ clang/include/clang/Basic/Builtins.td | 7 ++ clang/lib/CodeGen/CGBuiltin.cpp | 14 ++++ clang/lib/Sema/SemaChecking.cpp | 1 + .../test/CodeGen/builtins-elementwise-math.c | 66 +++++++++++++++++++ clang/test/Sema/builtins-elementwise-math.c | 38 +++++++++++ 7 files changed, 131 insertions(+) diff --git a/clang/docs/LanguageExtensions.md b/clang/docs/LanguageExtensions.md index cf453ac2e3b69b..73198aa8eb2520 100644 --- a/clang/docs/LanguageExtensions.md +++ b/clang/docs/LanguageExtensions.md @@ -804,6 +804,7 @@ of different sizes and signs is forbidden in binary and ternary builtins. | T \_\_builtin_elementwise_clmul(T x, T y) | perform a carry-less multiplication of x and y, returning the least significant bits of the wide result. | integer types | | T \_\_builtin_elementwise_pext(T x, T m) | extract bits from x selected by the mask m, pack them contiguously into the least significant bits of the result, and zero the rest. | integer types | | T \_\_builtin_elementwise_pdep(T x, T m) | deposit the least significant bits of x at the positions where m has a 1-bit, and zero the rest. | integer types | +| T \_\_builtin_elementwise_mulh(T x, T y) | perform signed or unsigned integer multiplication of x and y, returning the most significant bits of the wide result | integer types | *Reduction Builtins* diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 0601ffcec82fdb..9fbcf11e6c80f5 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -396,6 +396,10 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and be detected by watching the directories or by comparing their modification times. +- Added `__builtin_elementwise_mulh`, which returns the high half of + an unsigned or signed integer multiplication, and + works on integer scalars, vectors and `_BitInt`. + ### New Compiler Flags - Added `-fpch-base-dir-is-cwd` to serialize precompiled header input paths diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 15693d2fe128e5..879a0ac4c5f969 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -1892,6 +1892,13 @@ def ElementwisePdep : Builtin { let Prototype = "void(...)"; } +def ElementwiseMulh : Builtin { + let Spellings = ["__builtin_elementwise_mulh"]; + let Attributes = [NoThrow, Const, CustomTypeChecking]; + let Prototype = "void(...)"; +} + + def ReduceMax : Builtin { let Spellings = ["__builtin_reduce_max"]; let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index bdcd9ee43ce1c7..0cdcfc99a7c8b2 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -4454,6 +4454,20 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, return RValue::get(Result); } + case Builtin::BI__builtin_elementwise_mulh: { + Value *Op0 = EmitScalarExpr(E->getArg(0)); + Value *Op1 = EmitScalarExpr(E->getArg(1)); + Value *Result; + assert(Op0->getType()->isIntOrIntVectorTy() && "integer type expected"); + QualType Ty = E->getArg(0)->getType(); + if (auto *VecTy = Ty->getAs<VectorType>()) + Ty = VecTy->getElementType(); + bool IsSigned = Ty->isSignedIntegerType(); + unsigned Opc = IsSigned ? Intrinsic::smulh : Intrinsic::umulh; + Result = Builder.CreateBinaryIntrinsic(Opc, Op0, Op1, nullptr, "elt.mulh"); + return RValue::get(Result); + } + case Builtin::BI__builtin_elementwise_max: { Value *Op0 = EmitScalarExpr(E->getArg(0)); Value *Op1 = EmitScalarExpr(E->getArg(1)); diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index dfbfbf91b7cab4..4916624bb25cb0 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4025,6 +4025,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, case Builtin::BI__builtin_elementwise_clmul: case Builtin::BI__builtin_elementwise_pext: case Builtin::BI__builtin_elementwise_pdep: + case Builtin::BI__builtin_elementwise_mulh: if (BuiltinElementwiseMath(TheCall, EltwiseBuiltinArgTyRestriction::IntegerTy)) return ExprError(); diff --git a/clang/test/CodeGen/builtins-elementwise-math.c b/clang/test/CodeGen/builtins-elementwise-math.c index 63371ea7292288..1e7ddc5c56bbe9 100644 --- a/clang/test/CodeGen/builtins-elementwise-math.c +++ b/clang/test/CodeGen/builtins-elementwise-math.c @@ -1396,6 +1396,72 @@ void test_builtin_elementwise_pdep(unsigned int ui1, unsigned int ui2, bi1 = __builtin_elementwise_pdep(bi1, bi2); } +void test_builtin_elementwise_mulh(int i1, int i2, + unsigned int ui1, unsigned int ui2, + short is1, short is2, + unsigned short us1, unsigned short us2, + u4 vu1, u4 vu2, + int4 vi1, int4 vi2, + _BitInt(31) sbi1, + _BitInt(31) sbi2, + unsigned _BitInt(31) bi1, + unsigned _BitInt(31) bi2) { + // CHECK: [[I1:%.+]] = load i32, ptr %i1.addr, align 4 + // CHECK-NEXT: [[I2:%.+]] = load i32, ptr %i2.addr, align 4 + // CHECK-NEXT: [[I3:%.+]] = call i32 @llvm.smulh.i32(i32 [[I1]], i32 [[I2]]) + // CHECK-NEXT: store i32 [[I3]], ptr %i1.addr, align 4 + i1 = __builtin_elementwise_mulh(i1, i2); + + // CHECK: [[UI1:%.+]] = load i32, ptr %ui1.addr, align 4 + // CHECK-NEXT: [[UI2:%.+]] = load i32, ptr %ui2.addr, align 4 + // CHECK-NEXT: [[UI3:%.+]] = call i32 @llvm.umulh.i32(i32 [[UI1]], i32 [[UI2]]) + // CHECK-NEXT: store i32 [[UI3]], ptr %ui1.addr, align 4 + ui1 = __builtin_elementwise_mulh(ui1, ui2); + + // CHECK: [[IS1:%.+]] = load i16, ptr %is1.addr, align 2 + // CHECK-NEXT: [[IS2:%.+]] = load i16, ptr %is2.addr, align 2 + // CHECK-NEXT: [[IS3:%.+]] = call i16 @llvm.smulh.i16(i16 [[IS1]], i16 [[IS2]]) + // CHECK-NEXT: store i16 [[IS3]], ptr %is1.addr, align 2 + is1 = __builtin_elementwise_mulh(is1, is2); + + // CHECK: [[US1:%.+]] = load i16, ptr %us1.addr, align 2 + // CHECK-NEXT: [[US2:%.+]] = load i16, ptr %us2.addr, align 2 + // CHECK-NEXT: [[US3:%.+]] = call i16 @llvm.umulh.i16(i16 [[US1]], i16 [[US2]]) + // CHECK-NEXT: store i16 [[US3]], ptr %us1.addr, align 2 + us1 = __builtin_elementwise_mulh(us1, us2); + + // CHECK: [[VI1:%.+]] = load <4 x i32>, ptr %vi1.addr, align 16 + // CHECK-NEXT: [[VI2:%.+]] = load <4 x i32>, ptr %vi2.addr, align 16 + // CHECK-NEXT: [[VI3:%.+]] = call <4 x i32> @llvm.smulh.v4i32(<4 x i32> [[VI1]], <4 x i32> [[VI2]]) + // CHECK-NEXT: store <4 x i32> [[VI3]], ptr %vi1.addr, align 16 + vi1 = __builtin_elementwise_mulh(vi1, vi2); + + // CHECK: [[VU1:%.+]] = load <4 x i32>, ptr %vu1.addr, align 16 + // CHECK-NEXT: [[VU2:%.+]] = load <4 x i32>, ptr %vu2.addr, align 16 + // CHECK-NEXT: [[VU3:%.+]] = call <4 x i32> @llvm.umulh.v4i32(<4 x i32> [[VU1]], <4 x i32> [[VU2]]) + // CHECK-NEXT: store <4 x i32> [[VU3]], ptr %vu1.addr, align 16 + vu1 = __builtin_elementwise_mulh(vu1, vu2); + + // CHECK: [[SBI1:%.+]] = load i32, ptr %sbi1.addr, align 4 + // CHECK-NEXT: [[SBI1TRUNC:%.+]] = trunc i32 [[SBI1]] to i31 + // CHECK-NEXT: [[SBI2:%.+]] = load i32, ptr %sbi2.addr, align 4 + // CHECK-NEXT: [[SBI2TRUNC:%.+]] = trunc i32 [[SBI2]] to i31 + // CHECK-NEXT: [[SBIRES:%.+]] = call i31 @llvm.smulh.i31(i31 [[SBI1TRUNC]], i31 [[SBI2TRUNC]]) + // CHECK-NEXT: [[SBIRESSEXT:%.+]] = sext i31 [[SBIRES]] to i32 + // CHECK-NEXT: store i32 [[SBIRESSEXT]], ptr %sbi1.addr, align 4 + sbi1 = __builtin_elementwise_mulh(sbi1, sbi2); + + // CHECK: [[BI1:%.+]] = load i32, ptr %bi1.addr, align 4 + // CHECK-NEXT: [[BI1TRUNC:%.+]] = trunc i32 [[BI1]] to i31 + // CHECK-NEXT: [[BI2:%.+]] = load i32, ptr %bi2.addr, align 4 + // CHECK-NEXT: [[BI2TRUNC:%.+]] = trunc i32 [[BI2]] to i31 + // CHECK-NEXT: [[BIRES:%.+]] = call i31 @llvm.umulh.i31(i31 [[BI1TRUNC]], i31 [[BI2TRUNC]]) + // CHECK-NEXT: [[BIRESZEXT:%.+]] = zext i31 [[BIRES]] to i32 + // CHECK-NEXT: store i32 [[BIRESZEXT]], ptr %bi1.addr, align 4 + bi1 = __builtin_elementwise_mulh(bi1, bi2); +} + + void test_builtin_elementwise_clzg(si8 vs1, si8 vs2, u4 vu1, long long int lli, short si, _BitInt(31) bi, int i, diff --git a/clang/test/Sema/builtins-elementwise-math.c b/clang/test/Sema/builtins-elementwise-math.c index 511d1d8b43329e..33a6fddbc8703e 100644 --- a/clang/test/Sema/builtins-elementwise-math.c +++ b/clang/test/Sema/builtins-elementwise-math.c @@ -282,6 +282,44 @@ void test_builtin_elementwise_pdep(int i, short s, double d, float4 v, vu = __builtin_elementwise_pdep(vu, vu); } +void test_builtin_elementwise_mulh(int i, short s, double d, float4 v, + int3 iv, unsigned3 uv, unsigned u, + unsigned4 vu, int *p) { + i = __builtin_elementwise_mulh(p, d); + // expected-error@-1 {{1st argument must be a scalar or vector of integer types (was 'int *')}} + + struct Foo foo = __builtin_elementwise_mulh(i, i); + // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'int'}} + + i = __builtin_elementwise_mulh(i); + // expected-error@-1 {{too few arguments to function call, expected 2, have 1}} + + i = __builtin_elementwise_mulh(); + // expected-error@-1 {{too few arguments to function call, expected 2, have 0}} + + i = __builtin_elementwise_mulh(i, i, i); + // expected-error@-1 {{too many arguments to function call, expected 2, have 3}} + + i = __builtin_elementwise_mulh(v, v); + // expected-error@-1 {{1st argument must be a scalar or vector of integer types (was 'float4' (vector of 4 'float' values))}} + + i = __builtin_elementwise_mulh(i, s); + // expected-error@-1 {{arguments are of different types ('int' vs 'short')}} + + i = __builtin_elementwise_mulh(uv, iv); + // expected-error@-1 {{arguments are of different types ('unsigned3' (vector of 3 'unsigned int' values) vs 'int3' (vector of 3 'int' values))}} + + unsigned _BitInt(31) ext; // expected-warning {{'_BitInt' in C17 and earlier is a Clang extension}} + ext = __builtin_elementwise_mulh(ext, ext); + signed _BitInt(31) ixt; // expected-warning {{'_BitInt' in C17 and earlier is a Clang extension}} + ixt = __builtin_elementwise_mulh(ixt, ixt); + + i = __builtin_elementwise_mulh(i, i); + iv = __builtin_elementwise_mulh(iv, iv); + u = __builtin_elementwise_mulh(u, u); + vu = __builtin_elementwise_mulh(vu, vu); +} + void test_builtin_elementwise_max(int i, short s, double d, float4 v, int3 iv, unsigned3 uv, int *p) { i = __builtin_elementwise_max(p, d); // expected-error@-1 {{1st argument must be a vector, integer or floating-point type (was 'int *')}} >From 6c9535af7afa30f6a9c55acddfb11f1c6510d91b Mon Sep 17 00:00:00 2001 From: suriaharon1 <[email protected]> Date: Thu, 19 Nov 2026 14:33:21 -0600 Subject: [PATCH 2/5] Remove extra blank line --- clang/include/clang/Basic/Builtins.td | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 879a0ac4c5f969..17a6f6fe79bf44 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -1898,7 +1898,6 @@ def ElementwiseMulh : Builtin { let Prototype = "void(...)"; } - def ReduceMax : Builtin { let Spellings = ["__builtin_reduce_max"]; let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr]; >From df70aba4aaa9d3cf1de30ec128c3cdb932c3fe36 Mon Sep 17 00:00:00 2001 From: suriaharon1 <[email protected]> Date: Fri, 20 Nov 2026 19:06:21 -0600 Subject: [PATCH 3/5] Add constexpr support for __builtin_elementwise_mulh --- clang/include/clang/Basic/Builtins.td | 2 +- clang/lib/AST/ByteCode/InterpBuiltin.cpp | 6 ++++ clang/lib/AST/ExprConstant.cpp | 15 ++++++++- clang/test/AST/ByteCode/builtin-functions.cpp | 31 +++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 17a6f6fe79bf44..c955c035b6c8c8 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -1894,7 +1894,7 @@ def ElementwisePdep : Builtin { def ElementwiseMulh : Builtin { let Spellings = ["__builtin_elementwise_mulh"]; - let Attributes = [NoThrow, Const, CustomTypeChecking]; + let Attributes = [NoThrow, Const, CustomTypeChecking,Constexpr]; let Prototype = "void(...)"; } diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index ff7a8a7c098276..cac0971fffadec 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -5627,6 +5627,12 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call, return LHS.isSigned() ? LHS.ssub_sat(RHS) : LHS.usub_sat(RHS); }); + case Builtin::BI__builtin_elementwise_mulh: + return interp__builtin_elementwise_int_binop( + S, OpPC, Call,[](const APSInt &LHS, const APSInt &RHS) { + return LHS.isSigned() ? llvm::APIntOps::mulhs(LHS,RHS) : llvm::APIntOps::mulhu(LHS,RHS); + }); + case Builtin::BI__builtin_elementwise_pdep: return interp__builtin_elementwise_int_binop(S, OpPC, Call, llvm::APIntOps::pdep); diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 647bb9c45f871a..5ae9b98098fbcf 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -13079,7 +13079,10 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) { return EvaluateBinOpExpr([](const APSInt &LHS, const APSInt &RHS) { return LHS.isSigned() ? LHS.ssub_sat(RHS) : LHS.usub_sat(RHS); }); - + case Builtin::BI__builtin_elementwise_mulh: + return EvaluateBinOpExpr([](const APSInt &LHS, const APSInt &RHS) { + return LHS.isSigned() ? llvm::APIntOps::mulhs(LHS,RHS) : llvm::APIntOps::mulhu(LHS,RHS); + }); case X86::BI__builtin_ia32_extract128i256: case X86::BI__builtin_ia32_vextractf128_pd256: case X86::BI__builtin_ia32_vextractf128_ps256: @@ -18211,6 +18214,16 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, APInt Result = LHS.isSigned() ? LHS.ssub_sat(RHS) : LHS.usub_sat(RHS); return Success(APSInt(Result, !LHS.isSigned()), E); } + case Builtin::BI__builtin_elementwise_mulh: { + APSInt LHS, RHS; + if (!EvaluateInteger(E->getArg(0), LHS, Info) || + !EvaluateInteger(E->getArg(1), RHS, Info)) + return false; + + APInt Result = LHS.isSigned() ? llvm::APIntOps::mulhs(LHS,RHS) : llvm::APIntOps::mulhu(LHS,RHS); + return Success(APSInt(Result, !LHS.isSigned()), E); + } + case Builtin::BI__builtin_elementwise_max: { APSInt LHS, RHS; if (!EvaluateInteger(E->getArg(0), LHS, Info) || diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp index dc6d2274d82930..1df138c0841977 100644 --- a/clang/test/AST/ByteCode/builtin-functions.cpp +++ b/clang/test/AST/ByteCode/builtin-functions.cpp @@ -1475,6 +1475,37 @@ namespace ElementwisePdep { (vector4uint){0xCCU, 0xAAU, 0x0FU, 0x00U})) == 0x137U); } +namespace ElementwiseMulh { +#if __INT_WIDTH__ == 32 + static_assert(__builtin_elementwise_mulh(0U, 0U) == 0U); + static_assert(__builtin_elementwise_mulh(0xFFFFFFFFU, 2U) == 0x1U); + static_assert(__builtin_elementwise_mulh(-1, 2) == -1); + static_assert(__builtin_elementwise_mulh(0xFFFFFFFFU, 0xFFFFFFFFU) == + 0xFFFFFFFEU); + static_assert(__builtin_elementwise_mulh(1 << 30, 8) == 2); + static_assert(__builtin_elementwise_mulh((-2147483647 - 1), + (-2147483647 - 1)) == + 0x40000000); + + static_assert(__builtin_reduce_add(__builtin_elementwise_mulh( + (vector4uint){0xFFFFFFFEU, 0x10000U, 0x05U, 0x40000000U}, + (vector4uint){2U, 0x10000U, 0x0FU, 8U})) == 4U); + + static_assert(__builtin_reduce_add(__builtin_elementwise_mulh( + (vector4int){-1, -2147483647 - 1, -(1 << 30), 1 << 30}, + (vector4int){2, -2147483647 - 1, 8, 8})) == 0x3FFFFFFF); +#endif + +#ifndef __AVR__ + static_assert(__builtin_elementwise_mulh((unsigned _BitInt(31))(1 << 30), + (unsigned _BitInt(31))8) == + (unsigned _BitInt(31))4); + static_assert(__builtin_elementwise_mulh((_BitInt(31))(-1), + (_BitInt(31))2) == + (_BitInt(31))-1); +#endif +} + namespace BuiltinMemcpy { constexpr int simple() { int a = 12; >From be0e09bf8e63d47bd1380b2099c7d8bda40cb373 Mon Sep 17 00:00:00 2001 From: suriaharon1 <[email protected]> Date: Fri, 20 Nov 2026 19:06:37 -0600 Subject: [PATCH 4/5] Apply clang-format --- clang/lib/AST/ByteCode/InterpBuiltin.cpp | 5 +++-- clang/lib/AST/ExprConstant.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index cac0971fffadec..4b14add9c7282d 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -5629,8 +5629,9 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call, case Builtin::BI__builtin_elementwise_mulh: return interp__builtin_elementwise_int_binop( - S, OpPC, Call,[](const APSInt &LHS, const APSInt &RHS) { - return LHS.isSigned() ? llvm::APIntOps::mulhs(LHS,RHS) : llvm::APIntOps::mulhu(LHS,RHS); + S, OpPC, Call, [](const APSInt &LHS, const APSInt &RHS) { + return LHS.isSigned() ? llvm::APIntOps::mulhs(LHS, RHS) + : llvm::APIntOps::mulhu(LHS, RHS); }); case Builtin::BI__builtin_elementwise_pdep: diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 5ae9b98098fbcf..613fa2bfcf6077 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -13081,8 +13081,9 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) { }); case Builtin::BI__builtin_elementwise_mulh: return EvaluateBinOpExpr([](const APSInt &LHS, const APSInt &RHS) { - return LHS.isSigned() ? llvm::APIntOps::mulhs(LHS,RHS) : llvm::APIntOps::mulhu(LHS,RHS); - }); + return LHS.isSigned() ? llvm::APIntOps::mulhs(LHS, RHS) + : llvm::APIntOps::mulhu(LHS, RHS); + }); case X86::BI__builtin_ia32_extract128i256: case X86::BI__builtin_ia32_vextractf128_pd256: case X86::BI__builtin_ia32_vextractf128_ps256: @@ -18220,10 +18221,11 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, !EvaluateInteger(E->getArg(1), RHS, Info)) return false; - APInt Result = LHS.isSigned() ? llvm::APIntOps::mulhs(LHS,RHS) : llvm::APIntOps::mulhu(LHS,RHS); + APInt Result = LHS.isSigned() ? llvm::APIntOps::mulhs(LHS, RHS) + : llvm::APIntOps::mulhu(LHS, RHS); return Success(APSInt(Result, !LHS.isSigned()), E); } - + case Builtin::BI__builtin_elementwise_max: { APSInt LHS, RHS; if (!EvaluateInteger(E->getArg(0), LHS, Info) || >From 607c3637a7f2206e01fbab022ca42a5a87aa07fb Mon Sep 17 00:00:00 2001 From: suriaharon1 <[email protected]> Date: Fri, 20 Nov 2026 19:13:58 -0600 Subject: [PATCH 5/5] Fix whitespace and update release note --- clang/include/clang/Basic/Builtins.td | 2 +- clang/lib/AST/ExprConstant.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index c955c035b6c8c8..bed7dd5d364c65 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -1894,7 +1894,7 @@ def ElementwisePdep : Builtin { def ElementwiseMulh : Builtin { let Spellings = ["__builtin_elementwise_mulh"]; - let Attributes = [NoThrow, Const, CustomTypeChecking,Constexpr]; + let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr]; let Prototype = "void(...)"; } diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 613fa2bfcf6077..496530b860e02a 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -13079,11 +13079,13 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) { return EvaluateBinOpExpr([](const APSInt &LHS, const APSInt &RHS) { return LHS.isSigned() ? LHS.ssub_sat(RHS) : LHS.usub_sat(RHS); }); + case Builtin::BI__builtin_elementwise_mulh: return EvaluateBinOpExpr([](const APSInt &LHS, const APSInt &RHS) { return LHS.isSigned() ? llvm::APIntOps::mulhs(LHS, RHS) : llvm::APIntOps::mulhu(LHS, RHS); }); + case X86::BI__builtin_ia32_extract128i256: case X86::BI__builtin_ia32_vextractf128_pd256: case X86::BI__builtin_ia32_vextractf128_ps256: _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
