[Mlir-commits] [mlir] 40a89da - [Canonicalize] Don't call isBeforeInBlock in OperationFolder::tryToFold.
Chris Lattner
llvmlistbot at llvm.org
Wed Sep 8 13:33:28 PDT 2021
Author: Chris Lattner
Date: 2021-09-08T13:33:22-07:00
New Revision: 40a89da65ce85163123cdfec66afdcf2fa3687ce
URL: https://github.com/llvm/llvm-project/commit/40a89da65ce85163123cdfec66afdcf2fa3687ce
DIFF: https://github.com/llvm/llvm-project/commit/40a89da65ce85163123cdfec66afdcf2fa3687ce.diff
LOG: [Canonicalize] Don't call isBeforeInBlock in OperationFolder::tryToFold.
This patch (e4635e6328c8) fixed a bug where a newly generated/reused
constant wouldn't dominate a folded operation. It did so by calling
isBeforeInBlock to move the constant around on demand. This introduced
a significant compile time regression, because "isBeforeInBlock" is
O(n) in the size of a block the first time it is called, and the cache
is invalidated any time canonicalize changes something big in the block.
This fixes LLVM PR51738 and this CIRCT issue:
https://github.com/llvm/circt/issues/1700
This does affect the order of constants left in the top of a block,
I staged in the testsuite changes in rG42431b8207a5.
Differential Revision: https://reviews.llvm.org/D109454
Added:
Modified:
mlir/lib/Transforms/Utils/FoldUtils.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Transforms/Utils/FoldUtils.cpp b/mlir/lib/Transforms/Utils/FoldUtils.cpp
index f9e1bb45de56..2fcd6a4c5146 100644
--- a/mlir/lib/Transforms/Utils/FoldUtils.cpp
+++ b/mlir/lib/Transforms/Utils/FoldUtils.cpp
@@ -236,10 +236,9 @@ LogicalResult OperationFolder::tryToFold(
// Ensure that this constant dominates the operation we are replacing it
// with. This may not automatically happen if the operation being folded
// was inserted before the constant within the insertion block.
- if (constOp->getBlock() == op->getBlock() &&
- !constOp->isBeforeInBlock(op)) {
- constOp->moveBefore(op);
- }
+ Block *opBlock = op->getBlock();
+ if (opBlock == constOp->getBlock() && &opBlock->front() != constOp)
+ constOp->moveBefore(&opBlock->front());
results.push_back(constOp->getResult(0));
continue;
More information about the Mlir-commits
mailing list