diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2025-04-09 19:15:16 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-09 19:15:16 +0700 |
commit | 258aa65197126fda5b3566734cd7d980343e332d (patch) | |
tree | 009b1e6e5d5a041078169c8953ecd6852affd189 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | bc09c7405547fe56a896386b152b667878d2d8c2 (diff) | |
download | llvm-258aa65197126fda5b3566734cd7d980343e332d.zip llvm-258aa65197126fda5b3566734cd7d980343e332d.tar.gz llvm-258aa65197126fda5b3566734cd7d980343e332d.tar.bz2 |
ValueTracking: Do not look at users of constants for ephemeral values (#134618)
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 3b0249f..d9c5533 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<const Value *, 16> WorkSet(1, I); - SmallPtrSet<const Value *, 32> Visited; - SmallPtrSet<const Value *, 16> EphValues; + SmallVector<const Instruction *, 16> WorkSet(1, I); + SmallPtrSet<const Instruction *, 32> Visited; + SmallPtrSet<const Instruction *, 16> 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<Instruction>(U)); + })) { if (V == E) return true; - if (V == I || (isa<Instruction>(V) && - !cast<Instruction>(V)->mayHaveSideEffects() && - !cast<Instruction>(V)->isTerminator())) { - EphValues.insert(V); - if (const User *U = dyn_cast<User>(V)) - append_range(WorkSet, U->operands()); + if (V == I || (!V->mayHaveSideEffects() && !V->isTerminator())) { + EphValues.insert(V); + + if (const User *U = dyn_cast<User>(V)) { + for (const Use &U : U->operands()) { + if (const auto *I = dyn_cast<Instruction>(U.get())) + WorkSet.push_back(I); + } + } } } } |