Skip to content

Commit a442924

Browse files
ayokunle321lanza
authored andcommitted
[CIR][CodeGen] Replace LLVMIntrinsicCallOp with ACosOp in __builtin_elementwise_acos (#1507)
Closes: #1374 Replaces LLVMIntrinsicCallOp with ACosOp in __builtin_elementwise_acos.
1 parent 6b19f09 commit a442924

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4738,6 +4738,7 @@ class UnaryFPToFPBuiltinOp<string mnemonic, string llvmOpName>
47384738
}
47394739

47404740
def CeilOp : UnaryFPToFPBuiltinOp<"ceil", "FCeilOp">;
4741+
def ACosOp : UnaryFPToFPBuiltinOp<"acos", "ACosOp">;
47414742
def CosOp : UnaryFPToFPBuiltinOp<"cos", "CosOp">;
47424743
def ExpOp : UnaryFPToFPBuiltinOp<"exp", "ExpOp">;
47434744
def Exp2Op : UnaryFPToFPBuiltinOp<"exp2", "Exp2Op">;

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
14011401
return RValue::get(result);
14021402
}
14031403
case Builtin::BI__builtin_elementwise_acos: {
1404-
return emitBuiltinWithOneOverloadedType<1>(E, "acos");
1404+
return emitUnaryFPBuiltin<cir::ACosOp>(*this, *E);
14051405
}
14061406
case Builtin::BI__builtin_elementwise_asin:
14071407
llvm_unreachable("BI__builtin_elementwise_asin NYI");

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,8 +1451,8 @@ class CIRGenFunction : public CIRGenTypeCache {
14511451
const clang::CallExpr *E, ReturnValueSlot ReturnValue);
14521452
RValue emitRotate(const CallExpr *E, bool IsRotateRight);
14531453
template <uint32_t N>
1454-
RValue emitBuiltinWithOneOverloadedType(const CallExpr *E,
1455-
llvm::StringRef Name) {
1454+
[[maybe_unused]] RValue
1455+
emitBuiltinWithOneOverloadedType(const CallExpr *E, llvm::StringRef Name) {
14561456
static_assert(N, "expect non-empty argument");
14571457
mlir::Type cirTy = convertType(E->getArg(0)->getType());
14581458
SmallVector<mlir::Value, N> args;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ void test_builtin_elementwise_acos(float f, double d, vfloat4 vf4,
4141
vdouble4 vd4) {
4242
// CIR-LABEL: test_builtin_elementwise_acos
4343
// LLVM-LABEL: test_builtin_elementwise_acos
44-
// CIR: {{%.*}} = cir.llvm.intrinsic "acos" {{%.*}} : (!cir.float) -> !cir.float
44+
// CIR: {{%.*}} = cir.acos {{%.*}} : !cir.float
4545
// LLVM: {{%.*}} = call float @llvm.acos.f32(float {{%.*}})
4646
f = __builtin_elementwise_acos(f);
4747

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

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

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

0 commit comments

Comments
 (0)