Skip to content

Commit 8b6e586

Browse files
ghehglanza
authored andcommitted
[CIR][CIRGen][Builtin] Support __builtin_elementwise_abs with vector of floating type (#1174)
[PR1132](#1132) implements missing feature `fpUnaryOPsSupportVectorType`, so revisit this code. One another thing changed is that I stopped using `cir::isAnyFloatingPointType` as it contains types like long double and FP80 which are not supported by the [builtin's signature](https://clang.llvm.org/docs/LanguageExtensions.html#vector-builtins)
1 parent 53d7913 commit 8b6e586

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,6 @@ struct MissingFeatures {
330330

331331
//-- Other missing features
332332

333-
// We need to extend fpUnaryOPs to support vector types.
334-
static bool fpUnaryOPsSupportVectorType() { return false; }
335-
336333
// We need to track the parent record types that represent a field
337334
// declaration. This is necessary to determine the layout of a class.
338335
static bool fieldDeclAbstraction() { return false; }

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,10 +1309,12 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
13091309
mlir::Type cirTy = ConvertType(E->getArg(0)->getType());
13101310
bool isIntTy = cir::isIntOrIntVectorTy(cirTy);
13111311
if (!isIntTy) {
1312-
if (cir::isAnyFloatingPointType(cirTy)) {
1312+
mlir::Type eltTy = cirTy;
1313+
if (mlir::isa<cir::VectorType>(cirTy))
1314+
eltTy = mlir::cast<cir::VectorType>(cirTy).getEltType();
1315+
if (mlir::isa<cir::SingleType, cir::DoubleType>(eltTy)) {
13131316
return emitUnaryFPBuiltin<cir::FAbsOp>(*this, *E);
13141317
}
1315-
assert(!MissingFeatures::fpUnaryOPsSupportVectorType());
13161318
llvm_unreachable("unsupported type for BI__builtin_elementwise_abs");
13171319
}
13181320
mlir::Value arg = emitScalarExpr(E->getArg(0));

clang/test/CIR/CodeGen/builtins-elementwise.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
// XFAIL: *
77

88
typedef int vint4 __attribute__((ext_vector_type(4)));
9+
typedef float vfloat4 __attribute__((ext_vector_type(4)));
10+
typedef double vdouble4 __attribute__((ext_vector_type(4)));
911

10-
void test_builtin_elementwise_abs(vint4 vi4, int i, float f, double d) {
12+
void test_builtin_elementwise_abs(vint4 vi4, int i, float f, double d,
13+
vfloat4 vf4, vdouble4 vd4) {
1114
// CIR-LABEL: test_builtin_elementwise_abs
1215
// LLVM-LABEL: test_builtin_elementwise_abs
1316
// CIR: {{%.*}} = cir.fabs {{%.*}} : !cir.float
@@ -25,4 +28,12 @@ void test_builtin_elementwise_abs(vint4 vi4, int i, float f, double d) {
2528
// CIR: {{%.*}} = cir.abs {{%.*}} : !s32
2629
// LLVM: {{%.*}} = call i32 @llvm.abs.i32(i32 {{%.*}}, i1 false)
2730
i = __builtin_elementwise_abs(i);
31+
32+
// CIR: {{%.*}} = cir.fabs {{%.*}} : !cir.vector<!cir.float x 4>
33+
// LLVM: {{%.*}} = call <4 x float> @llvm.fabs.v4f32(<4 x float> {{%.*}})
34+
vf4 = __builtin_elementwise_abs(vf4);
35+
36+
// CIR: {{%.*}} = cir.fabs {{%.*}} : !cir.vector<!cir.double x 4>
37+
// LLVM: {{%.*}} = call <4 x double> @llvm.fabs.v4f64(<4 x double> {{%.*}})
38+
vd4 = __builtin_elementwise_abs(vd4);
2839
}

0 commit comments

Comments
 (0)