diff --git a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp index fd1531f8eee4..ed5fae18e707 100644 --- a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp +++ b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp @@ -311,6 +311,18 @@ class CIRCosOpLowering : public mlir::OpConversionPattern { } }; +class CIRTanOpLowering : public mlir::OpConversionPattern { +public: + using OpConversionPattern::OpConversionPattern; + + mlir::LogicalResult + matchAndRewrite(cir::TanOp op, OpAdaptor adaptor, + mlir::ConversionPatternRewriter &rewriter) const override { + rewriter.replaceOpWithNewOp(op, adaptor.getSrc()); + return mlir::LogicalResult::success(); + } +}; + class CIRSqrtOpLowering : public mlir::OpConversionPattern { public: using mlir::OpConversionPattern::OpConversionPattern; @@ -1418,8 +1430,8 @@ void populateCIRToMLIRConversionPatterns(mlir::RewritePatternSet &patterns, CIRBitClrsbOpLowering, CIRBitFfsOpLowering, CIRBitParityOpLowering, CIRIfOpLowering, CIRVectorCreateLowering, CIRVectorInsertLowering, CIRVectorExtractLowering, CIRVectorCmpOpLowering, CIRACosOpLowering, - CIRASinOpLowering, CIRUnreachableOpLowering>(converter, - patterns.getContext()); + CIRASinOpLowering, CIRUnreachableOpLowering, CIRTanOpLowering>( + converter, patterns.getContext()); } static mlir::TypeConverter prepareTypeConverter() { diff --git a/clang/test/CIR/Lowering/ThroughMLIR/tan.cir b/clang/test/CIR/Lowering/ThroughMLIR/tan.cir new file mode 100644 index 000000000000..be8e0ccb8168 --- /dev/null +++ b/clang/test/CIR/Lowering/ThroughMLIR/tan.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() { + %1 = cir.const #cir.fp<1.0> : !cir.float + %2 = cir.const #cir.fp<2.0> : !cir.double + %3 = cir.const #cir.fp<3.0> : !cir.long_double + %4 = cir.const #cir.fp<4.0> : !cir.long_double + %5 = cir.tan %1 : !cir.float + %6 = cir.tan %2 : !cir.double + %7 = cir.tan %3 : !cir.long_double + %8 = cir.tan %4 : !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 2.000000e+00 : f64 +// CHECK-NEXT: %[[C2:.+]] = arith.constant 3.000000e+00 : f80 +// CHECK-NEXT: %[[C3:.+]] = arith.constant 4.000000e+00 : f64 +// CHECK-NEXT: %{{.+}} = math.tan %[[C0]] : f32 +// CHECK-NEXT: %{{.+}} = math.tan %[[C1]] : f64 +// CHECK-NEXT: %{{.+}} = math.tan %[[C2]] : f80 +// CHECK-NEXT: %{{.+}} = math.tan %[[C3]] : f64 +// CHECK-NEXT: return +// CHECK-NEXT: } +// CHECK-NEXT: }