@@ -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
@@ -10258,11 +10268,8 @@ void llvm::findValuesAffectedByCondition(
10258
10268
CmpPredicate Pred;
10259
10269
Value *A, *B, *X;
10260
10270
10261
- if (IsAssume) {
10271
+ if (IsAssume)
10262
10272
AddAffected (V);
10263
- if (match (V, m_Not (m_Value (X))))
10264
- AddAffected (X);
10265
- }
10266
10273
10267
10274
if (match (V, m_LogicalOp (m_Value (A), m_Value (B)))) {
10268
10275
// assume(A && B) is split to -> assume(A); assume(B);
@@ -10347,8 +10354,7 @@ void llvm::findValuesAffectedByCondition(
10347
10354
// Assume is checked here as X is already added above for assumes in
10348
10355
// addValueAffectedByCondition
10349
10356
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)))) {
10352
10358
Worklist.push_back (X);
10353
10359
}
10354
10360
}
0 commit comments