Skip to content
Open
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
24 changes: 23 additions & 1 deletion lib/Conversion/ArithToNeura/ArithToNeuraPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ struct ArithAddIToNeuraAdd : public OpRewritePattern<mlir::arith::AddIOp> {
}
};

struct ArithCmpFToNeuraFCmp : public OpRewritePattern<mlir::arith::CmpFOp> {
using OpRewritePattern::OpRewritePattern;

LogicalResult matchAndRewrite(arith::CmpFOp op,
PatternRewriter &rewriter) const override {

Value lhs = op.getLhs();
Value rhs = op.getRhs();

mlir::arith::CmpFPredicate predicate_enum = op.getPredicate();

StringRef predicate_str = arith::stringifyCmpFPredicate(predicate_enum);

StringAttr predicate_attr = rewriter.getStringAttr(predicate_str);
// Converts arith CmpFOp to Neura FCmpOp.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment also needs indent.

rewriter.replaceOpWithNewOp<neura::FCmpOp>(
op, op.getResult().getType(), lhs, rhs, predicate_attr);

return success();
}
};

struct ArithFAddToNeuraFAdd : public OpRewritePattern<mlir::arith::AddFOp> {
using OpRewritePattern::OpRewritePattern;

Expand Down Expand Up @@ -338,7 +360,7 @@ struct LowerArithToNeuraPass
mlir::neura::arith2neura::populateWithGenerated(patterns);
patterns.add<
ArithFAddToNeuraFAdd, ArithConstantToNeuraConstant,
ArithAddIToNeuraAdd, ArithCmpiToNeuraICmp, ArithSelectToNeuraSel,
ArithAddIToNeuraAdd, ArithCmpiToNeuraICmp, ArithCmpFToNeuraFCmp, ArithSelectToNeuraSel,
ArithExtUIToNeuraCast, ArithIndexCastToNeuraCast,
ArithFDivToNeuraFDiv, ArithExtfToNeuraCast, ArithMulFToNeuraFMul,
ArithSubIToNeuraSub, ArithSubFToNeuraFSub, ArithMulIToNeuraMul,
Expand Down
12 changes: 12 additions & 0 deletions test/arith2neura/cmpf.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module {
func.func @test_cmpf(%arg0: f32, %arg1: f32) -> i1 {
%0 = arith.cmpf ogt, %arg0, %arg1 : f32
return %0 : i1
}
}

// RUN: mlir-neura-opt --assign-accelerator --lower-arith-to-neura %s | FileCheck %s --check-prefix=OPT

// CHECK-LABEL: func.func @test_cmpf(
// OPT: %{{.*}} = "neura.fcmp"
// OPT: cmpType = "ogt"