Skip to content

Commit 162b627

Browse files
committed
[ValueTracking] Handle not in assume argument in isEphemeralValueOf.
1 parent c2fea0d commit 162b627

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -441,16 +441,28 @@ void llvm::computeKnownBitsFromRangeMetadata(const MDNode &Ranges,
441441
}
442442

443443
static bool isEphemeralValueOf(const Instruction *I, const Value *E) {
444-
SmallVector<const Value *, 16> WorkSet(1, I);
445-
SmallPtrSet<const Value *, 32> Visited;
446-
SmallPtrSet<const Value *, 16> EphValues;
447444

448445
// The instruction defining an assumption's condition itself is always
449446
// considered ephemeral to that assumption (even if it has other
450447
// non-ephemeral users). See r246696's test case for an example.
451448
if (is_contained(I->operands(), E))
452449
return true;
453450

451+
SmallPtrSet<const Value *, 32> Visited{I};
452+
SmallPtrSet<const Value *, 16> EphValues{I};
453+
454+
Value *X;
455+
if (match(I, m_Intrinsic<Intrinsic::assume>(m_Not(m_Value(X))))) {
456+
if (X == E)
457+
return true;
458+
auto *Not = cast<Instruction>(I->getOperand(0));
459+
Visited.insert(Not);
460+
EphValues.insert(Not);
461+
I = Not;
462+
}
463+
464+
SmallVector<const Value *, 16> WorkSet(I->operands());
465+
454466
while (!WorkSet.empty()) {
455467
const Value *V = WorkSet.pop_back_val();
456468
if (!Visited.insert(V).second)
@@ -463,13 +475,11 @@ static bool isEphemeralValueOf(const Instruction *I, const Value *E) {
463475
if (V == E)
464476
return true;
465477

466-
if (V == I || (isa<Instruction>(V) &&
467-
!cast<Instruction>(V)->mayHaveSideEffects() &&
468-
!cast<Instruction>(V)->isTerminator())) {
469-
EphValues.insert(V);
470-
if (const User *U = dyn_cast<User>(V))
471-
append_range(WorkSet, U->operands());
472-
}
478+
if (const auto *II = dyn_cast<Instruction>(V))
479+
if (!II->mayHaveSideEffects() && !II->isTerminator()) {
480+
EphValues.insert(V);
481+
append_range(WorkSet, II->operands());
482+
}
473483
}
474484
}
475485

@@ -10214,11 +10224,8 @@ void llvm::findValuesAffectedByCondition(
1021410224
CmpPredicate Pred;
1021510225
Value *A, *B, *X;
1021610226

10217-
if (IsAssume) {
10227+
if (IsAssume)
1021810228
AddAffected(V);
10219-
if (match(V, m_Not(m_Value(X))))
10220-
AddAffected(X);
10221-
}
1022210229

1022310230
if (match(V, m_LogicalOp(m_Value(A), m_Value(B)))) {
1022410231
// assume(A && B) is split to -> assume(A); assume(B);
@@ -10302,8 +10309,7 @@ void llvm::findValuesAffectedByCondition(
1030210309
// Assume is checked here as X is already added above for assumes in
1030310310
// addValueAffectedByCondition
1030410311
AddAffected(X);
10305-
} else if (!IsAssume && match(V, m_Not(m_Value(X)))) {
10306-
// Assume is checked here to avoid issues with ephemeral values
10312+
} else if (match(V, m_Not(m_Value(X)))) {
1030710313
Worklist.push_back(X);
1030810314
}
1030910315
}

0 commit comments

Comments
 (0)