Skip to content
1 change: 1 addition & 0 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -4738,6 +4738,7 @@ class UnaryFPToFPBuiltinOp<string mnemonic, string llvmOpName>
}

def CeilOp : UnaryFPToFPBuiltinOp<"ceil", "FCeilOp">;
def ACosOp : UnaryFPToFPBuiltinOp<"acos", "ACosOp">;
def CosOp : UnaryFPToFPBuiltinOp<"cos", "CosOp">;
def ExpOp : UnaryFPToFPBuiltinOp<"exp", "ExpOp">;
def Exp2Op : UnaryFPToFPBuiltinOp<"exp2", "Exp2Op">;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
return RValue::get(result);
}
case Builtin::BI__builtin_elementwise_acos: {
return emitBuiltinWithOneOverloadedType<1>(E, "acos");
return emitUnaryFPBuiltin<cir::ACosOp>(*this, *E);
}
case Builtin::BI__builtin_elementwise_asin:
llvm_unreachable("BI__builtin_elementwise_asin NYI");
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1451,8 +1451,8 @@ class CIRGenFunction : public CIRGenTypeCache {
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) {
[[maybe_unused]] 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;
Expand Down
8 changes: 4 additions & 4 deletions clang/test/CIR/CodeGen/builtins-elementwise.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ 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
// CIR: {{%.*}} = cir.acos {{%.*}} : !cir.float
// LLVM: {{%.*}} = call float @llvm.acos.f32(float {{%.*}})
f = __builtin_elementwise_acos(f);

// CIR: {{%.*}} = cir.llvm.intrinsic "acos" {{%.*}} : (!cir.double) -> !cir.double
// CIR: {{%.*}} = cir.acos {{%.*}} : !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>
// CIR: {{%.*}} = cir.acos {{%.*}} : !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>
// CIR: {{%.*}} = cir.acos {{%.*}} : !cir.vector<!cir.double x 4>
// LLVM: {{%.*}} = call <4 x double> @llvm.acos.v4f64(<4 x double> {{%.*}})
vd4 = __builtin_elementwise_acos(vd4);
}
Expand Down
Loading