Jeroen Dobbelaere in
https://lists.llvm.org/pipermail/llvm-dev/2021-March/149206.html
is reporting that this function can end up in an endless loop
when called from SROA w/ full restrict patches.
For now, simply ensure that such problems are caught earlier/easier.
const Value *llvm::getUnderlyingObject(const Value *V, unsigned MaxLookup) {
if (!V->getType()->isPointerTy())
return V;
+#ifndef NDEBUG
+ SmallPtrSet<const Value *, 8> Visited;
+#endif
for (unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
+ assert(Visited.insert(V).second && "Cycle detected. Unreachable code?");
if (auto *GEP = dyn_cast<GEPOperator>(V)) {
V = GEP->getPointerOperand();
} else if (Operator::getOpcode(V) == Instruction::BitCast ||