Skip to content

[GVN][NFCI] Use early return in phiTranslateImpl()#149273

Merged
madhur13490 merged 2 commits intollvm:mainfrom
madhur13490:gvn-ertn
Jul 18, 2025
Merged

[GVN][NFCI] Use early return in phiTranslateImpl()#149273
madhur13490 merged 2 commits intollvm:mainfrom
madhur13490:gvn-ertn

Conversation

@madhur13490
Copy link
Copy Markdown
Contributor

No description provided.

@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Jul 17, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Madhur Amilkanthwar (madhur13490)

Changes

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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Scalar/GVN.cpp (+8-5)
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index 8bff458f88bb9..f6bf09d09433d 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -2367,11 +2367,14 @@ uint32_t GVNPass::ValueTable::phiTranslateImpl(const BasicBlock *Pred,
   // See if we can refine the value number by looking at the PN incoming value
   // for the given predecessor.
   if (PHINode *PN = NumberingPhi[Num]) {
-    if (PN->getParent() == PhiBlock)
-      for (unsigned I = 0; I != PN->getNumIncomingValues(); ++I)
-        if (PN->getIncomingBlock(I) == Pred)
-          if (uint32_t TransVal = lookup(PN->getIncomingValue(I), false))
-            return TransVal;
+    if (PN->getParent() != PhiBlock)
+      return Num;
+    for (unsigned I = 0; I != PN->getNumIncomingValues(); ++I) {
+      if (PN->getIncomingBlock(I) != Pred)
+        continue;
+      if (uint32_t TransVal = lookup(PN->getIncomingValue(I), false))
+        return TransVal;
+    }
     return Num;
   }
 

@madhur13490
Copy link
Copy Markdown
Contributor Author

Hi @fhahn @nikic
Just replacing with some better readable code by using early returns. I don't have a test case for this.

@madhur13490 madhur13490 changed the title [GVN][NFC] Use early return in phiTranslateImpl() [GVN][NFCI] Use early return in phiTranslateImpl() Jul 17, 2025
Copy link
Copy Markdown
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

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

I'm not sure this is really better in this specific case, but no strong objections either.

@madhur13490 madhur13490 merged commit 3eb0799 into llvm:main Jul 18, 2025
11 checks passed
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