diff --git a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp index c60901426521..b88b7a320ff6 100644 --- a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp +++ b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp @@ -279,6 +279,18 @@ class CIRStoreOpLowering : public mlir::OpConversionPattern { } }; +class CIRACosOpLowering : public mlir::OpConversionPattern { +public: + using OpConversionPattern::OpConversionPattern; + + mlir::LogicalResult + matchAndRewrite(cir::ACosOp op, OpAdaptor adaptor, + mlir::ConversionPatternRewriter &rewriter) const override { + rewriter.replaceOpWithNewOp(op, adaptor.getSrc()); + return mlir::LogicalResult::success(); + } +}; + class CIRATanOpLowering : public mlir::OpConversionPattern { public: using OpConversionPattern::OpConversionPattern; @@ -1383,7 +1395,7 @@ void populateCIRToMLIRConversionPatterns(mlir::RewritePatternSet &patterns, CIRBitClzOpLowering, CIRBitCtzOpLowering, CIRBitPopcountOpLowering, CIRBitClrsbOpLowering, CIRBitFfsOpLowering, CIRBitParityOpLowering, CIRIfOpLowering, CIRVectorCreateLowering, CIRVectorInsertLowering, - CIRVectorExtractLowering, CIRVectorCmpOpLowering>( + CIRVectorExtractLowering, CIRVectorCmpOpLowering, CIRACosOpLowering>( converter, patterns.getContext()); } diff --git a/clang/test/CIR/Lowering/ThroughMLIR/acos.cir b/clang/test/CIR/Lowering/ThroughMLIR/acos.cir new file mode 100644 index 000000000000..f885c7adea7d --- /dev/null +++ b/clang/test/CIR/Lowering/ThroughMLIR/acos.cir @@ -0,0 +1,30 @@ +// RUN: cir-opt %s -cir-to-mlir -o %t.mlir +// RUN: FileCheck %s --input-file %t.mlir + +module { + cir.func @foo() { + %0 = cir.const #cir.fp<1.0> : !cir.float + %1 = cir.const #cir.fp<3.0> : !cir.long_double + %2 = cir.const #cir.fp<2.0> : !cir.double + %3 = cir.const #cir.fp<4.00> : !cir.long_double + %4 = cir.acos %0 : !cir.float + %5 = cir.acos %1 : !cir.long_double + %6 = cir.acos %2 : !cir.double + %7 = cir.acos %3 : !cir.long_double + cir.return + } +} + +// CHECK: module { +// CHECK-NEXT: func.func @foo() { +// CHECK-NEXT: %[[C0:.+]] = arith.constant 1.000000e+00 : f32 +// CHECK-NEXT: %[[C1:.+]] = arith.constant 3.000000e+00 : f80 +// CHECK-NEXT: %[[C2:.+]] = arith.constant 2.000000e+00 : f64 +// CHECK-NEXT: %[[C3:.+]] = arith.constant 4.000000e+00 : f64 +// CHECK-NEXT: %{{.+}} = math.acos %[[C0]] : f32 +// CHECK-NEXT: %{{.+}} = math.acos %[[C1]] : f80 +// CHECK-NEXT: %{{.+}} = math.acos %[[C2]] : f64 +// CHECK-NEXT: %{{.+}} = math.acos %[[C3]] : f64 +// CHECK-NEXT: return +// CHECK-NEXT: } +// CHECK-NEXT: }