Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,18 @@ class CIRCosOpLowering : public mlir::OpConversionPattern<cir::CosOp> {
}
};

class CIRTanOpLowering : public mlir::OpConversionPattern<cir::TanOp> {
public:
using OpConversionPattern<cir::TanOp>::OpConversionPattern;

mlir::LogicalResult
matchAndRewrite(cir::TanOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const override {
rewriter.replaceOpWithNewOp<mlir::math::TanOp>(op, adaptor.getSrc());
return mlir::LogicalResult::success();
}
};

class CIRSqrtOpLowering : public mlir::OpConversionPattern<cir::SqrtOp> {
public:
using mlir::OpConversionPattern<cir::SqrtOp>::OpConversionPattern;
Expand Down Expand Up @@ -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() {
Expand Down
30 changes: 30 additions & 0 deletions clang/test/CIR/Lowering/ThroughMLIR/tan.cir
Original file line number Diff line number Diff line change
@@ -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<!cir.f80>
%4 = cir.const #cir.fp<4.0> : !cir.long_double<!cir.double>
%5 = cir.tan %1 : !cir.float
%6 = cir.tan %2 : !cir.double
%7 = cir.tan %3 : !cir.long_double<!cir.f80>
%8 = cir.tan %4 : !cir.long_double<!cir.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: }
Loading