[llvm-branch-commits] [llvm] 12245c2 - Revert "[IR] Use iteration limit in stripPointerCastsAndOffsets (#190472)"

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Apr 7 13:02:09 PDT 2026


Author: Arthur Eubanks
Date: 2026-04-07T13:02:05-07:00
New Revision: 12245c223ee55913a3bd18cb23e23f688c5e821c

URL: https://github.com/llvm/llvm-project/commit/12245c223ee55913a3bd18cb23e23f688c5e821c
DIFF: https://github.com/llvm/llvm-project/commit/12245c223ee55913a3bd18cb23e23f688c5e821c.diff

LOG: Revert "[IR] Use iteration limit in stripPointerCastsAndOffsets (#190472)"

This reverts commit b5e7dbb30ace6c9f7b7920462e209bb08e7ffa56.

Added: 
    

Modified: 
    llvm/lib/IR/Value.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index d97eb406d2130..360bf0f8fc47f 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -642,12 +642,11 @@ static const Value *stripPointerCastsAndOffsets(
     return V;
 
   // Even though we don't look through PHI nodes, we could be called on an
-  // instruction in an unreachable block, which may be on a cycle. E.g.:
-  //   %gep = getelementptr inbounds nuw i8, ptr %gep, i64 32
-  //
-  // Bound against that case with a simple iteration counter. Practically, more
-  // than 10 iterations are almost never needed.
-  for (unsigned N = 0; N < 12; ++N) {
+  // instruction in an unreachable block, which may be on a cycle.
+  SmallPtrSet<const Value *, 4> Visited;
+
+  Visited.insert(V);
+  do {
     Func(V);
     if (auto *GEP = dyn_cast<GEPOperator>(V)) {
       switch (StripKind) {
@@ -667,11 +666,7 @@ static const Value *stripPointerCastsAndOffsets(
           return V;
         break;
       }
-      const Value *NewV = GEP->getPointerOperand();
-      // Quick exit for degenerate IR, which can happen in unreachable blocks.
-      if (NewV == V)
-        return V;
-      V = NewV;
+      V = GEP->getPointerOperand();
     } else if (Operator::getOpcode(V) == Instruction::BitCast) {
       Value *NewV = cast<Operator>(V)->getOperand(0);
       if (!NewV->getType()->isPointerTy())
@@ -706,7 +701,7 @@ static const Value *stripPointerCastsAndOffsets(
       return V;
     }
     assert(V->getType()->isPointerTy() && "Unexpected operand type!");
-  }
+  } while (Visited.insert(V).second);
 
   return V;
 }


        


More information about the llvm-branch-commits mailing list