[Mlir-commits] [mlir] [MLIR] Don't check for key before inserting in map in GreedyPatternRewriteDriver worklist (NFC) (PR #88148)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Apr 9 09:20:18 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
Author: Mehdi Amini (joker-eph)
<details>
<summary>Changes</summary>
This is a common anti-pattern (any volunteer for a clang-tidy check?).
Amazingly a micro-benchmark of the GreedyPatternRewriteDriver shows a 2.5x speedup of the entire GreedyPatternRewriteDriver execution with this patch.
---
Full diff: https://github.com/llvm/llvm-project/pull/88148.diff
1 Files Affected:
- (modified) mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp (+1-2)
``````````diff
diff --git a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
index bbecbdb8566935..604d8628fae755 100644
--- a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
+++ b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
@@ -243,9 +243,8 @@ bool Worklist::empty() const {
void Worklist::push(Operation *op) {
assert(op && "cannot push nullptr to worklist");
// Check to see if the worklist already contains this op.
- if (map.count(op))
+ if (map.insert({op, list.size()}).second)
return;
- map[op] = list.size();
list.push_back(op);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/88148
More information about the Mlir-commits
mailing list