Skip to content

Commit 764cd36

Browse files
committed
[CIR] Upstream FPToFPBuiltin ASinOp
1 parent e41da79 commit 764cd36

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3808,6 +3808,16 @@ def CIR_ACosOp : CIR_UnaryFPToFPBuiltinOp<"acos", "ACosOp"> {
38083808
}];
38093809
}
38103810

3811+
def CIR_ASinOp : CIR_UnaryFPToFPBuiltinOp<"asin", "ASinOp"> {
3812+
let summary = "Computes the arcus sine of the specified value";
3813+
let description = [{
3814+
`cir.asin`computes the arcus sine of a given value and
3815+
returns a result of the same type.
3816+
3817+
Floating-point exceptions are ignored, and it does not set `errno`.
3818+
}];
3819+
}
3820+
38113821
def CIR_FAbsOp : CIR_UnaryFPToFPBuiltinOp<"fabs", "FAbsOp"> {
38123822
let summary = "Computes the floating-point absolute value";
38133823
let description = [{

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
360360

361361
case Builtin::BI__builtin_elementwise_acos:
362362
return emitUnaryFPBuiltin<cir::ACosOp>(*this, *e);
363+
case Builtin::BI__builtin_elementwise_asin:
364+
return emitUnaryFPBuiltin<cir::ASinOp>(*this, *e);
363365
}
364366

365367
// If this is an alias for a lib function (e.g. __builtin_sin), emit

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,15 @@ mlir::LogicalResult CIRToLLVMACosOpLowering::matchAndRewrite(
598598
return mlir::success();
599599
}
600600

601+
mlir::LogicalResult CIRToLLVMASinOpLowering::matchAndRewrite(
602+
cir::ASinOp op, OpAdaptor adaptor,
603+
mlir::ConversionPatternRewriter &rewriter) const {
604+
mlir::Type resTy = typeConverter->convertType(op.getType());
605+
rewriter.replaceOpWithNewOp<mlir::LLVM::ASinOp>(op, resTy,
606+
adaptor.getOperands()[0]);
607+
return mlir::success();
608+
}
609+
601610
mlir::LogicalResult CIRToLLVMAssumeOpLowering::matchAndRewrite(
602611
cir::AssumeOp op, OpAdaptor adaptor,
603612
mlir::ConversionPatternRewriter &rewriter) const {
@@ -2427,6 +2436,7 @@ void ConvertCIRToLLVMPass::runOnOperation() {
24272436
patterns.add<
24282437
// clang-format off
24292438
CIRToLLVMACosOpLowering,
2439+
CIRToLLVMASinOpLowering,
24302440
CIRToLLVMAssumeOpLowering,
24312441
CIRToLLVMAssumeAlignedOpLowering,
24322442
CIRToLLVMAssumeSepStorageOpLowering,

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,15 @@ class CIRToLLVMACosOpLowering : public mlir::OpConversionPattern<cir::ACosOp> {
736736
mlir::ConversionPatternRewriter &) const override;
737737
};
738738

739+
class CIRToLLVMASinOpLowering : public mlir::OpConversionPattern<cir::ASinOp> {
740+
public:
741+
using mlir::OpConversionPattern<cir::ASinOp>::OpConversionPattern;
742+
743+
mlir::LogicalResult
744+
matchAndRewrite(cir::ASinOp op, OpAdaptor,
745+
mlir::ConversionPatternRewriter &) const override;
746+
};
747+
739748
class CIRToLLVMInlineAsmOpLowering
740749
: public mlir::OpConversionPattern<cir::InlineAsmOp> {
741750
mlir::DataLayout const &dataLayout;

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,29 @@ void test_builtin_elementwise_acos(float f, double d, vfloat4 vf4,
3636
vd4 = __builtin_elementwise_acos(vd4);
3737
}
3838

39+
void test_builtin_elementwise_asin(float f, double d, vfloat4 vf4,
40+
vdouble4 vd4) {
41+
// CIR-LABEL: test_builtin_elementwise_asin
42+
// LLVM-LABEL: test_builtin_elementwise_asin
43+
// OGCG-LABEL: test_builtin_elementwise_asin
44+
45+
// CIR: %{{.*}} = cir.asin %{{.*}} : !cir.float
46+
// LLVM: %{{.*}} = call float @llvm.asin.f32(float %{{.*}})
47+
// OGCG: %{{.*}} = call float @llvm.asin.f32(float %{{.*}})
48+
f = __builtin_elementwise_asin(f);
49+
50+
// CIR: %{{.*}} = cir.asin %{{.*}} : !cir.double
51+
// LLVM: %{{.*}} = call double @llvm.asin.f64(double %{{.*}})
52+
// OGCG: %{{.*}} = call double @llvm.asin.f64(double %{{.*}})
53+
d = __builtin_elementwise_asin(d);
54+
55+
// CIR: %{{.*}} = cir.asin %{{.*}} : !cir.vector<4 x !cir.float>
56+
// LLVM: %{{.*}} = call <4 x float> @llvm.asin.v4f32(<4 x float> %{{.*}})
57+
// OGCG: %{{.*}} = call <4 x float> @llvm.asin.v4f32(<4 x float> %{{.*}})
58+
vf4 = __builtin_elementwise_asin(vf4);
59+
60+
// CIR: %{{.*}} = cir.asin %{{.*}} : !cir.vector<4 x !cir.double>
61+
// LLVM: %{{.*}} = call <4 x double> @llvm.asin.v4f64(<4 x double> %{{.*}})
62+
// OGCG: %{{.*}} = call <4 x double> @llvm.asin.v4f64(<4 x double> %{{.*}})
63+
vd4 = __builtin_elementwise_asin(vd4);
64+
}

0 commit comments

Comments
 (0)