@@ -836,19 +836,6 @@ void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
836836 }
837837}
838838
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-
852839std::optional<ValueLatticeElement>
853840LazyValueInfoImpl::solveBlockValueSelect (SelectInst *SI, BasicBlock *BB) {
854841 // Recurse on our inputs if needed
@@ -865,8 +852,8 @@ LazyValueInfoImpl::solveBlockValueSelect(SelectInst *SI, BasicBlock *BB) {
865852 ValueLatticeElement &FalseVal = *OptFalseVal;
866853
867854 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 ());
870857 Value *LHS = nullptr ;
871858 Value *RHS = nullptr ;
872859 SelectPatternResult SPR = matchSelectPattern (SI, LHS, RHS);
@@ -941,7 +928,7 @@ LazyValueInfoImpl::getRangeFor(Value *V, Instruction *CxtI, BasicBlock *BB) {
941928 std::optional<ValueLatticeElement> OptVal = getBlockValue (V, BB, CxtI);
942929 if (!OptVal)
943930 return std::nullopt ;
944- return toConstantRange (* OptVal, V->getType ());
931+ return OptVal-> asConstantRange ( V->getType ());
945932}
946933
947934std::optional<ValueLatticeElement>
@@ -1119,7 +1106,7 @@ LazyValueInfoImpl::getValueFromSimpleICmpCondition(CmpInst::Predicate Pred,
11191106 getBlockValue (RHS, CxtI->getParent (), CxtI);
11201107 if (!R)
11211108 return std::nullopt ;
1122- RHSRange = toConstantRange (*R, RHS->getType ());
1109+ RHSRange = R-> asConstantRange ( RHS->getType ());
11231110 }
11241111
11251112 ConstantRange TrueValues =
@@ -1734,15 +1721,15 @@ ConstantRange LazyValueInfo::getConstantRange(Value *V, Instruction *CxtI,
17341721 BasicBlock *BB = CxtI->getParent ();
17351722 ValueLatticeElement Result =
17361723 getOrCreateImpl (BB->getModule ()).getValueInBlock (V, BB, CxtI);
1737- return toConstantRange ( Result, V->getType (), UndefAllowed);
1724+ return Result. asConstantRange ( V->getType (), UndefAllowed);
17381725}
17391726
17401727ConstantRange LazyValueInfo::getConstantRangeAtUse (const Use &U,
17411728 bool UndefAllowed) {
17421729 auto *Inst = cast<Instruction>(U.getUser ());
17431730 ValueLatticeElement Result =
17441731 getOrCreateImpl (Inst->getModule ()).getValueAtUse (U);
1745- return toConstantRange ( Result, U->getType (), UndefAllowed);
1732+ return Result. asConstantRange ( U->getType (), UndefAllowed);
17461733}
17471734
17481735// / Determine whether the specified value is known to be a
@@ -1772,7 +1759,7 @@ ConstantRange LazyValueInfo::getConstantRangeOnEdge(Value *V,
17721759 ValueLatticeElement Result =
17731760 getOrCreateImpl (M).getValueOnEdge (V, FromBB, ToBB, CxtI);
17741761 // TODO: Should undef be allowed here?
1775- return toConstantRange ( Result, V->getType (), /* UndefAllowed*/ true );
1762+ return Result. asConstantRange ( V->getType (), /* UndefAllowed*/ true );
17761763}
17771764
17781765static Constant *getPredicateResult (CmpInst::Predicate Pred, Constant *C,
0 commit comments