Skip to content

Commit

Permalink
Add missing cmpf predicate conversion (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaAMD authored May 29, 2024
1 parent e452afa commit 9db9dd7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class CmpFOpConversion : public OpConversionPattern<arith::CmpFOp> {
unordered = false;
predicate = emitc::CmpPredicate::lt;
break;
case arith::CmpFPredicate::OLE:
unordered = false;
predicate = emitc::CmpPredicate::le;
break;
case arith::CmpFPredicate::ONE:
unordered = false;
predicate = emitc::CmpPredicate::ne;
Expand Down Expand Up @@ -179,9 +183,6 @@ class CmpFOpConversion : public OpConversionPattern<arith::CmpFOp> {
rewriter.replaceOp(op, constant);
return success();
}
default:
return rewriter.notifyMatchFailure(op.getLoc(),
"cannot match predicate ");
}

// Compare the values naively
Expand Down
15 changes: 15 additions & 0 deletions mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,21 @@ func.func @arith_cmpf_olt(%arg0: f32, %arg1: f32) -> i1 {

// -----

func.func @arith_cmpf_ole(%arg0: f32, %arg1: f32) -> i1 {
// CHECK-LABEL: arith_cmpf_ole
// CHECK-SAME: ([[Arg0:[^ ]*]]: f32, [[Arg1:[^ ]*]]: f32)
// CHECK-DAG: [[LT:[^ ]*]] = emitc.cmp le, [[Arg0]], [[Arg1]] : (f32, f32) -> i1
// CHECK-DAG: [[NaNArg0:[^ ]*]] = emitc.cmp eq, [[Arg0]], [[Arg0]] : (f32, f32) -> i1
// CHECK-DAG: [[NaNArg1:[^ ]*]] = emitc.cmp eq, [[Arg1]], [[Arg1]] : (f32, f32) -> i1
// CHECK-DAG: [[Ordered:[^ ]*]] = emitc.logical_and [[NaNArg0]], [[NaNArg1]] : i1, i1
// CHECK-DAG: [[OLE:[^ ]*]] = emitc.logical_and [[Ordered]], [[LT]] : i1, i1
%ole = arith.cmpf ole, %arg0, %arg1 : f32
// CHECK: return [[OLE]]
return %ole: i1
}

// -----

func.func @arith_cmpf_one(%arg0: f32, %arg1: f32) -> i1 {
// CHECK-LABEL: arith_cmpf_one
// CHECK-SAME: ([[Arg0:[^ ]*]]: f32, [[Arg1:[^ ]*]]: f32)
Expand Down

0 comments on commit 9db9dd7

Please sign in to comment.