Skip to content

Conversation

@kasuga-fj
Copy link
Contributor

This is a follow-up PR for post-commit comments in #121104 .

Details:

  • Rename mergeTwoCounter to mergeTwoCounters (add trailing s).
  • Avoid duplicated hash lookup.
  • Use /// instead of //.
  • Fix typo.

@llvmbot
Copy link
Member

llvmbot commented Aug 25, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Ryotaro Kasuga (kasuga-fj)

Changes

This is a follow-up PR for post-commit comments in #121104 .

Details:

  • Rename mergeTwoCounter to mergeTwoCounters (add trailing s).
  • Avoid duplicated hash lookup.
  • Use /// instead of //.
  • Fix typo.

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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Utils/LoopPeel.cpp (+9-11)
diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp
index ba0ac01cadd8e..735bad1cb1348 100644
--- a/llvm/lib/Transforms/Utils/LoopPeel.cpp
+++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp
@@ -225,9 +225,9 @@ class PhiAnalyzer {
 
   // Auxiliary function to calculate the number of iterations for a comparison
   // instruction or a binary operator.
-  PeelCounter mergeTwoCounter(const Instruction &CmpOrBinaryOp,
-                              const PeelCounterValue &LHS,
-                              const PeelCounterValue &RHS) const;
+  PeelCounter mergeTwoCounters(const Instruction &CmpOrBinaryOp,
+                               const PeelCounterValue &LHS,
+                               const PeelCounterValue &RHS) const;
 
   // Returns true if the \p Phi is an induction in the target loop. This is a
   // lightweight check and possible to detect an IV in some cases.
@@ -269,15 +269,13 @@ bool PhiAnalyzer::isInductionPHI(const PHINode *Phi) const {
       break;
 
     // Avoid infinite loop.
-    if (Visited.contains(Cur))
+    if (!Visited.insert(Cur).second)
       return false;
 
     auto *I = dyn_cast<Instruction>(Cur);
     if (!I || !L.contains(I))
       return false;
 
-    Visited.insert(Cur);
-
     if (auto *Cast = dyn_cast<CastInst>(I)) {
       Cur = Cast->getOperand(0);
     } else if (auto *BinOp = dyn_cast<BinaryOperator>(I)) {
@@ -300,14 +298,14 @@ bool PhiAnalyzer::isInductionPHI(const PHINode *Phi) const {
 
 /// When either \p LHS or \p RHS is an IV, the result of \p CmpOrBinaryOp is
 /// considered an IV only if it is an addition or a subtraction. Otherwise the
-/// result can be a value that is neither an loop-invariant nor an IV.
+/// result can be a value that is neither a loop-invariant nor an IV.
 ///
 /// If both \p LHS and \p RHS are loop-invariants, then the result of
 /// \CmpOrBinaryOp is also a loop-invariant.
 PhiAnalyzer::PeelCounter
-PhiAnalyzer::mergeTwoCounter(const Instruction &CmpOrBinaryOp,
-                             const PeelCounterValue &LHS,
-                             const PeelCounterValue &RHS) const {
+PhiAnalyzer::mergeTwoCounters(const Instruction &CmpOrBinaryOp,
+                              const PeelCounterValue &LHS,
+                              const PeelCounterValue &RHS) const {
   auto &[LVal, LTy] = LHS;
   auto &[RVal, RTy] = RHS;
   unsigned NewVal = std::max(LVal, RVal);
@@ -380,7 +378,7 @@ PhiAnalyzer::PeelCounter PhiAnalyzer::calculate(const Value &V) {
       if (RHS == Unknown)
         return Unknown;
       return (IterationsToInvarianceOrInduction[I] =
-                  mergeTwoCounter(*I, *LHS, *RHS));
+                  mergeTwoCounters(*I, *LHS, *RHS));
     }
     if (I->isCast())
       // Cast instructions get the value of the operand.

Copy link
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.

LGTM, thanks!

@nikic
Copy link
Contributor

nikic commented Aug 25, 2025

(CI failure is unrelated)

@kasuga-fj
Copy link
Contributor Author

Thanks for the review!

@kasuga-fj kasuga-fj merged commit df69dfe into llvm:main Aug 25, 2025
10 of 11 checks passed
@kasuga-fj kasuga-fj deleted the followup-121104 branch August 25, 2025 09:18
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