[clang] [libclc] Clang: Deprecate float support from __builtin_elementwise_max (PR #180885)
YunQiang Su via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 26 02:38:27 PST 2026
https://github.com/wzssyqa updated https://github.com/llvm/llvm-project/pull/180885
>From 482b39fd79365abedb51867c24f8e952468476f0 Mon Sep 17 00:00:00 2001
From: YunQiang Su <yunqiang at isrc.iscas.ac.cn>
Date: Wed, 11 Feb 2026 13:12:50 +0800
Subject: [PATCH 1/7] Clang: Drop float support from __builtin_elementwise_max
Now we have
__builtin_elementwise_maxnum
__builtin_elementwise_maximum
__builtin_elementwise_maximumnum
---
clang/docs/LanguageExtensions.rst | 12 +---
clang/docs/ReleaseNotes.rst | 3 +
clang/lib/CodeGen/CGBuiltin.cpp | 32 ++++-----
.../test/CodeGen/builtins-elementwise-math.c | 70 +------------------
.../CodeGen/strictfp-elementwise-builtins.cpp | 24 +++----
5 files changed, 33 insertions(+), 108 deletions(-)
diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst
index 29328355c3e6f..745000e79027c 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -839,16 +839,8 @@ of different sizes and signs is forbidden in binary and ternary builtins.
T __builtin_elementwise_copysign(T x, T y) return the magnitude of x with the sign of y. floating point types
T __builtin_elementwise_fmod(T x, T y) return the floating-point remainder of (x/y) whose sign floating point types
matches the sign of x.
- T __builtin_elementwise_max(T x, T y) return x or y, whichever is larger integer and floating point types
- For floating point types, follows semantics of maxNum
- in IEEE 754-2008. See `LangRef
- <http://llvm.org/docs/LangRef.html#i-fminmax-family>`_
- for the comparison.
- T __builtin_elementwise_min(T x, T y) return x or y, whichever is smaller integer and floating point types
- For floating point types, follows semantics of minNum
- in IEEE 754-2008. See `LangRef
- <http://llvm.org/docs/LangRef.html#i-fminmax-family>`_
- for the comparison.
+ T __builtin_elementwise_max(T x, T y) return x or y, whichever is larger integer types
+ T __builtin_elementwise_min(T x, T y) return x or y, whichever is smaller integer types
T __builtin_elementwise_maxnum(T x, T y) return x or y, whichever is larger. Follows IEEE 754-2008 floating point types
semantics (maxNum) with +0.0>-0.0. See `LangRef
<http://llvm.org/docs/LangRef.html#i-fminmax-family>`_
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0dbea8efc2642..758982d6e6431 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -138,6 +138,9 @@ Non-comprehensive list of changes in this release
Usable in constant expressions. Implicit conversion is supported for
class/struct types with conversion operators.
+- Removed float types support from ``__builtin_elementwise_max`` and
+ ``__builtin_elementwise_min``.
+
New Compiler Flags
------------------
- New option ``-fms-anonymous-structs`` / ``-fno-ms-anonymous-structs`` added
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index cf686581240a5..bb66677fb40c9 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -4066,30 +4066,26 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
Value *Op0 = EmitScalarExpr(E->getArg(0));
Value *Op1 = EmitScalarExpr(E->getArg(1));
Value *Result;
- if (Op0->getType()->isIntOrIntVectorTy()) {
- QualType Ty = E->getArg(0)->getType();
- if (auto *VecTy = Ty->getAs<VectorType>())
- Ty = VecTy->getElementType();
- Result = Builder.CreateBinaryIntrinsic(
- Ty->isSignedIntegerType() ? Intrinsic::smax : Intrinsic::umax, Op0,
- Op1, nullptr, "elt.max");
- } else
- Result = Builder.CreateMaxNum(Op0, Op1, /*FMFSource=*/nullptr, "elt.max");
+ assert(Op0->getType()->isIntOrIntVectorTy());
+ QualType Ty = E->getArg(0)->getType();
+ if (auto *VecTy = Ty->getAs<VectorType>())
+ Ty = VecTy->getElementType();
+ Result = Builder.CreateBinaryIntrinsic(
+ Ty->isSignedIntegerType() ? Intrinsic::smax : Intrinsic::umax, Op0,
+ Op1, nullptr, "elt.max");
return RValue::get(Result);
}
case Builtin::BI__builtin_elementwise_min: {
Value *Op0 = EmitScalarExpr(E->getArg(0));
Value *Op1 = EmitScalarExpr(E->getArg(1));
Value *Result;
- if (Op0->getType()->isIntOrIntVectorTy()) {
- QualType Ty = E->getArg(0)->getType();
- if (auto *VecTy = Ty->getAs<VectorType>())
- Ty = VecTy->getElementType();
- Result = Builder.CreateBinaryIntrinsic(
- Ty->isSignedIntegerType() ? Intrinsic::smin : Intrinsic::umin, Op0,
- Op1, nullptr, "elt.min");
- } else
- Result = Builder.CreateMinNum(Op0, Op1, /*FMFSource=*/nullptr, "elt.min");
+ assert(Op0->getType()->isIntOrIntVectorTy());
+ QualType Ty = E->getArg(0)->getType();
+ if (auto *VecTy = Ty->getAs<VectorType>())
+ Ty = VecTy->getElementType();
+ Result = Builder.CreateBinaryIntrinsic(
+ Ty->isSignedIntegerType() ? Intrinsic::smin : Intrinsic::umin, Op0,
+ Op1, nullptr, "elt.min");
return RValue::get(Result);
}
diff --git a/clang/test/CodeGen/builtins-elementwise-math.c b/clang/test/CodeGen/builtins-elementwise-math.c
index 2df485f0155c3..a201403e8b6b1 100644
--- a/clang/test/CodeGen/builtins-elementwise-math.c
+++ b/clang/test/CodeGen/builtins-elementwise-math.c
@@ -339,32 +339,10 @@ void test_builtin_elementwise_minimum(float f1, float f2, double d1, double d2,
vf1 = __builtin_elementwise_minimum(vf2, cvf1);
}
-void test_builtin_elementwise_max(float f1, float f2, double d1, double d2,
- float4 vf1, float4 vf2, long long int i1,
- long long int i2, si8 vi1, si8 vi2,
+void test_builtin_elementwise_max(long long int i2, si8 vi1, si8 vi2, long long int i1,
unsigned u1, unsigned u2, u4 vu1, u4 vu2,
_BitInt(31) bi1, _BitInt(31) bi2,
unsigned _BitInt(55) bu1, unsigned _BitInt(55) bu2) {
- // CHECK-LABEL: define void @test_builtin_elementwise_max(
- // CHECK: [[F1:%.+]] = load float, ptr %f1.addr, align 4
- // CHECK-NEXT: [[F2:%.+]] = load float, ptr %f2.addr, align 4
- // CHECK-NEXT: call float @llvm.maxnum.f32(float [[F1]], float [[F2]])
- f1 = __builtin_elementwise_max(f1, f2);
-
- // CHECK: [[D1:%.+]] = load double, ptr %d1.addr, align 8
- // CHECK-NEXT: [[D2:%.+]] = load double, ptr %d2.addr, align 8
- // CHECK-NEXT: call double @llvm.maxnum.f64(double [[D1]], double [[D2]])
- d1 = __builtin_elementwise_max(d1, d2);
-
- // CHECK: [[D2:%.+]] = load double, ptr %d2.addr, align 8
- // CHECK-NEXT: call double @llvm.maxnum.f64(double 2.000000e+01, double [[D2]])
- d1 = __builtin_elementwise_max(20.0, d2);
-
- // CHECK: [[VF1:%.+]] = load <4 x float>, ptr %vf1.addr, align 16
- // CHECK-NEXT: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
- // CHECK-NEXT: call <4 x float> @llvm.maxnum.v4f32(<4 x float> [[VF1]], <4 x float> [[VF2]])
- vf1 = __builtin_elementwise_max(vf1, vf2);
-
// CHECK: [[I1:%.+]] = load i64, ptr %i1.addr, align 8
// CHECK-NEXT: [[I2:%.+]] = load i64, ptr %i2.addr, align 8
// CHECK-NEXT: call i64 @llvm.smax.i64(i64 [[I1]], i64 [[I2]])
@@ -403,17 +381,6 @@ void test_builtin_elementwise_max(float f1, float f2, double d1, double d2,
// CHECK-NEXT: call i55 @llvm.umax.i55(i55 [[LOADEDV2]], i55 [[LOADEDV3]])
bu1 = __builtin_elementwise_max(bu1, bu2);
- // CHECK: [[CVF1:%.+]] = load <4 x float>, ptr %cvf1, align 16
- // CHECK-NEXT: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
- // CHECK-NEXT: call <4 x float> @llvm.maxnum.v4f32(<4 x float> [[CVF1]], <4 x float> [[VF2]])
- const float4 cvf1 = vf1;
- vf1 = __builtin_elementwise_max(cvf1, vf2);
-
- // CHECK: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
- // CHECK-NEXT: [[CVF1:%.+]] = load <4 x float>, ptr %cvf1, align 16
- // CHECK-NEXT: call <4 x float> @llvm.maxnum.v4f32(<4 x float> [[VF2]], <4 x float> [[CVF1]])
- vf1 = __builtin_elementwise_max(vf2, cvf1);
-
// CHECK: [[IAS1:%.+]] = load i32, ptr addrspace(1) @int_as_one, align 4
// CHECK-NEXT: [[B:%.+]] = load i32, ptr @b, align 4
// CHECK-NEXT: call i32 @llvm.smax.i32(i32 [[IAS1]], i32 [[B]])
@@ -423,32 +390,10 @@ void test_builtin_elementwise_max(float f1, float f2, double d1, double d2,
i1 = __builtin_elementwise_max(1, 'a');
}
-void test_builtin_elementwise_min(float f1, float f2, double d1, double d2,
- float4 vf1, float4 vf2, long long int i1,
- long long int i2, si8 vi1, si8 vi2,
+void test_builtin_elementwise_min(long long int i2, si8 vi1, si8 vi2, long long int i1,
unsigned u1, unsigned u2, u4 vu1, u4 vu2,
_BitInt(31) bi1, _BitInt(31) bi2,
unsigned _BitInt(55) bu1, unsigned _BitInt(55) bu2) {
- // CHECK-LABEL: define void @test_builtin_elementwise_min(
- // CHECK: [[F1:%.+]] = load float, ptr %f1.addr, align 4
- // CHECK-NEXT: [[F2:%.+]] = load float, ptr %f2.addr, align 4
- // CHECK-NEXT: call float @llvm.minnum.f32(float [[F1]], float [[F2]])
- f1 = __builtin_elementwise_min(f1, f2);
-
- // CHECK: [[D1:%.+]] = load double, ptr %d1.addr, align 8
- // CHECK-NEXT: [[D2:%.+]] = load double, ptr %d2.addr, align 8
- // CHECK-NEXT: call double @llvm.minnum.f64(double [[D1]], double [[D2]])
- d1 = __builtin_elementwise_min(d1, d2);
-
- // CHECK: [[D1:%.+]] = load double, ptr %d1.addr, align 8
- // CHECK-NEXT: call double @llvm.minnum.f64(double [[D1]], double 2.000000e+00)
- d1 = __builtin_elementwise_min(d1, 2.0);
-
- // CHECK: [[VF1:%.+]] = load <4 x float>, ptr %vf1.addr, align 16
- // CHECK-NEXT: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
- // CHECK-NEXT: call <4 x float> @llvm.minnum.v4f32(<4 x float> [[VF1]], <4 x float> [[VF2]])
- vf1 = __builtin_elementwise_min(vf1, vf2);
-
// CHECK: [[I1:%.+]] = load i64, ptr %i1.addr, align 8
// CHECK-NEXT: [[I2:%.+]] = load i64, ptr %i2.addr, align 8
// CHECK-NEXT: call i64 @llvm.smin.i64(i64 [[I1]], i64 [[I2]])
@@ -494,17 +439,6 @@ void test_builtin_elementwise_min(float f1, float f2, double d1, double d2,
// CHECK-NEXT: call i55 @llvm.umin.i55(i55 [[LOADEDV2]], i55 [[LOADEDV3]])
bu1 = __builtin_elementwise_min(bu1, bu2);
- // CHECK: [[CVF1:%.+]] = load <4 x float>, ptr %cvf1, align 16
- // CHECK-NEXT: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
- // CHECK-NEXT: call <4 x float> @llvm.minnum.v4f32(<4 x float> [[CVF1]], <4 x float> [[VF2]])
- const float4 cvf1 = vf1;
- vf1 = __builtin_elementwise_min(cvf1, vf2);
-
- // CHECK: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
- // CHECK-NEXT: [[CVF1:%.+]] = load <4 x float>, ptr %cvf1, align 16
- // CHECK-NEXT: call <4 x float> @llvm.minnum.v4f32(<4 x float> [[VF2]], <4 x float> [[CVF1]])
- vf1 = __builtin_elementwise_min(vf2, cvf1);
-
// CHECK: [[IAS1:%.+]] = load i32, ptr addrspace(1) @int_as_one, align 4
// CHECK-NEXT: [[B:%.+]] = load i32, ptr @b, align 4
// CHECK-NEXT: call i32 @llvm.smin.i32(i32 [[IAS1]], i32 [[B]])
diff --git a/clang/test/CodeGen/strictfp-elementwise-builtins.cpp b/clang/test/CodeGen/strictfp-elementwise-builtins.cpp
index 6453d50f044aa..7de0a396e08f9 100644
--- a/clang/test/CodeGen/strictfp-elementwise-builtins.cpp
+++ b/clang/test/CodeGen/strictfp-elementwise-builtins.cpp
@@ -27,24 +27,24 @@ float4 strict_elementwise_abs(float4 a) {
return __builtin_elementwise_abs(a);
}
-// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_maxDv4_fS_
-// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-LABEL: define dso_local noundef <4 x float> @_Z25strict_elementwise_maxnumDv4_fS_
+// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR2]] {
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[ELT_MAX:%.*]] = tail call <4 x float> @llvm.experimental.constrained.maxnum.v4f32(<4 x float> [[A]], <4 x float> [[B]], metadata !"fpexcept.strict") #[[ATTR4]]
-// CHECK-NEXT: ret <4 x float> [[ELT_MAX]]
+// CHECK-NEXT: [[ELT_MAXNUM:%.*]] = tail call <4 x float> @llvm.maxnum.v4f32(<4 x float> [[A]], <4 x float> [[B]]) #[[ATTR4]]
+// CHECK-NEXT: ret <4 x float> [[ELT_MAXNUM]]
//
-float4 strict_elementwise_max(float4 a, float4 b) {
- return __builtin_elementwise_max(a, b);
+float4 strict_elementwise_maxnum(float4 a, float4 b) {
+ return __builtin_elementwise_maxnum(a, b);
}
-// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_minDv4_fS_
-// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-LABEL: define dso_local noundef <4 x float> @_Z25strict_elementwise_minnumDv4_fS_
+// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR2]] {
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[ELT_MIN:%.*]] = tail call <4 x float> @llvm.experimental.constrained.minnum.v4f32(<4 x float> [[A]], <4 x float> [[B]], metadata !"fpexcept.strict") #[[ATTR4]]
-// CHECK-NEXT: ret <4 x float> [[ELT_MIN]]
+// CHECK-NEXT: [[ELT_MINNUM:%.*]] = tail call <4 x float> @llvm.minnum.v4f32(<4 x float> [[A]], <4 x float> [[B]]) #[[ATTR4]]
+// CHECK-NEXT: ret <4 x float> [[ELT_MINNUM]]
//
-float4 strict_elementwise_min(float4 a, float4 b) {
- return __builtin_elementwise_min(a, b);
+float4 strict_elementwise_minnum(float4 a, float4 b) {
+ return __builtin_elementwise_minnum(a, b);
}
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z26strict_elementwise_maximumDv4_fS_
>From 0ec494c401ca2630a4b30d82bb2041c19df0e92a Mon Sep 17 00:00:00 2001
From: YunQiang Su <yunqiang at isrc.iscas.ac.cn>
Date: Wed, 11 Feb 2026 13:27:21 +0800
Subject: [PATCH 2/7] fix code format
---
clang/lib/CodeGen/CGBuiltin.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index bb66677fb40c9..3daf08771c7a0 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -4071,8 +4071,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
if (auto *VecTy = Ty->getAs<VectorType>())
Ty = VecTy->getElementType();
Result = Builder.CreateBinaryIntrinsic(
- Ty->isSignedIntegerType() ? Intrinsic::smax : Intrinsic::umax, Op0,
- Op1, nullptr, "elt.max");
+ Ty->isSignedIntegerType() ? Intrinsic::smax : Intrinsic::umax, Op0, Op1,
+ nullptr, "elt.max");
return RValue::get(Result);
}
case Builtin::BI__builtin_elementwise_min: {
@@ -4084,8 +4084,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
if (auto *VecTy = Ty->getAs<VectorType>())
Ty = VecTy->getElementType();
Result = Builder.CreateBinaryIntrinsic(
- Ty->isSignedIntegerType() ? Intrinsic::smin : Intrinsic::umin, Op0,
- Op1, nullptr, "elt.min");
+ Ty->isSignedIntegerType() ? Intrinsic::smin : Intrinsic::umin, Op0, Op1,
+ nullptr, "elt.min");
return RValue::get(Result);
}
>From 52afce43f65c356e3d21073495e26ff96fcec6da Mon Sep 17 00:00:00 2001
From: YunQiang Su <yunqiang at isrc.iscas.ac.cn>
Date: Wed, 11 Feb 2026 23:41:28 +0800
Subject: [PATCH 3/7] update test cases
---
.../CodeGenHLSL/builtins/max-overloads.hlsl | 35 +------------
clang/test/CodeGenHLSL/builtins/max.hlsl | 49 +----------------
.../CodeGenHLSL/builtins/min-overloads.hlsl | 35 +------------
clang/test/CodeGenHLSL/builtins/min.hlsl | 52 +------------------
.../vec-scalar-compat-overload-warnings.hlsl | 20 -------
5 files changed, 4 insertions(+), 187 deletions(-)
diff --git a/clang/test/CodeGenHLSL/builtins/max-overloads.hlsl b/clang/test/CodeGenHLSL/builtins/max-overloads.hlsl
index da5cd8ff37510..6a99f2dee6c1f 100644
--- a/clang/test/CodeGenHLSL/builtins/max-overloads.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/max-overloads.hlsl
@@ -1,7 +1,7 @@
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
// RUN: -fnative-half-type -fnative-int16-type -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
-// RUN: -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
+// RUN: -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK
#ifdef __HLSL_ENABLE_16_BIT
// NATIVE_HALF-LABEL: define hidden noundef <4 x i16> {{.*}}test_max_short4_mismatch
@@ -46,36 +46,3 @@ int64_t4 test_max_long4_mismatch(int64_t4 p0, int64_t p1) { return max(p0, p1);
// CHECK: [[MAX:%.*]] = call noundef <4 x i64> @llvm.umax.v4i64(<4 x i64> %{{.*}}, <4 x i64> [[CONV1]])
// CHECK: ret <4 x i64> [[MAX]]
uint64_t4 test_max_ulong4_mismatch(uint64_t4 p0, uint64_t p1) { return max(p0, p1); }
-
-// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x half> {{.*}}test_max_half4_mismatch
-// NATIVE_HALF: [[CONV0:%.*]] = insertelement <4 x half> poison, half %{{.*}}, i64 0
-// NATIVE_HALF: [[CONV1:%.*]] = shufflevector <4 x half> [[CONV0]], <4 x half> poison, <4 x i32> zeroinitializer
-// NATIVE_HALF: [[MAX:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x half> @llvm.maxnum.v4f16(<4 x half> %{{.*}}, <4 x half> [[CONV1]])
-// NATIVE_HALF: ret <4 x half> [[MAX]]
-// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> {{.*}}test_max_half4_mismatch
-// NO_HALF: [[CONV0:%.*]] = insertelement <4 x float> poison, float %{{.*}}, i64 0
-// NO_HALF: [[CONV1:%.*]] = shufflevector <4 x float> [[CONV0]], <4 x float> poison, <4 x i32> zeroinitializer
-// NO_HALF: [[MAX:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x float> @llvm.maxnum.v4f32(<4 x float> %{{.*}}, <4 x float> [[CONV1]])
-// NO_HALF: ret <4 x float> [[MAX]]
-half4 test_max_half4_mismatch(half4 p0, half p1) { return max(p0, p1); }
-
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> {{.*}}test_max_float4_mismatch
-// CHECK: [[CONV0:%.*]] = insertelement <4 x float> poison, float %{{.*}}, i64 0
-// CHECK: [[CONV1:%.*]] = shufflevector <4 x float> [[CONV0]], <4 x float> poison, <4 x i32> zeroinitializer
-// CHECK: [[MAX:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x float> @llvm.maxnum.v4f32(<4 x float> %{{.*}}, <4 x float> [[CONV1]])
-// CHECK: ret <4 x float> [[MAX]]
-float4 test_max_float4_mismatch(float4 p0, float p1) { return max(p0, p1); }
-
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x double> {{.*}}test_max_double4_mismatch
-// CHECK: [[CONV0:%.*]] = insertelement <4 x double> poison, double %{{.*}}, i64 0
-// CHECK: [[CONV1:%.*]] = shufflevector <4 x double> [[CONV0]], <4 x double> poison, <4 x i32> zeroinitializer
-// CHECK: [[MAX:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x double> @llvm.maxnum.v4f64(<4 x double> %{{.*}}, <4 x double> [[CONV1]])
-// CHECK: ret <4 x double> [[MAX]]
-double4 test_max_double4_mismatch(double4 p0, double p1) { return max(p0, p1); }
-
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x double> {{.*}}test_max_double4_mismatch2
-// CHECK: [[CONV0:%.*]] = insertelement <4 x double> poison, double %{{.*}}, i64 0
-// CHECK: [[CONV1:%.*]] = shufflevector <4 x double> [[CONV0]], <4 x double> poison, <4 x i32> zeroinitializer
-// CHECK: [[MAX:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x double> @llvm.maxnum.v4f64(<4 x double> [[CONV1]], <4 x double> %{{.*}})
-// CHECK: ret <4 x double> [[MAX]]
-double4 test_max_double4_mismatch2(double4 p0, double p1) { return max(p1, p0); }
diff --git a/clang/test/CodeGenHLSL/builtins/max.hlsl b/clang/test/CodeGenHLSL/builtins/max.hlsl
index 9c621e62b5336..266859710947f 100644
--- a/clang/test/CodeGenHLSL/builtins/max.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/max.hlsl
@@ -3,7 +3,7 @@
// RUN: FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
// RUN: -emit-llvm -disable-llvm-passes -o - | \
-// RUN: FileCheck %s --check-prefixes=CHECK,NO_HALF
+// RUN: FileCheck %s --check-prefixes=CHECK
#ifdef __HLSL_ENABLE_16_BIT
// NATIVE_HALF-LABEL: define hidden noundef i16 @_Z14test_max_short
@@ -84,50 +84,3 @@ uint64_t3 test_max_ulong3(uint64_t3 p0, uint64_t3 p1) { return max(p0, p1); }
// CHECK-LABEL: define hidden noundef <4 x i64> @_Z15test_max_ulong4
// CHECK: call <4 x i64> @llvm.umax.v4i64
uint64_t4 test_max_ulong4(uint64_t4 p0, uint64_t4 p1) { return max(p0, p1); }
-
-// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) half @_Z13test_max_half
-// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn half @llvm.maxnum.f16(
-// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) float @_Z13test_max_half
-// NO_HALF: call reassoc nnan ninf nsz arcp afn float @llvm.maxnum.f32(
-half test_max_half(half p0, half p1) { return max(p0, p1); }
-// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <2 x half> @_Z14test_max_half2
-// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <2 x half> @llvm.maxnum.v2f16
-// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <2 x float> @_Z14test_max_half2
-// NO_HALF: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.maxnum.v2f32(
-half2 test_max_half2(half2 p0, half2 p1) { return max(p0, p1); }
-// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <3 x half> @_Z14test_max_half3
-// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <3 x half> @llvm.maxnum.v3f16
-// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <3 x float> @_Z14test_max_half3
-// NO_HALF: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.maxnum.v3f32(
-half3 test_max_half3(half3 p0, half3 p1) { return max(p0, p1); }
-// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x half> @_Z14test_max_half4
-// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <4 x half> @llvm.maxnum.v4f16
-// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> @_Z14test_max_half4
-// NO_HALF: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.maxnum.v4f32(
-half4 test_max_half4(half4 p0, half4 p1) { return max(p0, p1); }
-
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) float @_Z14test_max_float
-// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.maxnum.f32(
-float test_max_float(float p0, float p1) { return max(p0, p1); }
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <2 x float> @_Z15test_max_float2
-// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.maxnum.v2f32
-float2 test_max_float2(float2 p0, float2 p1) { return max(p0, p1); }
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <3 x float> @_Z15test_max_float3
-// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.maxnum.v3f32
-float3 test_max_float3(float3 p0, float3 p1) { return max(p0, p1); }
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> @_Z15test_max_float4
-// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.maxnum.v4f32
-float4 test_max_float4(float4 p0, float4 p1) { return max(p0, p1); }
-
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) double @_Z15test_max_double
-// CHECK: call reassoc nnan ninf nsz arcp afn double @llvm.maxnum.f64(
-double test_max_double(double p0, double p1) { return max(p0, p1); }
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <2 x double> @_Z16test_max_double2
-// CHECK: call reassoc nnan ninf nsz arcp afn <2 x double> @llvm.maxnum.v2f64
-double2 test_max_double2(double2 p0, double2 p1) { return max(p0, p1); }
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <3 x double> @_Z16test_max_double3
-// CHECK: call reassoc nnan ninf nsz arcp afn <3 x double> @llvm.maxnum.v3f64
-double3 test_max_double3(double3 p0, double3 p1) { return max(p0, p1); }
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x double> @_Z16test_max_double4
-// CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.maxnum.v4f64
-double4 test_max_double4(double4 p0, double4 p1) { return max(p0, p1); }
diff --git a/clang/test/CodeGenHLSL/builtins/min-overloads.hlsl b/clang/test/CodeGenHLSL/builtins/min-overloads.hlsl
index ee3455a07c8e1..bbbcc42181072 100644
--- a/clang/test/CodeGenHLSL/builtins/min-overloads.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/min-overloads.hlsl
@@ -1,7 +1,7 @@
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
// RUN: -fnative-half-type -fnative-int16-type -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
-// RUN: -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
+// RUN: -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK
#ifdef __HLSL_ENABLE_16_BIT
// NATIVE_HALF-LABEL: define hidden noundef <4 x i16> {{.*}}test_min_short4_mismatch
@@ -46,36 +46,3 @@ int64_t4 test_min_long4_mismatch(int64_t4 p0, int64_t p1) { return min(p0, p1);
// CHECK: [[MIN:%.*]] = call noundef <4 x i64> @llvm.umin.v4i64(<4 x i64> %{{.*}}, <4 x i64> [[CONV1]])
// CHECK: ret <4 x i64> [[MIN]]
uint64_t4 test_min_ulong4_mismatch(uint64_t4 p0, uint64_t p1) { return min(p0, p1); }
-
-// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x half> {{.*}}test_min_half4_mismatch
-// NATIVE_HALF: [[CONV0:%.*]] = insertelement <4 x half> poison, half %{{.*}}, i64 0
-// NATIVE_HALF: [[CONV1:%.*]] = shufflevector <4 x half> [[CONV0]], <4 x half> poison, <4 x i32> zeroinitializer
-// NATIVE_HALF: [[MIN:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x half> @llvm.minnum.v4f16(<4 x half> %{{.*}}, <4 x half> [[CONV1]])
-// NATIVE_HALF: ret <4 x half> [[MIN]]
-// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> {{.*}}test_min_half4_mismatch
-// NO_HALF: [[CONV0:%.*]] = insertelement <4 x float> poison, float %{{.*}}, i64 0
-// NO_HALF: [[CONV1:%.*]] = shufflevector <4 x float> [[CONV0]], <4 x float> poison, <4 x i32> zeroinitializer
-// NO_HALF: [[MIN:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x float> @llvm.minnum.v4f32(<4 x float> %{{.*}}, <4 x float> [[CONV1]])
-// NO_HALF: ret <4 x float> [[MIN]]
-half4 test_min_half4_mismatch(half4 p0, half p1) { return min(p0, p1); }
-
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> {{.*}}test_min_float4_mismatch
-// CHECK: [[CONV0:%.*]] = insertelement <4 x float> poison, float %{{.*}}, i64 0
-// CHECK: [[CONV1:%.*]] = shufflevector <4 x float> [[CONV0]], <4 x float> poison, <4 x i32> zeroinitializer
-// CHECK: [[MIN:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x float> @llvm.minnum.v4f32(<4 x float> %{{.*}}, <4 x float> [[CONV1]])
-// CHECK: ret <4 x float> [[MIN]]
-float4 test_min_float4_mismatch(float4 p0, float p1) { return min(p0, p1); }
-
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x double> {{.*}}test_min_double4_mismatch
-// CHECK: [[CONV0:%.*]] = insertelement <4 x double> poison, double %{{.*}}, i64 0
-// CHECK: [[CONV1:%.*]] = shufflevector <4 x double> [[CONV0]], <4 x double> poison, <4 x i32> zeroinitializer
-// CHECK: [[MIN:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x double> @llvm.minnum.v4f64(<4 x double> %{{.*}}, <4 x double> [[CONV1]])
-// CHECK: ret <4 x double> [[MIN]]
-double4 test_min_double4_mismatch(double4 p0, double p1) { return min(p0, p1); }
-
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x double> {{.*}}test_min_double4_mismatch2
-// CHECK: [[CONV0:%.*]] = insertelement <4 x double> poison, double %{{.*}}, i64 0
-// CHECK: [[CONV1:%.*]] = shufflevector <4 x double> [[CONV0]], <4 x double> poison, <4 x i32> zeroinitializer
-// CHECK: [[MIN:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x double> @llvm.minnum.v4f64(<4 x double> [[CONV1]], <4 x double> %{{.*}})
-// CHECK: ret <4 x double> [[MIN]]
-double4 test_min_double4_mismatch2(double4 p0, double p1) { return min(p1, p0); }
diff --git a/clang/test/CodeGenHLSL/builtins/min.hlsl b/clang/test/CodeGenHLSL/builtins/min.hlsl
index 44d2063229cdb..fae7888c6cce3 100644
--- a/clang/test/CodeGenHLSL/builtins/min.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/min.hlsl
@@ -3,7 +3,7 @@
// RUN: FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
// RUN: -emit-llvm -disable-llvm-passes -o - | \
-// RUN: FileCheck %s --check-prefixes=CHECK,NO_HALF
+// RUN: FileCheck %s --check-prefixes=CHECK
#ifdef __HLSL_ENABLE_16_BIT
// NATIVE_HALF-LABEL: define hidden noundef i16 @_Z14test_min_short
@@ -84,53 +84,3 @@ uint64_t3 test_min_ulong3(uint64_t3 p0, uint64_t3 p1) { return min(p0, p1); }
// CHECK-LABEL: define hidden noundef <4 x i64> @_Z15test_min_ulong4
// CHECK: call <4 x i64> @llvm.umin.v4i64
uint64_t4 test_min_ulong4(uint64_t4 p0, uint64_t4 p1) { return min(p0, p1); }
-
-// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) half @_Z13test_min_half
-// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn half @llvm.minnum.f16(
-// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) float @_Z13test_min_half
-// NO_HALF: call reassoc nnan ninf nsz arcp afn float @llvm.minnum.f32(
-half test_min_half(half p0, half p1) { return min(p0, p1); }
-// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <2 x half> @_Z14test_min_half2
-// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <2 x half> @llvm.minnum.v2f16
-// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <2 x float> @_Z14test_min_half2
-// NO_HALF: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.minnum.v2f32(
-half2 test_min_half2(half2 p0, half2 p1) { return min(p0, p1); }
-// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <3 x half> @_Z14test_min_half3
-// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <3 x half> @llvm.minnum.v3f16
-// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <3 x float> @_Z14test_min_half3
-// NO_HALF: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.minnum.v3f32(
-half3 test_min_half3(half3 p0, half3 p1) { return min(p0, p1); }
-// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x half> @_Z14test_min_half4
-// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <4 x half> @llvm.minnum.v4f16
-// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> @_Z14test_min_half4
-// NO_HALF: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.minnum.v4f32(
-half4 test_min_half4(half4 p0, half4 p1) { return min(p0, p1); }
-
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) float @_Z14test_min_float
-// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.minnum.f32(
-float test_min_float(float p0, float p1) { return min(p0, p1); }
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <2 x float> @_Z15test_min_float2
-// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.minnum.v2f32
-float2 test_min_float2(float2 p0, float2 p1) { return min(p0, p1); }
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <3 x float> @_Z15test_min_float3
-// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.minnum.v3f32
-float3 test_min_float3(float3 p0, float3 p1) { return min(p0, p1); }
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> @_Z15test_min_float4
-// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.minnum.v4f32
-float4 test_min_float4(float4 p0, float4 p1) { return min(p0, p1); }
-
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) double @_Z15test_min_double
-// CHECK: call reassoc nnan ninf nsz arcp afn double @llvm.minnum.f64(
-double test_min_double(double p0, double p1) { return min(p0, p1); }
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <2 x double> @_Z16test_min_double2
-// CHECK: call reassoc nnan ninf nsz arcp afn <2 x double> @llvm.minnum.v2f64
-double2 test_min_double2(double2 p0, double2 p1) { return min(p0, p1); }
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <3 x double> @_Z16test_min_double3
-// CHECK: call reassoc nnan ninf nsz arcp afn <3 x double> @llvm.minnum.v3f64
-double3 test_min_double3(double3 p0, double3 p1) { return min(p0, p1); }
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x double> @_Z16test_min_double4
-// CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.minnum.v4f64
-double4 test_min_double4(double4 p0, double4 p1) { return min(p0, p1); }
-// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x double> {{.*}}test_min_double4_mismatch
-// CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.minnum.v4f64
-double4 test_min_double4_mismatch(double4 p0, double p1) { return min(p0, p1); }
diff --git a/clang/test/SemaHLSL/BuiltIns/vec-scalar-compat-overload-warnings.hlsl b/clang/test/SemaHLSL/BuiltIns/vec-scalar-compat-overload-warnings.hlsl
index 9e942784041fa..f3b64d440c938 100644
--- a/clang/test/SemaHLSL/BuiltIns/vec-scalar-compat-overload-warnings.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/vec-scalar-compat-overload-warnings.hlsl
@@ -19,23 +19,3 @@ float3 lerp_test(float3 p0, float3 p1, float p2) {
// CHECK: warning: 'lerp<float, 3U>' is deprecated: In 202x mismatched vector/scalar lowering for lerp is deprecated. Explicitly cast parameters.
return lerp(p0, p1, p2);
}
-
-float2 max_test1(float2 p0, float p1) {
- // CHECK: warning: 'max<float, 2U>' is deprecated: In 202x mismatched vector/scalar lowering for max is deprecated. Explicitly cast parameters.
- return max(p0, p1);
-}
-
-float3 max_test2(float p0, float3 p1) {
- // CHECK: warning: 'max<float, 3U>' is deprecated: In 202x mismatched vector/scalar lowering for max is deprecated. Explicitly cast parameters.
- return max(p0, p1);
-}
-
-float2 min_test1(float2 p0, float p1) {
- // CHECK: warning: 'min<float, 2U>' is deprecated: In 202x mismatched vector/scalar lowering for min is deprecated. Explicitly cast parameters.
- return min(p0, p1);
-}
-
-float3 min_test2(float p0, float3 p1) {
- // CHECK: warning: 'min<float, 3U>' is deprecated: In 202x mismatched vector/scalar lowering for min is deprecated. Explicitly cast parameters.
- return min(p0, p1);
-}
>From 9fc9190fcb0cd8687fc295f4fd653ee561bd2db9 Mon Sep 17 00:00:00 2001
From: YunQiang Su <yunqiang at isrc.iscas.ac.cn>
Date: Wed, 25 Feb 2026 17:57:59 +0800
Subject: [PATCH 4/7] not remove, use deprecated
---
clang/docs/LanguageExtensions.rst | 12 +++-
.../clang/Basic/DiagnosticFrontendKinds.td | 2 +
clang/lib/CodeGen/CGBuiltin.cpp | 42 +++++++----
.../test/CodeGen/builtins-elementwise-math.c | 70 ++++++++++++++++++-
.../CodeGen/strictfp-elementwise-builtins.cpp | 24 +++----
.../CodeGenHLSL/builtins/max-overloads.hlsl | 35 +++++++++-
clang/test/CodeGenHLSL/builtins/max.hlsl | 49 ++++++++++++-
.../CodeGenHLSL/builtins/min-overloads.hlsl | 35 +++++++++-
clang/test/CodeGenHLSL/builtins/min.hlsl | 52 +++++++++++++-
.../vec-scalar-compat-overload-warnings.hlsl | 20 ++++++
libclc/clc/lib/generic/math/clc_fdim.inc | 2 +-
11 files changed, 308 insertions(+), 35 deletions(-)
diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst
index bac21e9434bc7..5943a51d5256d 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -839,8 +839,16 @@ of different sizes and signs is forbidden in binary and ternary builtins.
T __builtin_elementwise_copysign(T x, T y) return the magnitude of x with the sign of y. floating point types
T __builtin_elementwise_fmod(T x, T y) return the floating-point remainder of (x/y) whose sign floating point types
matches the sign of x.
- T __builtin_elementwise_max(T x, T y) return x or y, whichever is larger integer types
- T __builtin_elementwise_min(T x, T y) return x or y, whichever is smaller integer types
+ T __builtin_elementwise_max(T x, T y) return x or y, whichever is larger integer
+ For floating point types, follows semantics of maxNum floating point types (deprecated)
+ in IEEE 754-2008. See `LangRef
+ <http://llvm.org/docs/LangRef.html#i-fminmax-family>`_
+ for the comparison.
+ T __builtin_elementwise_min(T x, T y) return x or y, whichever is smaller integer
+ For floating point types, follows semantics of minNum floating point types (deprecated)
+ in IEEE 754-2008. See `LangRef
+ <http://llvm.org/docs/LangRef.html#i-fminmax-family>`_
+ for the comparison.
T __builtin_elementwise_maxnum(T x, T y) return x or y, whichever is larger. Follows IEEE 754-2008 floating point types
semantics (maxNum) with +0.0>-0.0. See `LangRef
<http://llvm.org/docs/LangRef.html#i-fminmax-family>`_
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 5c62bb70ebd0f..6a33e83f5fc4f 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -58,6 +58,8 @@ def warn_fe_backend_invalid_feature_flag : Warning<
def warn_fe_backend_readonly_feature_flag : Warning<
"feature flag '%0' is ignored since the feature is read only">,
InGroup<InvalidCommandLineArgument>;
+def warn_deprecated_float_builtin : Warning<"builtin %0 is deprecated; use %1 instead">,
+ InGroup<DeprecatedBuiltins>;
def err_incompatible_fp_eval_method_options : Error<
"option 'ffp-eval-method' cannot be used with option "
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a126212d173ab..89db8fa367578 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -4082,26 +4082,40 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
Value *Op0 = EmitScalarExpr(E->getArg(0));
Value *Op1 = EmitScalarExpr(E->getArg(1));
Value *Result;
- assert(Op0->getType()->isIntOrIntVectorTy());
- QualType Ty = E->getArg(0)->getType();
- if (auto *VecTy = Ty->getAs<VectorType>())
- Ty = VecTy->getElementType();
- Result = Builder.CreateBinaryIntrinsic(
- Ty->isSignedIntegerType() ? Intrinsic::smax : Intrinsic::umax, Op0, Op1,
- nullptr, "elt.max");
+ if (Op0->getType()->isIntOrIntVectorTy()) {
+ QualType Ty = E->getArg(0)->getType();
+ if (auto *VecTy = Ty->getAs<VectorType>())
+ Ty = VecTy->getElementType();
+ Result = Builder.CreateBinaryIntrinsic(
+ Ty->isSignedIntegerType() ? Intrinsic::smax : Intrinsic::umax, Op0,
+ Op1, nullptr, "elt.max");
+ } else {
+ DiagnosticsEngine &Diags = CGM.getDiags();
+ Diags.Report(E->getBeginLoc(), diag::warn_deprecated_float_builtin)
+ << "__builtin_elementwise_max"
+ << "__builtin_elementwise_maxnum/maximum/maximumnum";
+ Result = Builder.CreateMaxNum(Op0, Op1, /*FMFSource=*/nullptr, "elt.max");
+ }
return RValue::get(Result);
}
case Builtin::BI__builtin_elementwise_min: {
Value *Op0 = EmitScalarExpr(E->getArg(0));
Value *Op1 = EmitScalarExpr(E->getArg(1));
Value *Result;
- assert(Op0->getType()->isIntOrIntVectorTy());
- QualType Ty = E->getArg(0)->getType();
- if (auto *VecTy = Ty->getAs<VectorType>())
- Ty = VecTy->getElementType();
- Result = Builder.CreateBinaryIntrinsic(
- Ty->isSignedIntegerType() ? Intrinsic::smin : Intrinsic::umin, Op0, Op1,
- nullptr, "elt.min");
+ if (Op0->getType()->isIntOrIntVectorTy()) {
+ QualType Ty = E->getArg(0)->getType();
+ if (auto *VecTy = Ty->getAs<VectorType>())
+ Ty = VecTy->getElementType();
+ Result = Builder.CreateBinaryIntrinsic(
+ Ty->isSignedIntegerType() ? Intrinsic::smin : Intrinsic::umin, Op0,
+ Op1, nullptr, "elt.min");
+ } else {
+ DiagnosticsEngine &Diags = CGM.getDiags();
+ Diags.Report(E->getBeginLoc(), diag::warn_deprecated_float_builtin)
+ << "__builtin_elementwise_min"
+ << "__builtin_elementwise_minnum/minimum/minimumnum";
+ Result = Builder.CreateMinNum(Op0, Op1, /*FMFSource=*/nullptr, "elt.min");
+ }
return RValue::get(Result);
}
diff --git a/clang/test/CodeGen/builtins-elementwise-math.c b/clang/test/CodeGen/builtins-elementwise-math.c
index a201403e8b6b1..2df485f0155c3 100644
--- a/clang/test/CodeGen/builtins-elementwise-math.c
+++ b/clang/test/CodeGen/builtins-elementwise-math.c
@@ -339,10 +339,32 @@ void test_builtin_elementwise_minimum(float f1, float f2, double d1, double d2,
vf1 = __builtin_elementwise_minimum(vf2, cvf1);
}
-void test_builtin_elementwise_max(long long int i2, si8 vi1, si8 vi2, long long int i1,
+void test_builtin_elementwise_max(float f1, float f2, double d1, double d2,
+ float4 vf1, float4 vf2, long long int i1,
+ long long int i2, si8 vi1, si8 vi2,
unsigned u1, unsigned u2, u4 vu1, u4 vu2,
_BitInt(31) bi1, _BitInt(31) bi2,
unsigned _BitInt(55) bu1, unsigned _BitInt(55) bu2) {
+ // CHECK-LABEL: define void @test_builtin_elementwise_max(
+ // CHECK: [[F1:%.+]] = load float, ptr %f1.addr, align 4
+ // CHECK-NEXT: [[F2:%.+]] = load float, ptr %f2.addr, align 4
+ // CHECK-NEXT: call float @llvm.maxnum.f32(float [[F1]], float [[F2]])
+ f1 = __builtin_elementwise_max(f1, f2);
+
+ // CHECK: [[D1:%.+]] = load double, ptr %d1.addr, align 8
+ // CHECK-NEXT: [[D2:%.+]] = load double, ptr %d2.addr, align 8
+ // CHECK-NEXT: call double @llvm.maxnum.f64(double [[D1]], double [[D2]])
+ d1 = __builtin_elementwise_max(d1, d2);
+
+ // CHECK: [[D2:%.+]] = load double, ptr %d2.addr, align 8
+ // CHECK-NEXT: call double @llvm.maxnum.f64(double 2.000000e+01, double [[D2]])
+ d1 = __builtin_elementwise_max(20.0, d2);
+
+ // CHECK: [[VF1:%.+]] = load <4 x float>, ptr %vf1.addr, align 16
+ // CHECK-NEXT: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
+ // CHECK-NEXT: call <4 x float> @llvm.maxnum.v4f32(<4 x float> [[VF1]], <4 x float> [[VF2]])
+ vf1 = __builtin_elementwise_max(vf1, vf2);
+
// CHECK: [[I1:%.+]] = load i64, ptr %i1.addr, align 8
// CHECK-NEXT: [[I2:%.+]] = load i64, ptr %i2.addr, align 8
// CHECK-NEXT: call i64 @llvm.smax.i64(i64 [[I1]], i64 [[I2]])
@@ -381,6 +403,17 @@ void test_builtin_elementwise_max(long long int i2, si8 vi1, si8 vi2, long long
// CHECK-NEXT: call i55 @llvm.umax.i55(i55 [[LOADEDV2]], i55 [[LOADEDV3]])
bu1 = __builtin_elementwise_max(bu1, bu2);
+ // CHECK: [[CVF1:%.+]] = load <4 x float>, ptr %cvf1, align 16
+ // CHECK-NEXT: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
+ // CHECK-NEXT: call <4 x float> @llvm.maxnum.v4f32(<4 x float> [[CVF1]], <4 x float> [[VF2]])
+ const float4 cvf1 = vf1;
+ vf1 = __builtin_elementwise_max(cvf1, vf2);
+
+ // CHECK: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
+ // CHECK-NEXT: [[CVF1:%.+]] = load <4 x float>, ptr %cvf1, align 16
+ // CHECK-NEXT: call <4 x float> @llvm.maxnum.v4f32(<4 x float> [[VF2]], <4 x float> [[CVF1]])
+ vf1 = __builtin_elementwise_max(vf2, cvf1);
+
// CHECK: [[IAS1:%.+]] = load i32, ptr addrspace(1) @int_as_one, align 4
// CHECK-NEXT: [[B:%.+]] = load i32, ptr @b, align 4
// CHECK-NEXT: call i32 @llvm.smax.i32(i32 [[IAS1]], i32 [[B]])
@@ -390,10 +423,32 @@ void test_builtin_elementwise_max(long long int i2, si8 vi1, si8 vi2, long long
i1 = __builtin_elementwise_max(1, 'a');
}
-void test_builtin_elementwise_min(long long int i2, si8 vi1, si8 vi2, long long int i1,
+void test_builtin_elementwise_min(float f1, float f2, double d1, double d2,
+ float4 vf1, float4 vf2, long long int i1,
+ long long int i2, si8 vi1, si8 vi2,
unsigned u1, unsigned u2, u4 vu1, u4 vu2,
_BitInt(31) bi1, _BitInt(31) bi2,
unsigned _BitInt(55) bu1, unsigned _BitInt(55) bu2) {
+ // CHECK-LABEL: define void @test_builtin_elementwise_min(
+ // CHECK: [[F1:%.+]] = load float, ptr %f1.addr, align 4
+ // CHECK-NEXT: [[F2:%.+]] = load float, ptr %f2.addr, align 4
+ // CHECK-NEXT: call float @llvm.minnum.f32(float [[F1]], float [[F2]])
+ f1 = __builtin_elementwise_min(f1, f2);
+
+ // CHECK: [[D1:%.+]] = load double, ptr %d1.addr, align 8
+ // CHECK-NEXT: [[D2:%.+]] = load double, ptr %d2.addr, align 8
+ // CHECK-NEXT: call double @llvm.minnum.f64(double [[D1]], double [[D2]])
+ d1 = __builtin_elementwise_min(d1, d2);
+
+ // CHECK: [[D1:%.+]] = load double, ptr %d1.addr, align 8
+ // CHECK-NEXT: call double @llvm.minnum.f64(double [[D1]], double 2.000000e+00)
+ d1 = __builtin_elementwise_min(d1, 2.0);
+
+ // CHECK: [[VF1:%.+]] = load <4 x float>, ptr %vf1.addr, align 16
+ // CHECK-NEXT: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
+ // CHECK-NEXT: call <4 x float> @llvm.minnum.v4f32(<4 x float> [[VF1]], <4 x float> [[VF2]])
+ vf1 = __builtin_elementwise_min(vf1, vf2);
+
// CHECK: [[I1:%.+]] = load i64, ptr %i1.addr, align 8
// CHECK-NEXT: [[I2:%.+]] = load i64, ptr %i2.addr, align 8
// CHECK-NEXT: call i64 @llvm.smin.i64(i64 [[I1]], i64 [[I2]])
@@ -439,6 +494,17 @@ void test_builtin_elementwise_min(long long int i2, si8 vi1, si8 vi2, long long
// CHECK-NEXT: call i55 @llvm.umin.i55(i55 [[LOADEDV2]], i55 [[LOADEDV3]])
bu1 = __builtin_elementwise_min(bu1, bu2);
+ // CHECK: [[CVF1:%.+]] = load <4 x float>, ptr %cvf1, align 16
+ // CHECK-NEXT: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
+ // CHECK-NEXT: call <4 x float> @llvm.minnum.v4f32(<4 x float> [[CVF1]], <4 x float> [[VF2]])
+ const float4 cvf1 = vf1;
+ vf1 = __builtin_elementwise_min(cvf1, vf2);
+
+ // CHECK: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
+ // CHECK-NEXT: [[CVF1:%.+]] = load <4 x float>, ptr %cvf1, align 16
+ // CHECK-NEXT: call <4 x float> @llvm.minnum.v4f32(<4 x float> [[VF2]], <4 x float> [[CVF1]])
+ vf1 = __builtin_elementwise_min(vf2, cvf1);
+
// CHECK: [[IAS1:%.+]] = load i32, ptr addrspace(1) @int_as_one, align 4
// CHECK-NEXT: [[B:%.+]] = load i32, ptr @b, align 4
// CHECK-NEXT: call i32 @llvm.smin.i32(i32 [[IAS1]], i32 [[B]])
diff --git a/clang/test/CodeGen/strictfp-elementwise-builtins.cpp b/clang/test/CodeGen/strictfp-elementwise-builtins.cpp
index 7de0a396e08f9..6453d50f044aa 100644
--- a/clang/test/CodeGen/strictfp-elementwise-builtins.cpp
+++ b/clang/test/CodeGen/strictfp-elementwise-builtins.cpp
@@ -27,24 +27,24 @@ float4 strict_elementwise_abs(float4 a) {
return __builtin_elementwise_abs(a);
}
-// CHECK-LABEL: define dso_local noundef <4 x float> @_Z25strict_elementwise_maxnumDv4_fS_
-// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR2]] {
+// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_maxDv4_fS_
+// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR0]] {
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[ELT_MAXNUM:%.*]] = tail call <4 x float> @llvm.maxnum.v4f32(<4 x float> [[A]], <4 x float> [[B]]) #[[ATTR4]]
-// CHECK-NEXT: ret <4 x float> [[ELT_MAXNUM]]
+// CHECK-NEXT: [[ELT_MAX:%.*]] = tail call <4 x float> @llvm.experimental.constrained.maxnum.v4f32(<4 x float> [[A]], <4 x float> [[B]], metadata !"fpexcept.strict") #[[ATTR4]]
+// CHECK-NEXT: ret <4 x float> [[ELT_MAX]]
//
-float4 strict_elementwise_maxnum(float4 a, float4 b) {
- return __builtin_elementwise_maxnum(a, b);
+float4 strict_elementwise_max(float4 a, float4 b) {
+ return __builtin_elementwise_max(a, b);
}
-// CHECK-LABEL: define dso_local noundef <4 x float> @_Z25strict_elementwise_minnumDv4_fS_
-// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR2]] {
+// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_minDv4_fS_
+// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR0]] {
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[ELT_MINNUM:%.*]] = tail call <4 x float> @llvm.minnum.v4f32(<4 x float> [[A]], <4 x float> [[B]]) #[[ATTR4]]
-// CHECK-NEXT: ret <4 x float> [[ELT_MINNUM]]
+// CHECK-NEXT: [[ELT_MIN:%.*]] = tail call <4 x float> @llvm.experimental.constrained.minnum.v4f32(<4 x float> [[A]], <4 x float> [[B]], metadata !"fpexcept.strict") #[[ATTR4]]
+// CHECK-NEXT: ret <4 x float> [[ELT_MIN]]
//
-float4 strict_elementwise_minnum(float4 a, float4 b) {
- return __builtin_elementwise_minnum(a, b);
+float4 strict_elementwise_min(float4 a, float4 b) {
+ return __builtin_elementwise_min(a, b);
}
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z26strict_elementwise_maximumDv4_fS_
diff --git a/clang/test/CodeGenHLSL/builtins/max-overloads.hlsl b/clang/test/CodeGenHLSL/builtins/max-overloads.hlsl
index 6a99f2dee6c1f..da5cd8ff37510 100644
--- a/clang/test/CodeGenHLSL/builtins/max-overloads.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/max-overloads.hlsl
@@ -1,7 +1,7 @@
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
// RUN: -fnative-half-type -fnative-int16-type -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
-// RUN: -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK
+// RUN: -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
#ifdef __HLSL_ENABLE_16_BIT
// NATIVE_HALF-LABEL: define hidden noundef <4 x i16> {{.*}}test_max_short4_mismatch
@@ -46,3 +46,36 @@ int64_t4 test_max_long4_mismatch(int64_t4 p0, int64_t p1) { return max(p0, p1);
// CHECK: [[MAX:%.*]] = call noundef <4 x i64> @llvm.umax.v4i64(<4 x i64> %{{.*}}, <4 x i64> [[CONV1]])
// CHECK: ret <4 x i64> [[MAX]]
uint64_t4 test_max_ulong4_mismatch(uint64_t4 p0, uint64_t p1) { return max(p0, p1); }
+
+// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x half> {{.*}}test_max_half4_mismatch
+// NATIVE_HALF: [[CONV0:%.*]] = insertelement <4 x half> poison, half %{{.*}}, i64 0
+// NATIVE_HALF: [[CONV1:%.*]] = shufflevector <4 x half> [[CONV0]], <4 x half> poison, <4 x i32> zeroinitializer
+// NATIVE_HALF: [[MAX:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x half> @llvm.maxnum.v4f16(<4 x half> %{{.*}}, <4 x half> [[CONV1]])
+// NATIVE_HALF: ret <4 x half> [[MAX]]
+// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> {{.*}}test_max_half4_mismatch
+// NO_HALF: [[CONV0:%.*]] = insertelement <4 x float> poison, float %{{.*}}, i64 0
+// NO_HALF: [[CONV1:%.*]] = shufflevector <4 x float> [[CONV0]], <4 x float> poison, <4 x i32> zeroinitializer
+// NO_HALF: [[MAX:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x float> @llvm.maxnum.v4f32(<4 x float> %{{.*}}, <4 x float> [[CONV1]])
+// NO_HALF: ret <4 x float> [[MAX]]
+half4 test_max_half4_mismatch(half4 p0, half p1) { return max(p0, p1); }
+
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> {{.*}}test_max_float4_mismatch
+// CHECK: [[CONV0:%.*]] = insertelement <4 x float> poison, float %{{.*}}, i64 0
+// CHECK: [[CONV1:%.*]] = shufflevector <4 x float> [[CONV0]], <4 x float> poison, <4 x i32> zeroinitializer
+// CHECK: [[MAX:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x float> @llvm.maxnum.v4f32(<4 x float> %{{.*}}, <4 x float> [[CONV1]])
+// CHECK: ret <4 x float> [[MAX]]
+float4 test_max_float4_mismatch(float4 p0, float p1) { return max(p0, p1); }
+
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x double> {{.*}}test_max_double4_mismatch
+// CHECK: [[CONV0:%.*]] = insertelement <4 x double> poison, double %{{.*}}, i64 0
+// CHECK: [[CONV1:%.*]] = shufflevector <4 x double> [[CONV0]], <4 x double> poison, <4 x i32> zeroinitializer
+// CHECK: [[MAX:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x double> @llvm.maxnum.v4f64(<4 x double> %{{.*}}, <4 x double> [[CONV1]])
+// CHECK: ret <4 x double> [[MAX]]
+double4 test_max_double4_mismatch(double4 p0, double p1) { return max(p0, p1); }
+
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x double> {{.*}}test_max_double4_mismatch2
+// CHECK: [[CONV0:%.*]] = insertelement <4 x double> poison, double %{{.*}}, i64 0
+// CHECK: [[CONV1:%.*]] = shufflevector <4 x double> [[CONV0]], <4 x double> poison, <4 x i32> zeroinitializer
+// CHECK: [[MAX:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x double> @llvm.maxnum.v4f64(<4 x double> [[CONV1]], <4 x double> %{{.*}})
+// CHECK: ret <4 x double> [[MAX]]
+double4 test_max_double4_mismatch2(double4 p0, double p1) { return max(p1, p0); }
diff --git a/clang/test/CodeGenHLSL/builtins/max.hlsl b/clang/test/CodeGenHLSL/builtins/max.hlsl
index 266859710947f..9c621e62b5336 100644
--- a/clang/test/CodeGenHLSL/builtins/max.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/max.hlsl
@@ -3,7 +3,7 @@
// RUN: FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
// RUN: -emit-llvm -disable-llvm-passes -o - | \
-// RUN: FileCheck %s --check-prefixes=CHECK
+// RUN: FileCheck %s --check-prefixes=CHECK,NO_HALF
#ifdef __HLSL_ENABLE_16_BIT
// NATIVE_HALF-LABEL: define hidden noundef i16 @_Z14test_max_short
@@ -84,3 +84,50 @@ uint64_t3 test_max_ulong3(uint64_t3 p0, uint64_t3 p1) { return max(p0, p1); }
// CHECK-LABEL: define hidden noundef <4 x i64> @_Z15test_max_ulong4
// CHECK: call <4 x i64> @llvm.umax.v4i64
uint64_t4 test_max_ulong4(uint64_t4 p0, uint64_t4 p1) { return max(p0, p1); }
+
+// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) half @_Z13test_max_half
+// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn half @llvm.maxnum.f16(
+// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) float @_Z13test_max_half
+// NO_HALF: call reassoc nnan ninf nsz arcp afn float @llvm.maxnum.f32(
+half test_max_half(half p0, half p1) { return max(p0, p1); }
+// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <2 x half> @_Z14test_max_half2
+// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <2 x half> @llvm.maxnum.v2f16
+// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <2 x float> @_Z14test_max_half2
+// NO_HALF: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.maxnum.v2f32(
+half2 test_max_half2(half2 p0, half2 p1) { return max(p0, p1); }
+// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <3 x half> @_Z14test_max_half3
+// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <3 x half> @llvm.maxnum.v3f16
+// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <3 x float> @_Z14test_max_half3
+// NO_HALF: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.maxnum.v3f32(
+half3 test_max_half3(half3 p0, half3 p1) { return max(p0, p1); }
+// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x half> @_Z14test_max_half4
+// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <4 x half> @llvm.maxnum.v4f16
+// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> @_Z14test_max_half4
+// NO_HALF: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.maxnum.v4f32(
+half4 test_max_half4(half4 p0, half4 p1) { return max(p0, p1); }
+
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) float @_Z14test_max_float
+// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.maxnum.f32(
+float test_max_float(float p0, float p1) { return max(p0, p1); }
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <2 x float> @_Z15test_max_float2
+// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.maxnum.v2f32
+float2 test_max_float2(float2 p0, float2 p1) { return max(p0, p1); }
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <3 x float> @_Z15test_max_float3
+// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.maxnum.v3f32
+float3 test_max_float3(float3 p0, float3 p1) { return max(p0, p1); }
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> @_Z15test_max_float4
+// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.maxnum.v4f32
+float4 test_max_float4(float4 p0, float4 p1) { return max(p0, p1); }
+
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) double @_Z15test_max_double
+// CHECK: call reassoc nnan ninf nsz arcp afn double @llvm.maxnum.f64(
+double test_max_double(double p0, double p1) { return max(p0, p1); }
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <2 x double> @_Z16test_max_double2
+// CHECK: call reassoc nnan ninf nsz arcp afn <2 x double> @llvm.maxnum.v2f64
+double2 test_max_double2(double2 p0, double2 p1) { return max(p0, p1); }
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <3 x double> @_Z16test_max_double3
+// CHECK: call reassoc nnan ninf nsz arcp afn <3 x double> @llvm.maxnum.v3f64
+double3 test_max_double3(double3 p0, double3 p1) { return max(p0, p1); }
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x double> @_Z16test_max_double4
+// CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.maxnum.v4f64
+double4 test_max_double4(double4 p0, double4 p1) { return max(p0, p1); }
diff --git a/clang/test/CodeGenHLSL/builtins/min-overloads.hlsl b/clang/test/CodeGenHLSL/builtins/min-overloads.hlsl
index bbbcc42181072..ee3455a07c8e1 100644
--- a/clang/test/CodeGenHLSL/builtins/min-overloads.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/min-overloads.hlsl
@@ -1,7 +1,7 @@
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
// RUN: -fnative-half-type -fnative-int16-type -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
-// RUN: -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK
+// RUN: -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
#ifdef __HLSL_ENABLE_16_BIT
// NATIVE_HALF-LABEL: define hidden noundef <4 x i16> {{.*}}test_min_short4_mismatch
@@ -46,3 +46,36 @@ int64_t4 test_min_long4_mismatch(int64_t4 p0, int64_t p1) { return min(p0, p1);
// CHECK: [[MIN:%.*]] = call noundef <4 x i64> @llvm.umin.v4i64(<4 x i64> %{{.*}}, <4 x i64> [[CONV1]])
// CHECK: ret <4 x i64> [[MIN]]
uint64_t4 test_min_ulong4_mismatch(uint64_t4 p0, uint64_t p1) { return min(p0, p1); }
+
+// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x half> {{.*}}test_min_half4_mismatch
+// NATIVE_HALF: [[CONV0:%.*]] = insertelement <4 x half> poison, half %{{.*}}, i64 0
+// NATIVE_HALF: [[CONV1:%.*]] = shufflevector <4 x half> [[CONV0]], <4 x half> poison, <4 x i32> zeroinitializer
+// NATIVE_HALF: [[MIN:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x half> @llvm.minnum.v4f16(<4 x half> %{{.*}}, <4 x half> [[CONV1]])
+// NATIVE_HALF: ret <4 x half> [[MIN]]
+// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> {{.*}}test_min_half4_mismatch
+// NO_HALF: [[CONV0:%.*]] = insertelement <4 x float> poison, float %{{.*}}, i64 0
+// NO_HALF: [[CONV1:%.*]] = shufflevector <4 x float> [[CONV0]], <4 x float> poison, <4 x i32> zeroinitializer
+// NO_HALF: [[MIN:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x float> @llvm.minnum.v4f32(<4 x float> %{{.*}}, <4 x float> [[CONV1]])
+// NO_HALF: ret <4 x float> [[MIN]]
+half4 test_min_half4_mismatch(half4 p0, half p1) { return min(p0, p1); }
+
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> {{.*}}test_min_float4_mismatch
+// CHECK: [[CONV0:%.*]] = insertelement <4 x float> poison, float %{{.*}}, i64 0
+// CHECK: [[CONV1:%.*]] = shufflevector <4 x float> [[CONV0]], <4 x float> poison, <4 x i32> zeroinitializer
+// CHECK: [[MIN:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x float> @llvm.minnum.v4f32(<4 x float> %{{.*}}, <4 x float> [[CONV1]])
+// CHECK: ret <4 x float> [[MIN]]
+float4 test_min_float4_mismatch(float4 p0, float p1) { return min(p0, p1); }
+
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x double> {{.*}}test_min_double4_mismatch
+// CHECK: [[CONV0:%.*]] = insertelement <4 x double> poison, double %{{.*}}, i64 0
+// CHECK: [[CONV1:%.*]] = shufflevector <4 x double> [[CONV0]], <4 x double> poison, <4 x i32> zeroinitializer
+// CHECK: [[MIN:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x double> @llvm.minnum.v4f64(<4 x double> %{{.*}}, <4 x double> [[CONV1]])
+// CHECK: ret <4 x double> [[MIN]]
+double4 test_min_double4_mismatch(double4 p0, double p1) { return min(p0, p1); }
+
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x double> {{.*}}test_min_double4_mismatch2
+// CHECK: [[CONV0:%.*]] = insertelement <4 x double> poison, double %{{.*}}, i64 0
+// CHECK: [[CONV1:%.*]] = shufflevector <4 x double> [[CONV0]], <4 x double> poison, <4 x i32> zeroinitializer
+// CHECK: [[MIN:%.*]] = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x double> @llvm.minnum.v4f64(<4 x double> [[CONV1]], <4 x double> %{{.*}})
+// CHECK: ret <4 x double> [[MIN]]
+double4 test_min_double4_mismatch2(double4 p0, double p1) { return min(p1, p0); }
diff --git a/clang/test/CodeGenHLSL/builtins/min.hlsl b/clang/test/CodeGenHLSL/builtins/min.hlsl
index fae7888c6cce3..44d2063229cdb 100644
--- a/clang/test/CodeGenHLSL/builtins/min.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/min.hlsl
@@ -3,7 +3,7 @@
// RUN: FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
// RUN: -emit-llvm -disable-llvm-passes -o - | \
-// RUN: FileCheck %s --check-prefixes=CHECK
+// RUN: FileCheck %s --check-prefixes=CHECK,NO_HALF
#ifdef __HLSL_ENABLE_16_BIT
// NATIVE_HALF-LABEL: define hidden noundef i16 @_Z14test_min_short
@@ -84,3 +84,53 @@ uint64_t3 test_min_ulong3(uint64_t3 p0, uint64_t3 p1) { return min(p0, p1); }
// CHECK-LABEL: define hidden noundef <4 x i64> @_Z15test_min_ulong4
// CHECK: call <4 x i64> @llvm.umin.v4i64
uint64_t4 test_min_ulong4(uint64_t4 p0, uint64_t4 p1) { return min(p0, p1); }
+
+// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) half @_Z13test_min_half
+// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn half @llvm.minnum.f16(
+// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) float @_Z13test_min_half
+// NO_HALF: call reassoc nnan ninf nsz arcp afn float @llvm.minnum.f32(
+half test_min_half(half p0, half p1) { return min(p0, p1); }
+// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <2 x half> @_Z14test_min_half2
+// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <2 x half> @llvm.minnum.v2f16
+// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <2 x float> @_Z14test_min_half2
+// NO_HALF: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.minnum.v2f32(
+half2 test_min_half2(half2 p0, half2 p1) { return min(p0, p1); }
+// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <3 x half> @_Z14test_min_half3
+// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <3 x half> @llvm.minnum.v3f16
+// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <3 x float> @_Z14test_min_half3
+// NO_HALF: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.minnum.v3f32(
+half3 test_min_half3(half3 p0, half3 p1) { return min(p0, p1); }
+// NATIVE_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x half> @_Z14test_min_half4
+// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <4 x half> @llvm.minnum.v4f16
+// NO_HALF-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> @_Z14test_min_half4
+// NO_HALF: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.minnum.v4f32(
+half4 test_min_half4(half4 p0, half4 p1) { return min(p0, p1); }
+
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) float @_Z14test_min_float
+// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.minnum.f32(
+float test_min_float(float p0, float p1) { return min(p0, p1); }
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <2 x float> @_Z15test_min_float2
+// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.minnum.v2f32
+float2 test_min_float2(float2 p0, float2 p1) { return min(p0, p1); }
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <3 x float> @_Z15test_min_float3
+// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.minnum.v3f32
+float3 test_min_float3(float3 p0, float3 p1) { return min(p0, p1); }
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x float> @_Z15test_min_float4
+// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.minnum.v4f32
+float4 test_min_float4(float4 p0, float4 p1) { return min(p0, p1); }
+
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) double @_Z15test_min_double
+// CHECK: call reassoc nnan ninf nsz arcp afn double @llvm.minnum.f64(
+double test_min_double(double p0, double p1) { return min(p0, p1); }
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <2 x double> @_Z16test_min_double2
+// CHECK: call reassoc nnan ninf nsz arcp afn <2 x double> @llvm.minnum.v2f64
+double2 test_min_double2(double2 p0, double2 p1) { return min(p0, p1); }
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <3 x double> @_Z16test_min_double3
+// CHECK: call reassoc nnan ninf nsz arcp afn <3 x double> @llvm.minnum.v3f64
+double3 test_min_double3(double3 p0, double3 p1) { return min(p0, p1); }
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x double> @_Z16test_min_double4
+// CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.minnum.v4f64
+double4 test_min_double4(double4 p0, double4 p1) { return min(p0, p1); }
+// CHECK-LABEL: define hidden noundef nofpclass(nan inf) <4 x double> {{.*}}test_min_double4_mismatch
+// CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.minnum.v4f64
+double4 test_min_double4_mismatch(double4 p0, double p1) { return min(p0, p1); }
diff --git a/clang/test/SemaHLSL/BuiltIns/vec-scalar-compat-overload-warnings.hlsl b/clang/test/SemaHLSL/BuiltIns/vec-scalar-compat-overload-warnings.hlsl
index f3b64d440c938..9e942784041fa 100644
--- a/clang/test/SemaHLSL/BuiltIns/vec-scalar-compat-overload-warnings.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/vec-scalar-compat-overload-warnings.hlsl
@@ -19,3 +19,23 @@ float3 lerp_test(float3 p0, float3 p1, float p2) {
// CHECK: warning: 'lerp<float, 3U>' is deprecated: In 202x mismatched vector/scalar lowering for lerp is deprecated. Explicitly cast parameters.
return lerp(p0, p1, p2);
}
+
+float2 max_test1(float2 p0, float p1) {
+ // CHECK: warning: 'max<float, 2U>' is deprecated: In 202x mismatched vector/scalar lowering for max is deprecated. Explicitly cast parameters.
+ return max(p0, p1);
+}
+
+float3 max_test2(float p0, float3 p1) {
+ // CHECK: warning: 'max<float, 3U>' is deprecated: In 202x mismatched vector/scalar lowering for max is deprecated. Explicitly cast parameters.
+ return max(p0, p1);
+}
+
+float2 min_test1(float2 p0, float p1) {
+ // CHECK: warning: 'min<float, 2U>' is deprecated: In 202x mismatched vector/scalar lowering for min is deprecated. Explicitly cast parameters.
+ return min(p0, p1);
+}
+
+float3 min_test2(float p0, float3 p1) {
+ // CHECK: warning: 'min<float, 3U>' is deprecated: In 202x mismatched vector/scalar lowering for min is deprecated. Explicitly cast parameters.
+ return min(p0, p1);
+}
diff --git a/libclc/clc/lib/generic/math/clc_fdim.inc b/libclc/clc/lib/generic/math/clc_fdim.inc
index d34ee8c39a9d5..0a8463a71f7ef 100644
--- a/libclc/clc/lib/generic/math/clc_fdim.inc
+++ b/libclc/clc/lib/generic/math/clc_fdim.inc
@@ -8,7 +8,7 @@
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_fdim(__CLC_GENTYPE x,
__CLC_GENTYPE y) {
- return __clc_select(__builtin_elementwise_max(x - y, __CLC_FP_LIT(0.0)),
+ return __clc_select(__builtin_elementwise_maxnum(x - y, __CLC_FP_LIT(0.0)),
__CLC_GENTYPE_NAN,
__CLC_CONVERT_BIT_INTN(__clc_isnan(x) || __clc_isnan(y)));
}
>From 44658b8e125e59a2616f9450562dbb5d112d8e2e Mon Sep 17 00:00:00 2001
From: YunQiang Su <syq at debian.org>
Date: Thu, 26 Feb 2026 16:01:59 +0800
Subject: [PATCH 5/7] Use Sema
---
.../clang/Basic/DiagnosticFrontendKinds.td | 2 --
clang/lib/CodeGen/CGBuiltin.cpp | 14 ++------
clang/lib/Sema/SemaChecking.cpp | 33 +++++++++++++++++--
clang/test/Sema/builtins-elementwise-math.c | 17 ++++++++++
4 files changed, 50 insertions(+), 16 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 6a33e83f5fc4f..5c62bb70ebd0f 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -58,8 +58,6 @@ def warn_fe_backend_invalid_feature_flag : Warning<
def warn_fe_backend_readonly_feature_flag : Warning<
"feature flag '%0' is ignored since the feature is read only">,
InGroup<InvalidCommandLineArgument>;
-def warn_deprecated_float_builtin : Warning<"builtin %0 is deprecated; use %1 instead">,
- InGroup<DeprecatedBuiltins>;
def err_incompatible_fp_eval_method_options : Error<
"option 'ffp-eval-method' cannot be used with option "
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 89db8fa367578..850cc8d2c4c45 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -4089,13 +4089,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
Result = Builder.CreateBinaryIntrinsic(
Ty->isSignedIntegerType() ? Intrinsic::smax : Intrinsic::umax, Op0,
Op1, nullptr, "elt.max");
- } else {
- DiagnosticsEngine &Diags = CGM.getDiags();
- Diags.Report(E->getBeginLoc(), diag::warn_deprecated_float_builtin)
- << "__builtin_elementwise_max"
- << "__builtin_elementwise_maxnum/maximum/maximumnum";
+ } else
Result = Builder.CreateMaxNum(Op0, Op1, /*FMFSource=*/nullptr, "elt.max");
- }
return RValue::get(Result);
}
case Builtin::BI__builtin_elementwise_min: {
@@ -4109,13 +4104,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
Result = Builder.CreateBinaryIntrinsic(
Ty->isSignedIntegerType() ? Intrinsic::smin : Intrinsic::umin, Op0,
Op1, nullptr, "elt.min");
- } else {
- DiagnosticsEngine &Diags = CGM.getDiags();
- Diags.Report(E->getBeginLoc(), diag::warn_deprecated_float_builtin)
- << "__builtin_elementwise_min"
- << "__builtin_elementwise_minnum/minimum/minimumnum";
+ } else
Result = Builder.CreateMinNum(Op0, Op1, /*FMFSource=*/nullptr, "elt.min");
- }
return RValue::get(Result);
}
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0ea41ff1f613e..c390d6be2625d 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3558,11 +3558,40 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
TheCall, EltwiseBuiltinArgTyRestriction::IntegerTy))
return ExprError();
break;
- case Builtin::BI__builtin_elementwise_min:
- case Builtin::BI__builtin_elementwise_max:
+ case Builtin::BI__builtin_elementwise_min: {
if (BuiltinElementwiseMath(TheCall))
return ExprError();
+ Expr *Arg0 = TheCall->getArg(0);
+ Expr *Arg1 = TheCall->getArg(1);
+ QualType Ty0 = Arg0->getType();
+ QualType Ty1 = Arg1->getType();
+ const VectorType *VecTy0 = Ty0->getAs<VectorType>();
+ const VectorType *VecTy1 = Ty1->getAs<VectorType>();
+ if (Ty0->isFloatingType() || Ty1->isFloatingType() ||
+ (VecTy0 && VecTy0->getElementType()->isFloatingType()) ||
+ (VecTy1 && VecTy1->getElementType()->isFloatingType()))
+ Diag(TheCall->getBeginLoc(), diag::warn_deprecated_builtin)
+ << "__builtin_elementwise_min"
+ << "__builtin_elementwise_minnum/minimum/minimumnum";
break;
+ }
+ case Builtin::BI__builtin_elementwise_max: {
+ if (BuiltinElementwiseMath(TheCall))
+ return ExprError();
+ Expr *Arg0 = TheCall->getArg(0);
+ Expr *Arg1 = TheCall->getArg(1);
+ QualType Ty0 = Arg0->getType();
+ QualType Ty1 = Arg1->getType();
+ const VectorType *VecTy0 = Ty0->getAs<VectorType>();
+ const VectorType *VecTy1 = Ty1->getAs<VectorType>();
+ if (Ty0->isFloatingType() || Ty1->isFloatingType() ||
+ (VecTy0 && VecTy0->getElementType()->isFloatingType()) ||
+ (VecTy1 && VecTy1->getElementType()->isFloatingType()))
+ Diag(TheCall->getBeginLoc(), diag::warn_deprecated_builtin)
+ << "__builtin_elementwise_max"
+ << "__builtin_elementwise_maxnum/maximum/maximumnum";
+ break;
+ }
case Builtin::BI__builtin_elementwise_popcount:
case Builtin::BI__builtin_elementwise_bitreverse:
if (PrepareBuiltinElementwiseMathOneArgCall(
diff --git a/clang/test/Sema/builtins-elementwise-math.c b/clang/test/Sema/builtins-elementwise-math.c
index 47f78d658c922..d95149a112bd9 100644
--- a/clang/test/Sema/builtins-elementwise-math.c
+++ b/clang/test/Sema/builtins-elementwise-math.c
@@ -238,6 +238,14 @@ void test_builtin_elementwise_max(int i, short s, double d, float4 v, int3 iv, u
_Complex float c1, c2;
c1 = __builtin_elementwise_max(c1, c2);
// expected-error at -1 {{1st argument must be a vector, integer or floating-point type (was '_Complex float')}}
+
+ double dr;
+ dr = __builtin_elementwise_max(d, 0.0);
+ // expected-warning at -1 {{builtin __builtin_elementwise_max is deprecated; use __builtin_elementwise_maxnum/maximum/maximumnum instead}}
+
+ float4 vr;
+ vr = __builtin_elementwise_max(v, v);
+ // expected-warning at -1 {{builtin __builtin_elementwise_max is deprecated; use __builtin_elementwise_maxnum/maximum/maximumnum instead}}
}
void test_builtin_elementwise_min(int i, short s, double d, float4 v, int3 iv, unsigned3 uv, int *p) {
@@ -298,6 +306,14 @@ void test_builtin_elementwise_min(int i, short s, double d, float4 v, int3 iv, u
_Complex float c1, c2;
c1 = __builtin_elementwise_min(c1, c2);
// expected-error at -1 {{1st argument must be a vector, integer or floating-point type (was '_Complex float')}}
+
+ double dr;
+ dr = __builtin_elementwise_min(d, 0.0);
+ // expected-warning at -1 {{builtin __builtin_elementwise_min is deprecated; use __builtin_elementwise_minnum/minimum/minimumnum instead}}
+
+ float4 vr;
+ vr = __builtin_elementwise_min(v, v);
+ // expected-warning at -1 {{builtin __builtin_elementwise_min is deprecated; use __builtin_elementwise_minnum/minimum/minimumnum instead}}
}
void test_builtin_elementwise_maximum(int i, short s, float f, double d, float4 fv, double4 dv, int3 iv, unsigned3 uv, int *p) {
@@ -1379,6 +1395,7 @@ typedef struct {
float3 foo(float3 a,const struct_float3* hi) {
float3 b = __builtin_elementwise_max((float3)(0.0f), a);
+ // expected-warning at -1 {{builtin __builtin_elementwise_max is deprecated; use __builtin_elementwise_maxnum/maximum/maximumnum instead}}
return __builtin_elementwise_pow(b, hi->b.yyy);
}
>From 554e95b00c5950755d9d78a39fe5d6c1f8a66fa3 Mon Sep 17 00:00:00 2001
From: YunQiang Su <syq at debian.org>
Date: Thu, 26 Feb 2026 16:25:10 +0800
Subject: [PATCH 6/7] No suggestion for new choice
---
clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
clang/lib/Sema/SemaChecking.cpp | 10 ++++------
clang/test/Sema/builtins-elementwise-math.c | 10 +++++-----
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 68016ec4d58a3..690b4a60d7f64 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6297,6 +6297,8 @@ def warn_unavailable_def : Warning<
def warn_deprecated_builtin : Warning<
"builtin %0 is deprecated; use %1 instead">,
InGroup<DeprecatedBuiltins>;
+def warn_deprecated_builtin_no_suggestion : Warning<"builtin %0 is deprecated">,
+ InGroup<DeprecatedBuiltins>;
def err_unavailable : Error<"%0 is unavailable">;
def err_property_method_unavailable :
Error<"property access is using %0 method which is unavailable">;
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index c390d6be2625d..2df027923e571 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3570,9 +3570,8 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
if (Ty0->isFloatingType() || Ty1->isFloatingType() ||
(VecTy0 && VecTy0->getElementType()->isFloatingType()) ||
(VecTy1 && VecTy1->getElementType()->isFloatingType()))
- Diag(TheCall->getBeginLoc(), diag::warn_deprecated_builtin)
- << "__builtin_elementwise_min"
- << "__builtin_elementwise_minnum/minimum/minimumnum";
+ Diag(TheCall->getBeginLoc(), diag::warn_deprecated_builtin_no_suggestion)
+ << "__builtin_elementwise_min";
break;
}
case Builtin::BI__builtin_elementwise_max: {
@@ -3587,9 +3586,8 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
if (Ty0->isFloatingType() || Ty1->isFloatingType() ||
(VecTy0 && VecTy0->getElementType()->isFloatingType()) ||
(VecTy1 && VecTy1->getElementType()->isFloatingType()))
- Diag(TheCall->getBeginLoc(), diag::warn_deprecated_builtin)
- << "__builtin_elementwise_max"
- << "__builtin_elementwise_maxnum/maximum/maximumnum";
+ Diag(TheCall->getBeginLoc(), diag::warn_deprecated_builtin_no_suggestion)
+ << "__builtin_elementwise_max";
break;
}
case Builtin::BI__builtin_elementwise_popcount:
diff --git a/clang/test/Sema/builtins-elementwise-math.c b/clang/test/Sema/builtins-elementwise-math.c
index d95149a112bd9..3b96571d1abab 100644
--- a/clang/test/Sema/builtins-elementwise-math.c
+++ b/clang/test/Sema/builtins-elementwise-math.c
@@ -241,11 +241,11 @@ void test_builtin_elementwise_max(int i, short s, double d, float4 v, int3 iv, u
double dr;
dr = __builtin_elementwise_max(d, 0.0);
- // expected-warning at -1 {{builtin __builtin_elementwise_max is deprecated; use __builtin_elementwise_maxnum/maximum/maximumnum instead}}
+ // expected-warning at -1 {{builtin __builtin_elementwise_max is deprecated}}
float4 vr;
vr = __builtin_elementwise_max(v, v);
- // expected-warning at -1 {{builtin __builtin_elementwise_max is deprecated; use __builtin_elementwise_maxnum/maximum/maximumnum instead}}
+ // expected-warning at -1 {{builtin __builtin_elementwise_max is deprecated}}
}
void test_builtin_elementwise_min(int i, short s, double d, float4 v, int3 iv, unsigned3 uv, int *p) {
@@ -309,11 +309,11 @@ void test_builtin_elementwise_min(int i, short s, double d, float4 v, int3 iv, u
double dr;
dr = __builtin_elementwise_min(d, 0.0);
- // expected-warning at -1 {{builtin __builtin_elementwise_min is deprecated; use __builtin_elementwise_minnum/minimum/minimumnum instead}}
+ // expected-warning at -1 {{builtin __builtin_elementwise_min is deprecated}}
float4 vr;
vr = __builtin_elementwise_min(v, v);
- // expected-warning at -1 {{builtin __builtin_elementwise_min is deprecated; use __builtin_elementwise_minnum/minimum/minimumnum instead}}
+ // expected-warning at -1 {{builtin __builtin_elementwise_min is deprecated}}
}
void test_builtin_elementwise_maximum(int i, short s, float f, double d, float4 fv, double4 dv, int3 iv, unsigned3 uv, int *p) {
@@ -1395,7 +1395,7 @@ typedef struct {
float3 foo(float3 a,const struct_float3* hi) {
float3 b = __builtin_elementwise_max((float3)(0.0f), a);
- // expected-warning at -1 {{builtin __builtin_elementwise_max is deprecated; use __builtin_elementwise_maxnum/maximum/maximumnum instead}}
+ // expected-warning at -1 {{builtin __builtin_elementwise_max is deprecated}}
return __builtin_elementwise_pow(b, hi->b.yyy);
}
>From 230e97fab99d5f29c807176d23cb8c296db4638a Mon Sep 17 00:00:00 2001
From: YunQiang Su <syq at debian.org>
Date: Thu, 26 Feb 2026 18:38:02 +0800
Subject: [PATCH 7/7] Fix SemaCXX/builtins-elementwise-math.cpp
---
clang/test/SemaCXX/builtins-elementwise-math.cpp | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/clang/test/SemaCXX/builtins-elementwise-math.cpp b/clang/test/SemaCXX/builtins-elementwise-math.cpp
index 7482e5043aa35..112c7db361bb0 100644
--- a/clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ b/clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -12,8 +12,6 @@ struct false_type {
template <class T> struct is_const : false_type {};
template <class T> struct is_const<const T> : true_type {};
-// expected-no-diagnostics
-
void test_builtin_elementwise_abs() {
const int a = 2;
int b = 1;
@@ -64,16 +62,22 @@ void test_builtin_elementwise_max_fp() {
const float a = 2.0f;
float b = 1.0f;
static_assert(!is_const<decltype(__builtin_elementwise_max(a, b))>::value);
+ // expected-warning at -1 {{builtin __builtin_elementwise_max is deprecated}}
static_assert(!is_const<decltype(__builtin_elementwise_max(b, a))>::value);
+ // expected-warning at -1 {{builtin __builtin_elementwise_max is deprecated}}
static_assert(!is_const<decltype(__builtin_elementwise_max(a, a))>::value);
+ // expected-warning at -1 {{builtin __builtin_elementwise_max is deprecated}}
}
void test_builtin_elementwise_min_fp() {
const float a = 2.0f;
float b = 1.0f;
static_assert(!is_const<decltype(__builtin_elementwise_min(a, b))>::value);
+ // expected-warning at -1 {{builtin __builtin_elementwise_min is deprecated}}
static_assert(!is_const<decltype(__builtin_elementwise_min(b, a))>::value);
+ // expected-warning at -1 {{builtin __builtin_elementwise_min is deprecated}}
static_assert(!is_const<decltype(__builtin_elementwise_min(a, a))>::value);
+ // expected-warning at -1 {{builtin __builtin_elementwise_min is deprecated}}
}
void test_builtin_elementwise_maximum() {
More information about the cfe-commits
mailing list