[Mlir-commits] [mlir] [MLIR] Don't check for key before inserting in map in GreedyPatternRewriteDriver worklist (NFC) (PR #88148)

Mehdi Amini llvmlistbot at llvm.org
Tue Apr 9 10:12:16 PDT 2024


https://github.com/joker-eph updated https://github.com/llvm/llvm-project/pull/88148

>From 4018f03a534eb2e4cc3a733547ccc4125f810e4e Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Tue, 9 Apr 2024 09:16:33 -0700
Subject: [PATCH] [MLIR] Don't check for key before inserting in map in
 GreedyPatternRewriteDriver worklist (NFC)

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.
---
 mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
index bbecbdb8566935..cfd4f9c03aaff2 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);
 }
 



More information about the Mlir-commits mailing list