diff --git a/mlir/include/mlir/Dialect/Math/IR/MathOps.td b/mlir/include/mlir/Dialect/Math/IR/MathOps.td --- a/mlir/include/mlir/Dialect/Math/IR/MathOps.td +++ b/mlir/include/mlir/Dialect/Math/IR/MathOps.td @@ -857,7 +857,8 @@ //===----------------------------------------------------------------------===// def Math_FPowIOp : Math_Op<"fpowi", - [SameOperandsAndResultShape, AllTypesMatch<["lhs", "result"]>]> { + [SameOperandsAndResultShape, AllTypesMatch<["lhs", "result"]>, + DeclareOpInterfaceMethods]> { let summary = "floating point raised to the signed integer power"; let description = [{ Syntax: @@ -890,9 +891,12 @@ ``` }]; - let arguments = (ins FloatLike:$lhs, SignlessIntegerLike:$rhs); + let arguments = (ins FloatLike:$lhs, SignlessIntegerLike:$rhs, + DefaultValuedAttr:$fastmath); let results = (outs FloatLike:$result); - let assemblyFormat = "$lhs `,` $rhs attr-dict `:` type($lhs) `,` type($rhs)"; + let assemblyFormat = [{ $lhs `,` $rhs (`fastmath` `` $fastmath^)? + attr-dict `:` type($lhs) `,` type($rhs) }]; // TODO: add a constant folder using pow[f] for cases, when // the power argument is exactly representable in floating diff --git a/mlir/test/Dialect/Math/ops.mlir b/mlir/test/Dialect/Math/ops.mlir --- a/mlir/test/Dialect/Math/ops.mlir +++ b/mlir/test/Dialect/Math/ops.mlir @@ -271,15 +271,18 @@ } // CHECK-LABEL: func @fastmath( -// CHECK-SAME: %[[F:.*]]: f32, %[[V:.*]]: vector<4xf32>, %[[T:.*]]: tensor<4x4x?xf32>) -func.func @fastmath(%f: f32, %v: vector<4xf32>, %t: tensor<4x4x?xf32>) { - // CHECK: %{{.*}} = math.trunc %[[F]] fastmath : f32 +// CHECK-SAME: %[[F:.*]]: f32, %[[I:.*]]: i32, +// CHECK-SAME: %[[V:.*]]: vector<4xf32>, %[[T:.*]]: tensor<4x4x?xf32>) +func.func @fastmath(%f: f32, %i: i32, %v: vector<4xf32>, %t: tensor<4x4x?xf32>) { + // CHECK: math.trunc %[[F]] fastmath : f32 %0 = math.trunc %f fastmath : f32 - // CHECK: %{{.*}} = math.powf %[[V]], %[[V]] fastmath : vector<4xf32> + // CHECK: math.powf %[[V]], %[[V]] fastmath : vector<4xf32> %1 = math.powf %v, %v fastmath : vector<4xf32> - // CHECK: %{{.*}} = math.fma %[[T]], %[[T]], %[[T]] : tensor<4x4x?xf32> + // CHECK: math.fma %[[T]], %[[T]], %[[T]] : tensor<4x4x?xf32> %2 = math.fma %t, %t, %t fastmath : tensor<4x4x?xf32> - // CHECK: %{{.*}} = math.absf %[[F]] fastmath : f32 + // CHECK: math.absf %[[F]] fastmath : f32 %3 = math.absf %f fastmath : f32 + // CHECK: math.fpowi %[[F]], %[[I]] fastmath : f32, i32 + %4 = math.fpowi %f, %i fastmath : f32, i32 return }