@@ -441,16 +441,28 @@ void llvm::computeKnownBitsFromRangeMetadata(const MDNode &Ranges,
441
441
}
442
442
443
443
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;
447
444
448
445
// The instruction defining an assumption's condition itself is always
449
446
// considered ephemeral to that assumption (even if it has other
450
447
// non-ephemeral users). See r246696's test case for an example.
451
448
if (is_contained (I->operands (), E))
452
449
return true ;
453
450
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
+
454
466
while (!WorkSet.empty ()) {
455
467
const Value *V = WorkSet.pop_back_val ();
456
468
if (!Visited.insert (V).second )
@@ -463,13 +475,11 @@ static bool isEphemeralValueOf(const Instruction *I, const Value *E) {
463
475
if (V == E)
464
476
return true ;
465
477
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
+ }
473
483
}
474
484
}
475
485
@@ -10214,11 +10224,8 @@ void llvm::findValuesAffectedByCondition(
10214
10224
CmpPredicate Pred;
10215
10225
Value *A, *B, *X;
10216
10226
10217
- if (IsAssume) {
10227
+ if (IsAssume)
10218
10228
AddAffected (V);
10219
- if (match(V, m_Not(m_Value(X))))
10220
- AddAffected(X);
10221
- }
10222
10229
10223
10230
if (match (V, m_LogicalOp (m_Value (A), m_Value (B)))) {
10224
10231
// assume(A && B) is split to -> assume(A); assume(B);
@@ -10302,8 +10309,7 @@ void llvm::findValuesAffectedByCondition(
10302
10309
// Assume is checked here as X is already added above for assumes in
10303
10310
// addValueAffectedByCondition
10304
10311
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)))) {
10307
10313
Worklist.push_back (X);
10308
10314
}
10309
10315
}
0 commit comments