[Mlir-commits] [mlir] [Bytecode] Avoid repeated hash lookups (NFC) (PR #108320)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Sep 11 20:00:51 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/108320.diff


1 Files Affected:

- (modified) mlir/lib/Bytecode/Reader/BytecodeReader.cpp (+1-2) 


``````````diff
diff --git a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
index a57b2178aec707..e9de3062d41c70 100644
--- a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
+++ b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
@@ -2017,10 +2017,9 @@ LogicalResult BytecodeReader::Impl::sortUseListOrder(Value value) {
   DenseSet<unsigned> set;
   uint64_t accumulator = 0;
   for (const auto &elem : shuffle) {
-    if (set.contains(elem))
+    if (!set.insert(elem).second)
       return failure();
     accumulator += elem;
-    set.insert(elem);
   }
   if (numUses != shuffle.size() ||
       accumulator != (((numUses - 1) * numUses) >> 1))

``````````

</details>


https://github.com/llvm/llvm-project/pull/108320


More information about the Mlir-commits mailing list