diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 2a49a10447e0b..3f94a82d08417 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -441,9 +441,6 @@ void llvm::computeKnownBitsFromRangeMetadata(const MDNode &Ranges, } static bool isEphemeralValueOf(const Instruction *I, const Value *E) { - 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 @@ -451,6 +448,21 @@ static bool isEphemeralValueOf(const Instruction *I, const Value *E) { if (is_contained(I->operands(), E)) return true; + SmallPtrSet Visited{I}; + SmallPtrSet EphValues{I}; + + Value *X; + if (match(I, m_Intrinsic(m_Not(m_Value(X))))) { + if (X == E) + return true; + auto *Not = cast(I->getOperand(0)); + Visited.insert(Not); + EphValues.insert(Not); + I = Not; + } + + SmallVector WorkSet(I->operands()); + while (!WorkSet.empty()) { const Value *V = WorkSet.pop_back_val(); if (!Visited.insert(V).second) @@ -463,13 +475,11 @@ static bool isEphemeralValueOf(const Instruction *I, const Value *E) { 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 (const auto *II = dyn_cast(V)) + if (!II->mayHaveSideEffects() && !II->isTerminator()) { + EphValues.insert(V); + append_range(WorkSet, II->operands()); + } } } @@ -10258,11 +10268,8 @@ void llvm::findValuesAffectedByCondition( CmpPredicate Pred; Value *A, *B, *X; - if (IsAssume) { + if (IsAssume) AddAffected(V); - if (match(V, m_Not(m_Value(X)))) - AddAffected(X); - } if (match(V, m_LogicalOp(m_Value(A), m_Value(B)))) { // assume(A && B) is split to -> assume(A); assume(B); @@ -10347,8 +10354,7 @@ void llvm::findValuesAffectedByCondition( // Assume is checked here as X is already added above for assumes in // addValueAffectedByCondition AddAffected(X); - } else if (!IsAssume && match(V, m_Not(m_Value(X)))) { - // Assume is checked here to avoid issues with ephemeral values + } else if (match(V, m_Not(m_Value(X)))) { Worklist.push_back(X); } } diff --git a/llvm/test/Transforms/InstCombine/assume.ll b/llvm/test/Transforms/InstCombine/assume.ll index 0007cc1518730..ed133342d1775 100644 --- a/llvm/test/Transforms/InstCombine/assume.ll +++ b/llvm/test/Transforms/InstCombine/assume.ll @@ -983,8 +983,7 @@ define i1 @not_cond_use(i8 %x) { ; CHECK-NEXT: tail call void @use(i1 [[CMP]]) ; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[CMP]], true ; CHECK-NEXT: tail call void @llvm.assume(i1 [[NOT]]) -; CHECK-NEXT: [[RVAL:%.*]] = icmp eq i8 [[X]], 0 -; CHECK-NEXT: ret i1 [[RVAL]] +; CHECK-NEXT: ret i1 false ; %cmp = icmp eq i8 %x, 0 tail call void @use(i1 %cmp)