@@ -395,7 +395,8 @@ class LazyValueInfoImpl {
395
395
// / if it exists in the module.
396
396
Function *GuardDecl;
397
397
398
- Optional<ValueLatticeElement> getBlockValue (Value *Val, BasicBlock *BB);
398
+ Optional<ValueLatticeElement> getBlockValue (Value *Val, BasicBlock *BB,
399
+ Instruction *CxtI);
399
400
Optional<ValueLatticeElement> getEdgeValue (Value *V, BasicBlock *F,
400
401
BasicBlock *T, Instruction *CxtI = nullptr );
401
402
@@ -533,15 +534,17 @@ void LazyValueInfoImpl::solve() {
533
534
}
534
535
}
535
536
536
- Optional<ValueLatticeElement> LazyValueInfoImpl::getBlockValue (Value *Val,
537
- BasicBlock *BB) {
537
+ Optional<ValueLatticeElement> LazyValueInfoImpl::getBlockValue (
538
+ Value *Val, BasicBlock *BB, Instruction *CxtI ) {
538
539
// If already a constant, there is nothing to compute.
539
540
if (Constant *VC = dyn_cast<Constant>(Val))
540
541
return ValueLatticeElement::get (VC);
541
542
542
543
if (Optional<ValueLatticeElement> OptLatticeVal =
543
- TheCache.getCachedValueInfo (Val, BB))
544
+ TheCache.getCachedValueInfo (Val, BB)) {
545
+ intersectAssumeOrGuardBlockValueConstantRange (Val, *OptLatticeVal, CxtI);
544
546
return OptLatticeVal;
547
+ }
545
548
546
549
// We have hit a cycle, assume overdefined.
547
550
if (!pushBlockValue ({ BB, Val }))
@@ -796,13 +799,13 @@ Optional<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueSelect(
796
799
SelectInst *SI, BasicBlock *BB) {
797
800
// Recurse on our inputs if needed
798
801
Optional<ValueLatticeElement> OptTrueVal =
799
- getBlockValue (SI->getTrueValue (), BB);
802
+ getBlockValue (SI->getTrueValue (), BB, SI );
800
803
if (!OptTrueVal)
801
804
return None;
802
805
ValueLatticeElement &TrueVal = *OptTrueVal;
803
806
804
807
Optional<ValueLatticeElement> OptFalseVal =
805
- getBlockValue (SI->getFalseValue (), BB);
808
+ getBlockValue (SI->getFalseValue (), BB, SI );
806
809
if (!OptFalseVal)
807
810
return None;
808
811
ValueLatticeElement &FalseVal = *OptFalseVal;
@@ -873,12 +876,11 @@ Optional<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueSelect(
873
876
Optional<ConstantRange> LazyValueInfoImpl::getRangeFor (Value *V,
874
877
Instruction *CxtI,
875
878
BasicBlock *BB) {
876
- Optional<ValueLatticeElement> OptVal = getBlockValue (V, BB);
879
+ Optional<ValueLatticeElement> OptVal = getBlockValue (V, BB, CxtI );
877
880
if (!OptVal)
878
881
return None;
879
882
880
883
ValueLatticeElement &Val = *OptVal;
881
- intersectAssumeOrGuardBlockValueConstantRange (V, Val, CxtI);
882
884
if (Val.isConstantRange ())
883
885
return Val.getConstantRange ();
884
886
@@ -1017,7 +1019,7 @@ Optional<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueExtractValue(
1017
1019
if (Value *V = SimplifyExtractValueInst (
1018
1020
EVI->getAggregateOperand (), EVI->getIndices (),
1019
1021
EVI->getModule ()->getDataLayout ()))
1020
- return getBlockValue (V, BB);
1022
+ return getBlockValue (V, BB, EVI );
1021
1023
1022
1024
LLVM_DEBUG (dbgs () << " compute BB '" << BB->getName ()
1023
1025
<< " ' - overdefined (unknown extractvalue).\n " );
@@ -1430,14 +1432,12 @@ Optional<ValueLatticeElement> LazyValueInfoImpl::getEdgeValue(
1430
1432
// Can't get any more precise here
1431
1433
return LocalResult;
1432
1434
1433
- Optional<ValueLatticeElement> OptInBlock = getBlockValue (Val, BBFrom);
1435
+ Optional<ValueLatticeElement> OptInBlock =
1436
+ getBlockValue (Val, BBFrom, BBFrom->getTerminator ());
1434
1437
if (!OptInBlock)
1435
1438
return None;
1436
1439
ValueLatticeElement &InBlock = *OptInBlock;
1437
1440
1438
- // Try to intersect ranges of the BB and the constraint on the edge.
1439
- intersectAssumeOrGuardBlockValueConstantRange (Val, InBlock,
1440
- BBFrom->getTerminator ());
1441
1441
// We can use the context instruction (generically the ultimate instruction
1442
1442
// the calling pass is trying to simplify) here, even though the result of
1443
1443
// this function is generally cached when called from the solve* functions
@@ -1457,15 +1457,14 @@ ValueLatticeElement LazyValueInfoImpl::getValueInBlock(Value *V, BasicBlock *BB,
1457
1457
<< BB->getName () << " '\n " );
1458
1458
1459
1459
assert (BlockValueStack.empty () && BlockValueSet.empty ());
1460
- Optional<ValueLatticeElement> OptResult = getBlockValue (V, BB);
1460
+ Optional<ValueLatticeElement> OptResult = getBlockValue (V, BB, CxtI );
1461
1461
if (!OptResult) {
1462
1462
solve ();
1463
- OptResult = getBlockValue (V, BB);
1463
+ OptResult = getBlockValue (V, BB, CxtI );
1464
1464
assert (OptResult && " Value not available after solving" );
1465
1465
}
1466
- ValueLatticeElement Result = *OptResult;
1467
- intersectAssumeOrGuardBlockValueConstantRange (V, Result, CxtI);
1468
1466
1467
+ ValueLatticeElement Result = *OptResult;
1469
1468
LLVM_DEBUG (dbgs () << " Result = " << Result << " \n " );
1470
1469
return Result;
1471
1470
}
0 commit comments