@@ -441,16 +441,28 @@ void llvm::computeKnownBitsFromRangeMetadata(const MDNode &Ranges,
441441}
442442
443443static 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
@@ -10258,11 +10268,8 @@ void llvm::findValuesAffectedByCondition(
1025810268 CmpPredicate Pred;
1025910269 Value *A, *B, *X;
1026010270
10261- if (IsAssume) {
10271+ if (IsAssume)
1026210272 AddAffected (V);
10263- if (match (V, m_Not (m_Value (X))))
10264- AddAffected (X);
10265- }
1026610273
1026710274 if (match (V, m_LogicalOp (m_Value (A), m_Value (B)))) {
1026810275 // assume(A && B) is split to -> assume(A); assume(B);
@@ -10347,8 +10354,7 @@ void llvm::findValuesAffectedByCondition(
1034710354 // Assume is checked here as X is already added above for assumes in
1034810355 // addValueAffectedByCondition
1034910356 AddAffected (X);
10350- } else if (!IsAssume && match (V, m_Not (m_Value (X)))) {
10351- // Assume is checked here to avoid issues with ephemeral values
10357+ } else if (match (V, m_Not (m_Value (X)))) {
1035210358 Worklist.push_back (X);
1035310359 }
1035410360 }
0 commit comments