@@ -1775,70 +1775,66 @@ ConstantRange LazyValueInfo::getConstantRangeOnEdge(Value *V,
1775
1775
return toConstantRange (Result, V->getType (), /* UndefAllowed*/ true );
1776
1776
}
1777
1777
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) {
1781
1781
// 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);
1789
1784
1785
+ Type *ResTy = CmpInst::makeCmpResultType (C->getType ());
1790
1786
if (Val.isConstantRange ()) {
1791
1787
ConstantInt *CI = dyn_cast<ConstantInt>(C);
1792
- if (!CI) return LazyValueInfo::Unknown;
1788
+ if (!CI)
1789
+ return nullptr ;
1793
1790
1794
1791
const ConstantRange &CR = Val.getConstantRange ();
1795
1792
ConstantRange RHS (CI->getValue ());
1796
1793
if (CR.icmp (Pred, RHS))
1797
- return LazyValueInfo::True ;
1794
+ return ConstantInt::getTrue (ResTy) ;
1798
1795
if (CR.icmp (CmpInst::getInversePredicate (Pred), RHS))
1799
- return LazyValueInfo::False ;
1800
- return LazyValueInfo::Unknown ;
1796
+ return ConstantInt::getFalse (ResTy) ;
1797
+ return nullptr ;
1801
1798
}
1802
1799
1803
1800
if (Val.isNotConstant ()) {
1804
1801
// If this is an equality comparison, we can try to fold it knowing that
1805
1802
// "V != C1".
1806
1803
if (Pred == ICmpInst::ICMP_EQ) {
1807
1804
// !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);
1810
1807
if (Res && Res->isNullValue ())
1811
- return LazyValueInfo::False ;
1808
+ return ConstantInt::getFalse (ResTy) ;
1812
1809
} else if (Pred == ICmpInst::ICMP_NE) {
1813
1810
// !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);
1816
1813
if (Res && Res->isNullValue ())
1817
- return LazyValueInfo::True ;
1814
+ return ConstantInt::getTrue (ResTy) ;
1818
1815
}
1819
- return LazyValueInfo::Unknown ;
1816
+ return nullptr ;
1820
1817
}
1821
1818
1822
- return LazyValueInfo::Unknown ;
1819
+ return nullptr ;
1823
1820
}
1824
1821
1825
1822
// / Determine whether the specified value comparison with a constant is known to
1826
1823
// / 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) {
1831
1828
Module *M = FromBB->getModule ();
1832
1829
ValueLatticeElement Result =
1833
1830
getOrCreateImpl (M).getValueOnEdge (V, FromBB, ToBB, CxtI);
1834
1831
1835
1832
return getPredicateResult (Pred, C, Result, M->getDataLayout ());
1836
1833
}
1837
1834
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) {
1842
1838
// Is or is not NonNull are common predicates being queried. If
1843
1839
// isKnownNonZero can tell us the result of the predicate, we can
1844
1840
// return it quickly. But this is only a fastpath, and falling
@@ -1847,18 +1843,19 @@ LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(CmpInst::Predicate Pred,
1847
1843
const DataLayout &DL = M->getDataLayout ();
1848
1844
if (V->getType ()->isPointerTy () && C->isNullValue () &&
1849
1845
isKnownNonZero (V->stripPointerCastsSameRepresentation (), DL)) {
1846
+ Type *ResTy = CmpInst::makeCmpResultType (C->getType ());
1850
1847
if (Pred == ICmpInst::ICMP_EQ)
1851
- return LazyValueInfo::False ;
1848
+ return ConstantInt::getFalse (ResTy) ;
1852
1849
else if (Pred == ICmpInst::ICMP_NE)
1853
- return LazyValueInfo::True ;
1850
+ return ConstantInt::getTrue (ResTy) ;
1854
1851
}
1855
1852
1856
1853
auto &Impl = getOrCreateImpl (M);
1857
1854
ValueLatticeElement Result =
1858
1855
UseBlockValue ? Impl.getValueInBlock (V, CxtI->getParent (), CxtI)
1859
1856
: 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)
1862
1859
return Ret;
1863
1860
1864
1861
// 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,
1889
1886
// analysis below.
1890
1887
pred_iterator PI = pred_begin (BB), PE = pred_end (BB);
1891
1888
if (PI == PE)
1892
- return Unknown ;
1889
+ return nullptr ;
1893
1890
1894
1891
// If V is a PHI node in the same block as the context, we need to ask
1895
1892
// questions about the predicate as applied to the incoming value along
1896
1893
// each edge. This is useful for eliminating cases where the predicate is
1897
1894
// known along all incoming edges.
1898
1895
if (auto *PHI = dyn_cast<PHINode>(V))
1899
1896
if (PHI->getParent () == BB) {
1900
- Tristate Baseline = Unknown ;
1897
+ Constant * Baseline = nullptr ;
1901
1898
for (unsigned i = 0 , e = PHI->getNumIncomingValues (); i < e; i++) {
1902
1899
Value *Incoming = PHI->getIncomingValue (i);
1903
1900
BasicBlock *PredBB = PHI->getIncomingBlock (i);
1904
1901
// Note that PredBB may be BB itself.
1905
- Tristate Result =
1902
+ Constant * Result =
1906
1903
getPredicateOnEdge (Pred, Incoming, C, PredBB, BB, CxtI);
1907
1904
1908
1905
// Keep going as long as we've seen a consistent known result for
1909
1906
// all inputs.
1910
1907
Baseline = (i == 0 ) ? Result /* First iteration */
1911
1908
: (Baseline == Result ? Baseline
1912
- : Unknown ); /* All others */
1913
- if (Baseline == Unknown )
1909
+ : nullptr ); /* All others */
1910
+ if (! Baseline)
1914
1911
break ;
1915
1912
}
1916
- if (Baseline != Unknown )
1913
+ if (Baseline)
1917
1914
return Baseline;
1918
1915
}
1919
1916
@@ -1924,11 +1921,11 @@ LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(CmpInst::Predicate Pred,
1924
1921
// For predecessor edge, determine if the comparison is true or false
1925
1922
// on that edge. If they're all true or all false, we can conclude
1926
1923
// 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) {
1929
1926
// Check that all remaining incoming values match the first one.
1930
1927
while (++PI != PE) {
1931
- Tristate Ret = getPredicateOnEdge (Pred, V, C, *PI, BB, CxtI);
1928
+ Constant * Ret = getPredicateOnEdge (Pred, V, C, *PI, BB, CxtI);
1932
1929
if (Ret != Baseline)
1933
1930
break ;
1934
1931
}
@@ -1939,13 +1936,12 @@ LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(CmpInst::Predicate Pred,
1939
1936
}
1940
1937
}
1941
1938
1942
- return Unknown ;
1939
+ return nullptr ;
1943
1940
}
1944
1941
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) {
1949
1945
if (auto *C = dyn_cast<Constant>(RHS))
1950
1946
return getPredicateAt (Pred, LHS, C, CxtI, UseBlockValue);
1951
1947
if (auto *C = dyn_cast<Constant>(LHS))
@@ -1960,19 +1956,14 @@ LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(CmpInst::Predicate Pred,
1960
1956
ValueLatticeElement L =
1961
1957
getOrCreateImpl (M).getValueInBlock (LHS, CxtI->getParent (), CxtI);
1962
1958
if (L.isOverdefined ())
1963
- return LazyValueInfo::Unknown ;
1959
+ return nullptr ;
1964
1960
1965
1961
ValueLatticeElement R =
1966
1962
getOrCreateImpl (M).getValueInBlock (RHS, CxtI->getParent (), CxtI);
1967
1963
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 ());
1974
1965
}
1975
- return LazyValueInfo::Unknown ;
1966
+ return nullptr ;
1976
1967
}
1977
1968
1978
1969
void LazyValueInfo::threadEdge (BasicBlock *PredBB, BasicBlock *OldSucc,
0 commit comments