Skip to content

[CIR][CIRGen] handle __builtin_elementwise_acos #1362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 19, 2025
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
5 changes: 3 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,8 +1356,9 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
mlir::Value result = call->getResult(0);
return RValue::get(result);
}
case Builtin::BI__builtin_elementwise_acos:
llvm_unreachable("BI__builtin_elementwise_acos NYI");
case Builtin::BI__builtin_elementwise_acos: {
return emitBuiltinWithOneOverloadedType<1>(E, "acos");
}
case Builtin::BI__builtin_elementwise_asin:
llvm_unreachable("BI__builtin_elementwise_asin NYI");
case Builtin::BI__builtin_elementwise_atan:
Expand Down
13 changes: 13 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,19 @@ class CIRGenFunction : public CIRGenTypeCache {
RValue emitBuiltinExpr(const clang::GlobalDecl GD, unsigned BuiltinID,
const clang::CallExpr *E, ReturnValueSlot ReturnValue);
RValue emitRotate(const CallExpr *E, bool IsRotateRight);
template <uint32_t N>
RValue emitBuiltinWithOneOverloadedType(const CallExpr *E,
llvm::StringRef Name) {
static_assert(N, "expect non-empty argument");
mlir::Type cirTy = convertType(E->getArg(0)->getType());
SmallVector<mlir::Value, N> args;
for (uint32_t i = 0; i < N; ++i) {
args.push_back(emitScalarExpr(E->getArg(i)));
}
const auto call = builder.create<cir::LLVMIntrinsicCallOp>(
getLoc(E->getExprLoc()), builder.getStringAttr(Name), cirTy, args);
return RValue::get(call->getResult(0));
}
mlir::Value emitTargetBuiltinExpr(unsigned BuiltinID,
const clang::CallExpr *E,
ReturnValueSlot ReturnValue);
Expand Down
21 changes: 21 additions & 0 deletions clang/test/CIR/CodeGen/builtins-elementwise.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,24 @@ void test_builtin_elementwise_abs(vint4 vi4, int i, float f, double d,
// LLVM: {{%.*}} = call <4 x double> @llvm.fabs.v4f64(<4 x double> {{%.*}})
vd4 = __builtin_elementwise_abs(vd4);
}

void test_builtin_elementwise_acos(float f, double d, vfloat4 vf4,
vdouble4 vd4) {
// CIR-LABEL: test_builtin_elementwise_acos
// LLVM-LABEL: test_builtin_elementwise_acos
// CIR: {{%.*}} = cir.llvm.intrinsic "acos" {{%.*}} : (!cir.float) -> !cir.float
// LLVM: {{%.*}} = call float @llvm.acos.f32(float {{%.*}})
f = __builtin_elementwise_acos(f);

// CIR: {{%.*}} = cir.llvm.intrinsic "acos" {{%.*}} : (!cir.double) -> !cir.double
// LLVM: {{%.*}} = call double @llvm.acos.f64(double {{%.*}})
d = __builtin_elementwise_acos(d);

// CIR: {{%.*}} = cir.llvm.intrinsic "acos" {{%.*}} : (!cir.vector<!cir.float x 4>) -> !cir.vector<!cir.float x 4>
// LLVM: {{%.*}} = call <4 x float> @llvm.acos.v4f32(<4 x float> {{%.*}})
vf4 = __builtin_elementwise_acos(vf4);

// CIR: {{%.*}} = cir.llvm.intrinsic "acos" {{%.*}} : (!cir.vector<!cir.double x 4>) -> !cir.vector<!cir.double x 4>
// LLVM: {{%.*}} = call <4 x double> @llvm.acos.v4f64(<4 x double> {{%.*}})
vd4 = __builtin_elementwise_acos(vd4);
}