diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 3b0249f91d6d7..d9c55330f8664 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -446,9 +446,9 @@ void llvm::computeKnownBitsFromRangeMetadata(const MDNode &Ranges, } static bool isEphemeralValueOf(const Instruction *I, const Value *E) { - SmallVector WorkSet(1, I); - SmallPtrSet Visited; - SmallPtrSet EphValues; + SmallVector WorkSet(1, I); + SmallPtrSet Visited; + SmallPtrSet EphValues; // The instruction defining an assumption's condition itself is always // considered ephemeral to that assumption (even if it has other @@ -457,23 +457,26 @@ static bool isEphemeralValueOf(const Instruction *I, const Value *E) { return true; while (!WorkSet.empty()) { - const Value *V = WorkSet.pop_back_val(); + const Instruction *V = WorkSet.pop_back_val(); if (!Visited.insert(V).second) continue; // If all uses of this value are ephemeral, then so is this value. - if (llvm::all_of(V->users(), [&](const User *U) { - return EphValues.count(U); - })) { + if (all_of(V->users(), [&](const User *U) { + return EphValues.count(cast(U)); + })) { if (V == E) return true; - if (V == I || (isa(V) && - !cast(V)->mayHaveSideEffects() && - !cast(V)->isTerminator())) { - EphValues.insert(V); - if (const User *U = dyn_cast(V)) - append_range(WorkSet, U->operands()); + if (V == I || (!V->mayHaveSideEffects() && !V->isTerminator())) { + EphValues.insert(V); + + if (const User *U = dyn_cast(V)) { + for (const Use &U : U->operands()) { + if (const auto *I = dyn_cast(U.get())) + WorkSet.push_back(I); + } + } } } }