Skip to content

[SCEV] Improve code in SCEVLoopGuardRewriter (NFC) #139257

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

Merged
merged 2 commits into from
May 11, 2025

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
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants