diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -4299,47 +4299,12 @@ return true; } -static AllocaInst * -findAllocaForValue(Value *V, DenseMap &AllocaForValue) { - if (AllocaInst *AI = dyn_cast(V)) - return AI; - // See if we've already calculated (or started to calculate) alloca for a - // given value. - auto I = AllocaForValue.find(V); - if (I != AllocaForValue.end()) - return I->second; - // Store 0 while we're calculating alloca for value V to avoid - // infinite recursion if the value references itself. - AllocaForValue[V] = nullptr; - AllocaInst *Res = nullptr; - if (CastInst *CI = dyn_cast(V)) - Res = findAllocaForValue(CI->getOperand(0), AllocaForValue); - else if (PHINode *PN = dyn_cast(V)) { - for (Value *IncValue : PN->incoming_values()) { - // Allow self-referencing phi-nodes. - if (IncValue == PN) - continue; - AllocaInst *IncValueAI = findAllocaForValue(IncValue, AllocaForValue); - // AI for incoming values should exist and should all be equal. - if (IncValueAI == nullptr || (Res != nullptr && IncValueAI != Res)) - return nullptr; - Res = IncValueAI; - } - } else if (GetElementPtrInst *EP = dyn_cast(V)) { - Res = findAllocaForValue(EP->getPointerOperand(), AllocaForValue); - } else { -#ifndef NDEBUG - dbgs() << "Alloca search cancelled on unknown instruction: " << *V << "\n"; -#endif - } - if (Res) - AllocaForValue[V] = Res; - return Res; -} - AllocaInst *llvm::findAllocaForValue(Value *V) { - DenseMap AllocaForValue; - return ::findAllocaForValue(V, AllocaForValue); + SmallVector Objects; + GetUnderlyingObjects(V, Objects); + if (Objects.size() != 1) + return nullptr; + return const_cast(dyn_cast(Objects.front())); } static bool onlyUsedByLifetimeMarkersOrDroppableInstsHelper(