Skip to content

Conversation

@artagnon
Copy link
Contributor

@artagnon artagnon commented May 9, 2025

Prefer DenseMap::lookup over DenseMap::find.

Prefer DenseMap::lookup over DenseMap::find.
@artagnon artagnon requested a review from nikic as a code owner May 9, 2025 12:56
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label May 9, 2025
@llvmbot
Copy link
Member

llvmbot commented May 9, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Ramkumar Ramachandra (artagnon)

Changes

Prefer DenseMap::lookup over DenseMap::find.


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

1 Files Affected:

  • (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+12-12)
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 3f9614254ae7a..38071c0714e82 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -15867,8 +15867,8 @@ const SCEV *ScalarEvolution::LoopGuards::rewrite(const SCEV *Expr) const {
     }
 
     const SCEV *visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) {
-      auto I = Map.find(Expr);
-      if (I == Map.end()) {
+      const SCEV *S = Map.lookup(Expr);
+      if (!S) {
         // If we didn't find the extact ZExt expr in the map, check if there's
         // an entry for a smaller ZExt we can use instead.
         Type *Ty = Expr->getType();
@@ -15887,29 +15887,29 @@ const SCEV *ScalarEvolution::LoopGuards::rewrite(const SCEV *Expr) const {
         return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitZeroExtendExpr(
             Expr);
       }
-      return I->second;
+      return S;
     }
 
     const SCEV *visitSignExtendExpr(const SCEVSignExtendExpr *Expr) {
-      auto I = Map.find(Expr);
-      if (I == Map.end())
+      const SCEV *S = Map.lookup(Expr);
+      if (!S)
         return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitSignExtendExpr(
             Expr);
-      return I->second;
+      return S;
     }
 
     const SCEV *visitUMinExpr(const SCEVUMinExpr *Expr) {
-      auto I = Map.find(Expr);
-      if (I == Map.end())
+      const SCEV *S = Map.lookup(Expr);
+      if (!S)
         return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitUMinExpr(Expr);
-      return I->second;
+      return S;
     }
 
     const SCEV *visitSMinExpr(const SCEVSMinExpr *Expr) {
-      auto I = Map.find(Expr);
-      if (I == Map.end())
+      const SCEV *S = Map.lookup(Expr);
+      if (!S)
         return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitSMinExpr(Expr);
-      return I->second;
+      return S;
     }
 
     const SCEV *visitAddExpr(const SCEVAddExpr *Expr) {

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

Might be also worth folding the lookup into the if if possible

@artagnon artagnon merged commit acd6294 into llvm:main May 11, 2025
8 of 11 checks passed
@artagnon artagnon deleted the scev-loopguardrew-nfc branch May 11, 2025 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants