Skip to content

ValueTracking: Do not look at users of constants for ephemeral values #134618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
}
}
}
Expand Down