diff --git a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td --- a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td +++ b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td @@ -2339,6 +2339,7 @@ %x = powf %y, %z : tensor<4x?xbf16> ``` }]; + let hasFolder = 1; } //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp --- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp +++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp @@ -2263,6 +2263,22 @@ [](APInt a, APInt b) { return a | b; }); } +//===----------------------------------------------------------------------===// +// PowFOp +//===----------------------------------------------------------------------===// + +OpFoldResult PowFOp::fold(ArrayRef operands) { + return constFoldBinaryOp(operands, [](APFloat a, APFloat b) { + bool unused; + // assume a and b are the same floating point type (i.e. share the same + // semantics) + APFloat res = APFloat( + pow(FloatAttr::getValueAsDouble(a), FloatAttr::getValueAsDouble(b))); + res.convert(a.getSemantics(), APFloat::rmNearestTiesToEven, &unused); + return res; + }); +} + //===----------------------------------------------------------------------===// // PrefetchOp //===----------------------------------------------------------------------===//