Skip to content

Commit e5102e2

Browse files
authored
[CIR] Upstream FPToFPBuiltin ASinOp (#157350)
Upstream support for FPToFPBuiltin ASinOp
1 parent c82d09c commit e5102e2

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-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
@@ -3827,6 +3827,16 @@ def CIR_ACosOp : CIR_UnaryFPToFPBuiltinOp<"acos", "ACosOp"> {
38273827
}];
38283828
}
38293829

3830+
def CIR_ASinOp : CIR_UnaryFPToFPBuiltinOp<"asin", "ASinOp"> {
3831+
let summary = "Computes the arcus sine of the specified value";
3832+
let description = [{
3833+
`cir.asin`computes the arcus sine of a given value and
3834+
returns a result of the same type.
3835+
3836+
Floating-point exceptions are ignored, and it does not set `errno`.
3837+
}];
3838+
}
3839+
38303840
def CIR_FAbsOp : CIR_UnaryFPToFPBuiltinOp<"fabs", "FAbsOp"> {
38313841
let summary = "Computes the floating-point absolute value";
38323842
let description = [{

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

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

412412
case Builtin::BI__builtin_elementwise_acos:
413413
return emitUnaryFPBuiltin<cir::ACosOp>(*this, *e);
414+
case Builtin::BI__builtin_elementwise_asin:
415+
return emitUnaryFPBuiltin<cir::ASinOp>(*this, *e);
414416
}
415417

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

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,14 @@ 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, adaptor.getSrc());
606+
return mlir::success();
607+
}
608+
601609
mlir::LogicalResult CIRToLLVMAssumeOpLowering::matchAndRewrite(
602610
cir::AssumeOp op, OpAdaptor adaptor,
603611
mlir::ConversionPatternRewriter &rewriter) const {
@@ -2454,6 +2462,7 @@ void ConvertCIRToLLVMPass::runOnOperation() {
24542462
patterns.add<
24552463
// clang-format off
24562464
CIRToLLVMACosOpLowering,
2465+
CIRToLLVMASinOpLowering,
24572466
CIRToLLVMAssumeOpLowering,
24582467
CIRToLLVMAssumeAlignedOpLowering,
24592468
CIRToLLVMAssumeSepStorageOpLowering,

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

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

749+
class CIRToLLVMASinOpLowering : public mlir::OpConversionPattern<cir::ASinOp> {
750+
public:
751+
using mlir::OpConversionPattern<cir::ASinOp>::OpConversionPattern;
752+
753+
mlir::LogicalResult
754+
matchAndRewrite(cir::ASinOp op, OpAdaptor,
755+
mlir::ConversionPatternRewriter &) const override;
756+
};
757+
749758
class CIRToLLVMInlineAsmOpLowering
750759
: public mlir::OpConversionPattern<cir::InlineAsmOp> {
751760
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)