Skip to content

[Transforms] Avoid repeated hash looksup (NFC) #107727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Sep 7, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp (+1-3)
diff --git a/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp b/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
index c7b88d3c48a69f..2c2400d9dd7a82 100644
--- a/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
@@ -139,11 +139,9 @@ static bool processHeaderPhiOperands(BasicBlock *Header, BasicBlock *Latch,
   SmallPtrSet<Instruction *, 8> VisitedInstr;
 
   std::function<bool(Instruction * I)> ProcessInstr = [&](Instruction *I) {
-    if (VisitedInstr.count(I))
+    if (!VisitedInstr.insert(I).second)
       return true;
 
-    VisitedInstr.insert(I);
-
     if (AftBlocks.count(I->getParent()))
       for (auto &U : I->operands())
         if (Instruction *II = dyn_cast<Instruction>(U))

Copy link
Contributor

@caojoshua caojoshua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kazutakahirata kazutakahirata merged commit caebb45 into llvm:main Sep 8, 2024
10 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_LoopUnrollAndJam branch September 8, 2024 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants