[clang] b2ed9f3 - [Clang] Implement the rest of __builtin_elementwise_* functions.
Florian Hahn via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 7 07:11:56 PST 2022
Author: Jun Zhang
Date: 2022-01-07T15:11:36Z
New Revision: b2ed9f3f44d084bf2aae0af1b84f76a68a7c477b
URL: https://github.com/llvm/llvm-project/commit/b2ed9f3f44d084bf2aae0af1b84f76a68a7c477b
DIFF: https://github.com/llvm/llvm-project/commit/b2ed9f3f44d084bf2aae0af1b84f76a68a7c477b.diff
LOG: [Clang] Implement the rest of __builtin_elementwise_* functions.
The patch implement the rest of __builtin_elementwise_* functions
specified in D111529, including:
* __builtin_elementwise_floor
* __builtin_elementwise_roundeven
* __builtin_elementwise_trunc
Signed-off-by: Jun <jun at junz.org>
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D115429
Added:
Modified:
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtins-elementwise-math.c
clang/test/Sema/builtins-elementwise-math.c
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def
index 45d4451637495..f73efdde3e2b1 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -647,6 +647,9 @@ BUILTIN(__builtin_elementwise_abs, "v.", "nct")
BUILTIN(__builtin_elementwise_max, "v.", "nct")
BUILTIN(__builtin_elementwise_min, "v.", "nct")
BUILTIN(__builtin_elementwise_ceil, "v.", "nct")
+BUILTIN(__builtin_elementwise_floor, "v.", "nct")
+BUILTIN(__builtin_elementwise_roundeven, "v.", "nct")
+BUILTIN(__builtin_elementwise_trunc, "v.", "nct")
BUILTIN(__builtin_reduce_max, "v.", "nct")
BUILTIN(__builtin_reduce_min, "v.", "nct")
BUILTIN(__builtin_reduce_xor, "v.", "nct")
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 50f59a2abab85..e98c9d5fd8444 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3143,6 +3143,15 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
case Builtin::BI__builtin_elementwise_ceil:
return RValue::get(
emitUnaryBuiltin(*this, E, llvm::Intrinsic::ceil, "elt.ceil"));
+ case Builtin::BI__builtin_elementwise_floor:
+ return RValue::get(
+ emitUnaryBuiltin(*this, E, llvm::Intrinsic::floor, "elt.floor"));
+ case Builtin::BI__builtin_elementwise_roundeven:
+ return RValue::get(emitUnaryBuiltin(*this, E, llvm::Intrinsic::roundeven,
+ "elt.roundeven"));
+ case Builtin::BI__builtin_elementwise_trunc:
+ return RValue::get(
+ emitUnaryBuiltin(*this, E, llvm::Intrinsic::trunc, "elt.trunc"));
case Builtin::BI__builtin_elementwise_max: {
Value *Op0 = EmitScalarExpr(E->getArg(0));
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 03608a339e55e..908cb78fbb0a7 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2189,9 +2189,12 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
break;
}
- // __builtin_elementwise_ceil restricts the element type to floating point
+ // These builtins restrict the element type to floating point
// types only.
- case Builtin::BI__builtin_elementwise_ceil: {
+ case Builtin::BI__builtin_elementwise_ceil:
+ case Builtin::BI__builtin_elementwise_floor:
+ case Builtin::BI__builtin_elementwise_roundeven:
+ case Builtin::BI__builtin_elementwise_trunc: {
if (PrepareBuiltinElementwiseMathOneArgCall(TheCall))
return ExprError();
diff --git a/clang/test/CodeGen/builtins-elementwise-math.c b/clang/test/CodeGen/builtins-elementwise-math.c
index c0c948ffea78b..a4785b8f28f22 100644
--- a/clang/test/CodeGen/builtins-elementwise-math.c
+++ b/clang/test/CodeGen/builtins-elementwise-math.c
@@ -205,3 +205,51 @@ void test_builtin_elementwise_ceil(float f1, float f2, double d1, double d2,
// CHECK-NEXT: call <4 x float> @llvm.ceil.v4f32(<4 x float> [[VF1]])
vf2 = __builtin_elementwise_ceil(vf1);
}
+
+void test_builtin_elementwise_floor(float f1, float f2, double d1, double d2,
+ float4 vf1, float4 vf2) {
+ // CHECK-LABEL: define void @test_builtin_elementwise_floor(
+ // CHECK: [[F1:%.+]] = load float, float* %f1.addr, align 4
+ // CHECK-NEXT: call float @llvm.floor.f32(float [[F1]])
+ f2 = __builtin_elementwise_floor(f1);
+
+ // CHECK: [[D1:%.+]] = load double, double* %d1.addr, align 8
+ // CHECK-NEXT: call double @llvm.floor.f64(double [[D1]])
+ d2 = __builtin_elementwise_floor(d1);
+
+ // CHECK: [[VF1:%.+]] = load <4 x float>, <4 x float>* %vf1.addr, align 16
+ // CHECK-NEXT: call <4 x float> @llvm.floor.v4f32(<4 x float> [[VF1]])
+ vf2 = __builtin_elementwise_floor(vf1);
+}
+
+void test_builtin_elementwise_roundeven(float f1, float f2, double d1, double d2,
+ float4 vf1, float4 vf2) {
+ // CHECK-LABEL: define void @test_builtin_elementwise_roundeven(
+ // CHECK: [[F1:%.+]] = load float, float* %f1.addr, align 4
+ // CHECK-NEXT: call float @llvm.roundeven.f32(float [[F1]])
+ f2 = __builtin_elementwise_roundeven(f1);
+
+ // CHECK: [[D1:%.+]] = load double, double* %d1.addr, align 8
+ // CHECK-NEXT: call double @llvm.roundeven.f64(double [[D1]])
+ d2 = __builtin_elementwise_roundeven(d1);
+
+ // CHECK: [[VF1:%.+]] = load <4 x float>, <4 x float>* %vf1.addr, align 16
+ // CHECK-NEXT: call <4 x float> @llvm.roundeven.v4f32(<4 x float> [[VF1]])
+ vf2 = __builtin_elementwise_roundeven(vf1);
+}
+
+void test_builtin_elementwise_trunc(float f1, float f2, double d1, double d2,
+ float4 vf1, float4 vf2) {
+ // CHECK-LABEL: define void @test_builtin_elementwise_trunc(
+ // CHECK: [[F1:%.+]] = load float, float* %f1.addr, align 4
+ // CHECK-NEXT: call float @llvm.trunc.f32(float [[F1]])
+ f2 = __builtin_elementwise_trunc(f1);
+
+ // CHECK: [[D1:%.+]] = load double, double* %d1.addr, align 8
+ // CHECK-NEXT: call double @llvm.trunc.f64(double [[D1]])
+ d2 = __builtin_elementwise_trunc(d1);
+
+ // CHECK: [[VF1:%.+]] = load <4 x float>, <4 x float>* %vf1.addr, align 16
+ // CHECK-NEXT: call <4 x float> @llvm.trunc.v4f32(<4 x float> [[VF1]])
+ vf2 = __builtin_elementwise_trunc(vf1);
+}
diff --git a/clang/test/Sema/builtins-elementwise-math.c b/clang/test/Sema/builtins-elementwise-math.c
index 41228c69a8b4f..4243ddd1d71d7 100644
--- a/clang/test/Sema/builtins-elementwise-math.c
+++ b/clang/test/Sema/builtins-elementwise-math.c
@@ -156,3 +156,66 @@ void test_builtin_elementwise_ceil(int i, float f, double d, float4 v, int3 iv,
uv = __builtin_elementwise_ceil(uv);
// expected-error at -1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
}
+
+void test_builtin_elementwise_floor(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+ struct Foo s = __builtin_elementwise_floor(f);
+ // expected-error at -1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+ i = __builtin_elementwise_floor();
+ // expected-error at -1 {{too few arguments to function call, expected 1, have 0}}
+
+ i = __builtin_elementwise_floor(i);
+ // expected-error at -1 {{1st argument must be a floating point type (was 'int')}}
+
+ i = __builtin_elementwise_floor(f, f);
+ // expected-error at -1 {{too many arguments to function call, expected 1, have 2}}
+
+ u = __builtin_elementwise_floor(u);
+ // expected-error at -1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+ uv = __builtin_elementwise_floor(uv);
+ // expected-error at -1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
+
+void test_builtin_elementwise_roundeven(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+ struct Foo s = __builtin_elementwise_roundeven(f);
+ // expected-error at -1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+ i = __builtin_elementwise_roundeven();
+ // expected-error at -1 {{too few arguments to function call, expected 1, have 0}}
+
+ i = __builtin_elementwise_roundeven(i);
+ // expected-error at -1 {{1st argument must be a floating point type (was 'int')}}
+
+ i = __builtin_elementwise_roundeven(f, f);
+ // expected-error at -1 {{too many arguments to function call, expected 1, have 2}}
+
+ u = __builtin_elementwise_roundeven(u);
+ // expected-error at -1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+ uv = __builtin_elementwise_roundeven(uv);
+ // expected-error at -1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
+
+void test_builtin_elementwise_trunc(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+ struct Foo s = __builtin_elementwise_trunc(f);
+ // expected-error at -1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+ i = __builtin_elementwise_trunc();
+ // expected-error at -1 {{too few arguments to function call, expected 1, have 0}}
+
+ i = __builtin_elementwise_trunc(i);
+ // expected-error at -1 {{1st argument must be a floating point type (was 'int')}}
+
+ i = __builtin_elementwise_trunc(f, f);
+ // expected-error at -1 {{too many arguments to function call, expected 1, have 2}}
+
+ u = __builtin_elementwise_trunc(u);
+ // expected-error at -1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+ uv = __builtin_elementwise_trunc(uv);
+ // expected-error at -1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
More information about the cfe-commits
mailing list