@@ -801,12 +801,15 @@ void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
801
801
}
802
802
}
803
803
804
- static ConstantRange getConstantRangeOrFull (const ValueLatticeElement &Val,
805
- Type *Ty ) {
804
+ static ConstantRange toConstantRange (const ValueLatticeElement &Val,
805
+ Type *Ty, bool UndefAllowed = false ) {
806
806
assert (Ty->isIntOrIntVectorTy () && " Must be integer type" );
807
- if (Val.isConstantRange (/* UndefAllowed*/ false ))
807
+ if (Val.isConstantRange (UndefAllowed))
808
808
return Val.getConstantRange ();
809
- return ConstantRange::getFull (Ty->getScalarSizeInBits ());
809
+ unsigned BW = Ty->getScalarSizeInBits ();
810
+ if (Val.isUnknown ())
811
+ return ConstantRange::getEmpty (BW);
812
+ return ConstantRange::getFull (BW);
810
813
}
811
814
812
815
std::optional<ValueLatticeElement>
@@ -825,10 +828,8 @@ LazyValueInfoImpl::solveBlockValueSelect(SelectInst *SI, BasicBlock *BB) {
825
828
ValueLatticeElement &FalseVal = *OptFalseVal;
826
829
827
830
if (TrueVal.isConstantRange () || FalseVal.isConstantRange ()) {
828
- const ConstantRange &TrueCR =
829
- getConstantRangeOrFull (TrueVal, SI->getType ());
830
- const ConstantRange &FalseCR =
831
- getConstantRangeOrFull (FalseVal, SI->getType ());
831
+ const ConstantRange &TrueCR = toConstantRange (TrueVal, SI->getType ());
832
+ const ConstantRange &FalseCR = toConstantRange (FalseVal, SI->getType ());
832
833
Value *LHS = nullptr ;
833
834
Value *RHS = nullptr ;
834
835
SelectPatternResult SPR = matchSelectPattern (SI, LHS, RHS);
@@ -899,7 +900,7 @@ LazyValueInfoImpl::getRangeFor(Value *V, Instruction *CxtI, BasicBlock *BB) {
899
900
std::optional<ValueLatticeElement> OptVal = getBlockValue (V, BB, CxtI);
900
901
if (!OptVal)
901
902
return std::nullopt;
902
- return getConstantRangeOrFull (*OptVal, V->getType ());
903
+ return toConstantRange (*OptVal, V->getType ());
903
904
}
904
905
905
906
std::optional<ValueLatticeElement>
@@ -1624,19 +1625,10 @@ Constant *LazyValueInfo::getConstant(Value *V, Instruction *CxtI) {
1624
1625
ConstantRange LazyValueInfo::getConstantRange (Value *V, Instruction *CxtI,
1625
1626
bool UndefAllowed) {
1626
1627
assert (V->getType ()->isIntegerTy ());
1627
- unsigned Width = V->getType ()->getIntegerBitWidth ();
1628
1628
BasicBlock *BB = CxtI->getParent ();
1629
1629
ValueLatticeElement Result =
1630
1630
getOrCreateImpl (BB->getModule ()).getValueInBlock (V, BB, CxtI);
1631
- if (Result.isUnknown ())
1632
- return ConstantRange::getEmpty (Width);
1633
- if (Result.isConstantRange (UndefAllowed))
1634
- return Result.getConstantRange (UndefAllowed);
1635
- // We represent ConstantInt constants as constant ranges but other kinds
1636
- // of integer constants, i.e. ConstantExpr will be tagged as constants
1637
- assert (!(Result.isConstant () && isa<ConstantInt>(Result.getConstant ())) &&
1638
- " ConstantInt value must be represented as constantrange" );
1639
- return ConstantRange::getFull (Width);
1631
+ return toConstantRange (Result, V->getType (), UndefAllowed);
1640
1632
}
1641
1633
1642
1634
ConstantRange LazyValueInfo::getConstantRangeAtUse (const Use &U,
@@ -1709,20 +1701,11 @@ ConstantRange LazyValueInfo::getConstantRangeOnEdge(Value *V,
1709
1701
BasicBlock *FromBB,
1710
1702
BasicBlock *ToBB,
1711
1703
Instruction *CxtI) {
1712
- unsigned Width = V->getType ()->getIntegerBitWidth ();
1713
1704
Module *M = FromBB->getModule ();
1714
1705
ValueLatticeElement Result =
1715
1706
getOrCreateImpl (M).getValueOnEdge (V, FromBB, ToBB, CxtI);
1716
-
1717
- if (Result.isUnknown ())
1718
- return ConstantRange::getEmpty (Width);
1719
- if (Result.isConstantRange ())
1720
- return Result.getConstantRange ();
1721
- // We represent ConstantInt constants as constant ranges but other kinds
1722
- // of integer constants, i.e. ConstantExpr will be tagged as constants
1723
- assert (!(Result.isConstant () && isa<ConstantInt>(Result.getConstant ())) &&
1724
- " ConstantInt value must be represented as constantrange" );
1725
- return ConstantRange::getFull (Width);
1707
+ // TODO: Should undef be allowed here?
1708
+ return toConstantRange (Result, V->getType (), /* UndefAllowed*/ true );
1726
1709
}
1727
1710
1728
1711
static LazyValueInfo::Tristate
0 commit comments