@@ -836,19 +836,6 @@ void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
836
836
}
837
837
}
838
838
839
- static ConstantRange toConstantRange (const ValueLatticeElement &Val,
840
- Type *Ty, bool UndefAllowed = false ) {
841
- assert (Ty->isIntOrIntVectorTy () && " Must be integer type" );
842
- if (Val.isConstantRange (UndefAllowed))
843
- return Val.getConstantRange ();
844
- unsigned BW = Ty->getScalarSizeInBits ();
845
- if (Val.isUnknown ())
846
- return ConstantRange::getEmpty (BW);
847
- if (Val.isConstant ())
848
- return Val.getConstant ()->toConstantRange ();
849
- return ConstantRange::getFull (BW);
850
- }
851
-
852
839
std::optional<ValueLatticeElement>
853
840
LazyValueInfoImpl::solveBlockValueSelect (SelectInst *SI, BasicBlock *BB) {
854
841
// Recurse on our inputs if needed
@@ -865,8 +852,8 @@ LazyValueInfoImpl::solveBlockValueSelect(SelectInst *SI, BasicBlock *BB) {
865
852
ValueLatticeElement &FalseVal = *OptFalseVal;
866
853
867
854
if (TrueVal.isConstantRange () || FalseVal.isConstantRange ()) {
868
- const ConstantRange &TrueCR = toConstantRange ( TrueVal, SI->getType ());
869
- const ConstantRange &FalseCR = toConstantRange ( FalseVal, SI->getType ());
855
+ const ConstantRange &TrueCR = TrueVal. asConstantRange ( SI->getType ());
856
+ const ConstantRange &FalseCR = FalseVal. asConstantRange ( SI->getType ());
870
857
Value *LHS = nullptr ;
871
858
Value *RHS = nullptr ;
872
859
SelectPatternResult SPR = matchSelectPattern (SI, LHS, RHS);
@@ -941,7 +928,7 @@ LazyValueInfoImpl::getRangeFor(Value *V, Instruction *CxtI, BasicBlock *BB) {
941
928
std::optional<ValueLatticeElement> OptVal = getBlockValue (V, BB, CxtI);
942
929
if (!OptVal)
943
930
return std::nullopt;
944
- return toConstantRange (* OptVal, V->getType ());
931
+ return OptVal-> asConstantRange ( V->getType ());
945
932
}
946
933
947
934
std::optional<ValueLatticeElement>
@@ -1119,7 +1106,7 @@ LazyValueInfoImpl::getValueFromSimpleICmpCondition(CmpInst::Predicate Pred,
1119
1106
getBlockValue (RHS, CxtI->getParent (), CxtI);
1120
1107
if (!R)
1121
1108
return std::nullopt;
1122
- RHSRange = toConstantRange (*R, RHS->getType ());
1109
+ RHSRange = R-> asConstantRange ( RHS->getType ());
1123
1110
}
1124
1111
1125
1112
ConstantRange TrueValues =
@@ -1734,15 +1721,15 @@ ConstantRange LazyValueInfo::getConstantRange(Value *V, Instruction *CxtI,
1734
1721
BasicBlock *BB = CxtI->getParent ();
1735
1722
ValueLatticeElement Result =
1736
1723
getOrCreateImpl (BB->getModule ()).getValueInBlock (V, BB, CxtI);
1737
- return toConstantRange ( Result, V->getType (), UndefAllowed);
1724
+ return Result. asConstantRange ( V->getType (), UndefAllowed);
1738
1725
}
1739
1726
1740
1727
ConstantRange LazyValueInfo::getConstantRangeAtUse (const Use &U,
1741
1728
bool UndefAllowed) {
1742
1729
auto *Inst = cast<Instruction>(U.getUser ());
1743
1730
ValueLatticeElement Result =
1744
1731
getOrCreateImpl (Inst->getModule ()).getValueAtUse (U);
1745
- return toConstantRange ( Result, U->getType (), UndefAllowed);
1732
+ return Result. asConstantRange ( U->getType (), UndefAllowed);
1746
1733
}
1747
1734
1748
1735
// / Determine whether the specified value is known to be a
@@ -1772,7 +1759,7 @@ ConstantRange LazyValueInfo::getConstantRangeOnEdge(Value *V,
1772
1759
ValueLatticeElement Result =
1773
1760
getOrCreateImpl (M).getValueOnEdge (V, FromBB, ToBB, CxtI);
1774
1761
// TODO: Should undef be allowed here?
1775
- return toConstantRange ( Result, V->getType (), /* UndefAllowed*/ true );
1762
+ return Result. asConstantRange ( V->getType (), /* UndefAllowed*/ true );
1776
1763
}
1777
1764
1778
1765
static Constant *getPredicateResult (CmpInst::Predicate Pred, Constant *C,
0 commit comments