[Mlir-commits] [mlir] 1bf2b16 - Implement constant folding for DivFOp
Mehdi Amini
llvmlistbot at llvm.org
Tue Jan 19 15:08:21 PST 2021
Author: Jackson Fellows
Date: 2021-01-19T23:08:06Z
New Revision: 1bf2b1665b43e1a5090177486c8fa6374a4596a2
URL: https://github.com/llvm/llvm-project/commit/1bf2b1665b43e1a5090177486c8fa6374a4596a2
DIFF: https://github.com/llvm/llvm-project/commit/1bf2b1665b43e1a5090177486c8fa6374a4596a2.diff
LOG: Implement constant folding for DivFOp
Add a constant folder for DivFOp. Analogous to existing folders for
AddFOp, SubFOp, and MulFOp. Matches the behavior of existing LLVM
constant folding (https://github.com/llvm/llvm-project/blob/999f5da6b3088fa4c0bb9d05b358d015ca74c71f/llvm/lib/IR/ConstantFold.cpp#L1432).
Reviewed By: ftynse
Differential Revision: https://reviews.llvm.org/D94939
Added:
Modified:
mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
index 8e3f1f1a7a85..8db6129dbb88 100644
--- a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
+++ b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
@@ -1589,6 +1589,7 @@ def DimOp : Std_Op<"dim", [NoSideEffect]> {
def DivFOp : FloatArithmeticOp<"divf"> {
let summary = "floating point division operation";
+ let hasFolder = 1;
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
index e1be47f54798..1718ab14d5d1 100644
--- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
+++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
@@ -1483,6 +1483,15 @@ void DimOp::getCanonicalizationPatterns(OwningRewritePatternList &results,
DimOfCastOp<tensor::CastOp>>(context);
}
+// ---------------------------------------------------------------------------
+// DivFOp
+// ---------------------------------------------------------------------------
+
+OpFoldResult DivFOp::fold(ArrayRef<Attribute> operands) {
+ return constFoldBinaryOp<FloatAttr>(
+ operands, [](APFloat a, APFloat b) { return a / b; });
+}
+
// ---------------------------------------------------------------------------
// DmaStartOp
// ---------------------------------------------------------------------------
More information about the Mlir-commits
mailing list