Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions clang/docs/LanguageExtensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -839,13 +839,13 @@ 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
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 and floating point types
For floating point types, follows semantics of minNum
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.
Expand Down
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ Non-comprehensive list of changes in this release
extends bit-reversal support to all standard integers type, including
``_BitInt``

- Deprecated float types support from ``__builtin_elementwise_max`` and
``__builtin_elementwise_min``.

New Compiler Flags
------------------
- New option ``-fms-anonymous-structs`` / ``-fno-ms-anonymous-structs`` added
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -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">;
Expand Down
14 changes: 13 additions & 1 deletion clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3559,10 +3559,22 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
return ExprError();
break;
case Builtin::BI__builtin_elementwise_min:
case Builtin::BI__builtin_elementwise_max:
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_no_suggestion)
<< Context.BuiltinInfo.getQuotedName(BuiltinID);
break;
}
case Builtin::BI__builtin_elementwise_popcount:
case Builtin::BI__builtin_elementwise_bitreverse:
if (PrepareBuiltinElementwiseMathOneArgCall(
Expand Down
17 changes: 17 additions & 0 deletions clang/test/Sema/builtins-elementwise-math.c
Original file line number Diff line number Diff line change
Expand Up @@ -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@-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@-1 {{builtin '__builtin_elementwise_max' is deprecated}}

float4 vr;
vr = __builtin_elementwise_max(v, v);
// expected-warning@-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) {
Expand Down Expand Up @@ -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@-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@-1 {{builtin '__builtin_elementwise_min' is deprecated}}

float4 vr;
vr = __builtin_elementwise_min(v, v);
// expected-warning@-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) {
Expand Down Expand Up @@ -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@-1 {{builtin '__builtin_elementwise_max' is deprecated}}
return __builtin_elementwise_pow(b, hi->b.yyy);
}

Expand Down
8 changes: 6 additions & 2 deletions clang/test/SemaCXX/builtins-elementwise-math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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@-1 {{builtin '__builtin_elementwise_max' is deprecated}}
static_assert(!is_const<decltype(__builtin_elementwise_max(b, a))>::value);
// expected-warning@-1 {{builtin '__builtin_elementwise_max' is deprecated}}
static_assert(!is_const<decltype(__builtin_elementwise_max(a, a))>::value);
// expected-warning@-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@-1 {{builtin '__builtin_elementwise_min' is deprecated}}
static_assert(!is_const<decltype(__builtin_elementwise_min(b, a))>::value);
// expected-warning@-1 {{builtin '__builtin_elementwise_min' is deprecated}}
static_assert(!is_const<decltype(__builtin_elementwise_min(a, a))>::value);
// expected-warning@-1 {{builtin '__builtin_elementwise_min' is deprecated}}
}

void test_builtin_elementwise_maximum() {
Expand Down
2 changes: 1 addition & 1 deletion libclc/clc/lib/generic/math/clc_fdim.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}