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
14 changes: 13 additions & 1 deletion clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,18 @@ class CIRStoreOpLowering : public mlir::OpConversionPattern<cir::StoreOp> {
}
};

class CIRACosOpLowering : public mlir::OpConversionPattern<cir::ACosOp> {
public:
using OpConversionPattern<cir::ACosOp>::OpConversionPattern;

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

class CIRATanOpLowering : public mlir::OpConversionPattern<cir::ATanOp> {
public:
using OpConversionPattern<cir::ATanOp>::OpConversionPattern;
Expand Down Expand Up @@ -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());
}

Expand Down
30 changes: 30 additions & 0 deletions clang/test/CIR/Lowering/ThroughMLIR/acos.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() {
%0 = cir.const #cir.fp<1.0> : !cir.float
%1 = cir.const #cir.fp<3.0> : !cir.long_double<!cir.f80>
%2 = cir.const #cir.fp<2.0> : !cir.double
%3 = cir.const #cir.fp<4.00> : !cir.long_double<!cir.double>
%4 = cir.acos %0 : !cir.float
%5 = cir.acos %1 : !cir.long_double<!cir.f80>
%6 = cir.acos %2 : !cir.double
%7 = cir.acos %3 : !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 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: }
Loading