@@ -1775,70 +1775,66 @@ ConstantRange LazyValueInfo::getConstantRangeOnEdge(Value *V,
17751775 return toConstantRange (Result, V->getType (), /* UndefAllowed*/ true );
17761776}
17771777
1778- static LazyValueInfo::Tristate
1779- getPredicateResult (CmpInst::Predicate Pred, Constant *C ,
1780- const ValueLatticeElement &Val, const DataLayout &DL) {
1778+ static Constant * getPredicateResult (CmpInst::Predicate Pred, Constant *C,
1779+ const ValueLatticeElement &Val ,
1780+ const DataLayout &DL) {
17811781 // If we know the value is a constant, evaluate the conditional.
1782- Constant *Res = nullptr ;
1783- if (Val.isConstant ()) {
1784- Res = ConstantFoldCompareInstOperands (Pred, Val.getConstant (), C, DL);
1785- if (ConstantInt *ResCI = dyn_cast_or_null<ConstantInt>(Res))
1786- return ResCI->isZero () ? LazyValueInfo::False : LazyValueInfo::True;
1787- return LazyValueInfo::Unknown;
1788- }
1782+ if (Val.isConstant ())
1783+ return ConstantFoldCompareInstOperands (Pred, Val.getConstant (), C, DL);
17891784
1785+ Type *ResTy = CmpInst::makeCmpResultType (C->getType ());
17901786 if (Val.isConstantRange ()) {
17911787 ConstantInt *CI = dyn_cast<ConstantInt>(C);
1792- if (!CI) return LazyValueInfo::Unknown;
1788+ if (!CI)
1789+ return nullptr ;
17931790
17941791 const ConstantRange &CR = Val.getConstantRange ();
17951792 ConstantRange RHS (CI->getValue ());
17961793 if (CR.icmp (Pred, RHS))
1797- return LazyValueInfo::True ;
1794+ return ConstantInt::getTrue (ResTy) ;
17981795 if (CR.icmp (CmpInst::getInversePredicate (Pred), RHS))
1799- return LazyValueInfo::False ;
1800- return LazyValueInfo::Unknown ;
1796+ return ConstantInt::getFalse (ResTy) ;
1797+ return nullptr ;
18011798 }
18021799
18031800 if (Val.isNotConstant ()) {
18041801 // If this is an equality comparison, we can try to fold it knowing that
18051802 // "V != C1".
18061803 if (Pred == ICmpInst::ICMP_EQ) {
18071804 // !C1 == C -> false iff C1 == C.
1808- Res = ConstantFoldCompareInstOperands (ICmpInst::ICMP_NE,
1809- Val.getNotConstant (), C, DL);
1805+ Constant * Res = ConstantFoldCompareInstOperands (
1806+ ICmpInst::ICMP_NE, Val.getNotConstant (), C, DL);
18101807 if (Res && Res->isNullValue ())
1811- return LazyValueInfo::False ;
1808+ return ConstantInt::getFalse (ResTy) ;
18121809 } else if (Pred == ICmpInst::ICMP_NE) {
18131810 // !C1 != C -> true iff C1 == C.
1814- Res = ConstantFoldCompareInstOperands (ICmpInst::ICMP_NE,
1815- Val.getNotConstant (), C, DL);
1811+ Constant * Res = ConstantFoldCompareInstOperands (
1812+ ICmpInst::ICMP_NE, Val.getNotConstant (), C, DL);
18161813 if (Res && Res->isNullValue ())
1817- return LazyValueInfo::True ;
1814+ return ConstantInt::getTrue (ResTy) ;
18181815 }
1819- return LazyValueInfo::Unknown ;
1816+ return nullptr ;
18201817 }
18211818
1822- return LazyValueInfo::Unknown ;
1819+ return nullptr ;
18231820}
18241821
18251822// / Determine whether the specified value comparison with a constant is known to
18261823// / be true or false on the specified CFG edge. Pred is a CmpInst predicate.
1827- LazyValueInfo::Tristate
1828- LazyValueInfo::getPredicateOnEdge (CmpInst::Predicate Pred, Value *V ,
1829- Constant *C, BasicBlock *FromBB ,
1830- BasicBlock *ToBB, Instruction *CxtI) {
1824+ Constant * LazyValueInfo::getPredicateOnEdge (CmpInst::Predicate Pred, Value *V,
1825+ Constant *C, BasicBlock *FromBB ,
1826+ BasicBlock *ToBB ,
1827+ Instruction *CxtI) {
18311828 Module *M = FromBB->getModule ();
18321829 ValueLatticeElement Result =
18331830 getOrCreateImpl (M).getValueOnEdge (V, FromBB, ToBB, CxtI);
18341831
18351832 return getPredicateResult (Pred, C, Result, M->getDataLayout ());
18361833}
18371834
1838- LazyValueInfo::Tristate LazyValueInfo::getPredicateAt (CmpInst::Predicate Pred,
1839- Value *V, Constant *C,
1840- Instruction *CxtI,
1841- bool UseBlockValue) {
1835+ Constant *LazyValueInfo::getPredicateAt (CmpInst::Predicate Pred, Value *V,
1836+ Constant *C, Instruction *CxtI,
1837+ bool UseBlockValue) {
18421838 // Is or is not NonNull are common predicates being queried. If
18431839 // isKnownNonZero can tell us the result of the predicate, we can
18441840 // return it quickly. But this is only a fastpath, and falling
@@ -1847,18 +1843,19 @@ LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(CmpInst::Predicate Pred,
18471843 const DataLayout &DL = M->getDataLayout ();
18481844 if (V->getType ()->isPointerTy () && C->isNullValue () &&
18491845 isKnownNonZero (V->stripPointerCastsSameRepresentation (), DL)) {
1846+ Type *ResTy = CmpInst::makeCmpResultType (C->getType ());
18501847 if (Pred == ICmpInst::ICMP_EQ)
1851- return LazyValueInfo::False ;
1848+ return ConstantInt::getFalse (ResTy) ;
18521849 else if (Pred == ICmpInst::ICMP_NE)
1853- return LazyValueInfo::True ;
1850+ return ConstantInt::getTrue (ResTy) ;
18541851 }
18551852
18561853 auto &Impl = getOrCreateImpl (M);
18571854 ValueLatticeElement Result =
18581855 UseBlockValue ? Impl.getValueInBlock (V, CxtI->getParent (), CxtI)
18591856 : Impl.getValueAt (V, CxtI);
1860- Tristate Ret = getPredicateResult (Pred, C, Result, DL);
1861- if (Ret != Unknown )
1857+ Constant * Ret = getPredicateResult (Pred, C, Result, DL);
1858+ if (Ret)
18621859 return Ret;
18631860
18641861 // Note: The following bit of code is somewhat distinct from the rest of LVI;
@@ -1889,31 +1886,31 @@ LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(CmpInst::Predicate Pred,
18891886 // analysis below.
18901887 pred_iterator PI = pred_begin (BB), PE = pred_end (BB);
18911888 if (PI == PE)
1892- return Unknown ;
1889+ return nullptr ;
18931890
18941891 // If V is a PHI node in the same block as the context, we need to ask
18951892 // questions about the predicate as applied to the incoming value along
18961893 // each edge. This is useful for eliminating cases where the predicate is
18971894 // known along all incoming edges.
18981895 if (auto *PHI = dyn_cast<PHINode>(V))
18991896 if (PHI->getParent () == BB) {
1900- Tristate Baseline = Unknown ;
1897+ Constant * Baseline = nullptr ;
19011898 for (unsigned i = 0 , e = PHI->getNumIncomingValues (); i < e; i++) {
19021899 Value *Incoming = PHI->getIncomingValue (i);
19031900 BasicBlock *PredBB = PHI->getIncomingBlock (i);
19041901 // Note that PredBB may be BB itself.
1905- Tristate Result =
1902+ Constant * Result =
19061903 getPredicateOnEdge (Pred, Incoming, C, PredBB, BB, CxtI);
19071904
19081905 // Keep going as long as we've seen a consistent known result for
19091906 // all inputs.
19101907 Baseline = (i == 0 ) ? Result /* First iteration */
19111908 : (Baseline == Result ? Baseline
1912- : Unknown ); /* All others */
1913- if (Baseline == Unknown )
1909+ : nullptr ); /* All others */
1910+ if (! Baseline)
19141911 break ;
19151912 }
1916- if (Baseline != Unknown )
1913+ if (Baseline)
19171914 return Baseline;
19181915 }
19191916
@@ -1924,11 +1921,11 @@ LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(CmpInst::Predicate Pred,
19241921 // For predecessor edge, determine if the comparison is true or false
19251922 // on that edge. If they're all true or all false, we can conclude
19261923 // the value of the comparison in this block.
1927- Tristate Baseline = getPredicateOnEdge (Pred, V, C, *PI, BB, CxtI);
1928- if (Baseline != Unknown ) {
1924+ Constant * Baseline = getPredicateOnEdge (Pred, V, C, *PI, BB, CxtI);
1925+ if (Baseline) {
19291926 // Check that all remaining incoming values match the first one.
19301927 while (++PI != PE) {
1931- Tristate Ret = getPredicateOnEdge (Pred, V, C, *PI, BB, CxtI);
1928+ Constant * Ret = getPredicateOnEdge (Pred, V, C, *PI, BB, CxtI);
19321929 if (Ret != Baseline)
19331930 break ;
19341931 }
@@ -1939,13 +1936,12 @@ LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(CmpInst::Predicate Pred,
19391936 }
19401937 }
19411938
1942- return Unknown ;
1939+ return nullptr ;
19431940}
19441941
1945- LazyValueInfo::Tristate LazyValueInfo::getPredicateAt (CmpInst::Predicate Pred,
1946- Value *LHS, Value *RHS,
1947- Instruction *CxtI,
1948- bool UseBlockValue) {
1942+ Constant *LazyValueInfo::getPredicateAt (CmpInst::Predicate Pred, Value *LHS,
1943+ Value *RHS, Instruction *CxtI,
1944+ bool UseBlockValue) {
19491945 if (auto *C = dyn_cast<Constant>(RHS))
19501946 return getPredicateAt (Pred, LHS, C, CxtI, UseBlockValue);
19511947 if (auto *C = dyn_cast<Constant>(LHS))
@@ -1960,19 +1956,14 @@ LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(CmpInst::Predicate Pred,
19601956 ValueLatticeElement L =
19611957 getOrCreateImpl (M).getValueInBlock (LHS, CxtI->getParent (), CxtI);
19621958 if (L.isOverdefined ())
1963- return LazyValueInfo::Unknown ;
1959+ return nullptr ;
19641960
19651961 ValueLatticeElement R =
19661962 getOrCreateImpl (M).getValueInBlock (RHS, CxtI->getParent (), CxtI);
19671963 Type *Ty = CmpInst::makeCmpResultType (LHS->getType ());
1968- if (Constant *Res = L.getCompare (Pred, Ty, R, M->getDataLayout ())) {
1969- if (Res->isNullValue ())
1970- return LazyValueInfo::False;
1971- if (Res->isOneValue ())
1972- return LazyValueInfo::True;
1973- }
1964+ return L.getCompare (Pred, Ty, R, M->getDataLayout ());
19741965 }
1975- return LazyValueInfo::Unknown ;
1966+ return nullptr ;
19761967}
19771968
19781969void LazyValueInfo::threadEdge (BasicBlock *PredBB, BasicBlock *OldSucc,
0 commit comments