@@ -1777,6 +1777,25 @@ void ReinitIntBoolOpDsc(IntBoolOpDsc* intBoolOpDsc)
1777
1777
intBoolOpDsc->lclVarArrLength = 0 ;
1778
1778
}
1779
1779
1780
+ // -----------------------------------------------------------------------------
1781
+ // GetNextOrOp: Function used for searching the next GT_OR node
1782
+ //
1783
+ // Arguments:
1784
+ // b3 the tree to inspect
1785
+ //
1786
+ // Return:
1787
+ // On success, return the next GT_OR node or nullptr if it fails
1788
+ //
1789
+ GenTree* GetNextOrOp (GenTree* b4)
1790
+ {
1791
+ while (b4 != nullptr && !b4->OperIs (GT_OR))
1792
+ {
1793
+ b4 = b4->gtPrev ;
1794
+ }
1795
+
1796
+ return b4;
1797
+ }
1798
+
1780
1799
// -----------------------------------------------------------------------------
1781
1800
// GetNextIntBoolOpToOptimize: Function used for searching constant INT OR operation that can be folded
1782
1801
//
@@ -1802,25 +1821,20 @@ IntBoolOpDsc* GetNextIntBoolOpToOptimize(GenTree* b3)
1802
1821
intBoolOpDsc->lclVarArrLength = 0 ;
1803
1822
intBoolOpDsc->start = nullptr ;
1804
1823
intBoolOpDsc->end = nullptr ;
1805
- int orOpCount = 1 ;
1824
+ int orOpCount = 2 ;
1806
1825
1807
- GenTree* b4 = b3->gtPrev ;
1826
+ GenTree* b4 = GetNextOrOp ( b3->gtPrev ) ;
1808
1827
1809
- while (b4 != nullptr && !b4-> OperIs (GT_OR) )
1828
+ if (b4 != nullptr )
1810
1829
{
1811
- b4 = b4->gtPrev ;
1830
+ intBoolOpDsc->start = b4->gtNext ;
1831
+ b4 = b4->gtPrev ;
1812
1832
}
1813
1833
1814
1834
while (b4 != nullptr )
1815
1835
{
1816
1836
if (!b4->OperIs (GT_OR, GT_LCL_VAR, GT_CNS_INT) || !b4->TypeIs (TYP_INT))
1817
1837
{
1818
- if (intBoolOpDsc->start == nullptr )
1819
- {
1820
- b4 = b4->gtPrev ;
1821
- continue ;
1822
- }
1823
-
1824
1838
if (intBoolOpDsc->ctsArrayLength >= 2 && intBoolOpDsc->lclVarArrLength >= 2 )
1825
1839
{
1826
1840
intBoolOpDsc->end = b4;
@@ -1829,98 +1843,92 @@ IntBoolOpDsc* GetNextIntBoolOpToOptimize(GenTree* b3)
1829
1843
else
1830
1844
{
1831
1845
ReinitIntBoolOpDsc (intBoolOpDsc);
1832
- b4 = b4->gtPrev ;
1833
- orOpCount = 0 ;
1834
- continue ;
1835
- }
1836
- }
1846
+ b4 = GetNextOrOp (b4);
1837
1847
1838
- if (intBoolOpDsc->start == nullptr )
1839
- {
1840
- intBoolOpDsc->start = b4->gtNext ;
1848
+ if (b4 != nullptr )
1849
+ {
1850
+ orOpCount = 2 ;
1851
+ intBoolOpDsc->start = b4->gtNext ;
1852
+ }
1853
+ else
1854
+ {
1855
+ break ;
1856
+ }
1857
+ }
1841
1858
}
1842
1859
1843
- switch (b4-> gtOper )
1860
+ if (orOpCount <= 0 )
1844
1861
{
1845
- case GT_LCL_VAR:
1862
+ if (intBoolOpDsc-> ctsArrayLength >= 2 && intBoolOpDsc-> lclVarArrLength >= 2 )
1846
1863
{
1847
- if (orOpCount <= 0 )
1848
- {
1849
- if (intBoolOpDsc->ctsArrayLength >= 2 && intBoolOpDsc->lclVarArrLength >= 2 )
1850
- {
1851
- intBoolOpDsc->end = b4;
1852
- return intBoolOpDsc;
1853
- }
1864
+ intBoolOpDsc->end = b4;
1865
+ return intBoolOpDsc;
1866
+ }
1854
1867
1855
- ReinitIntBoolOpDsc (intBoolOpDsc);
1856
- break ;
1857
- }
1868
+ ReinitIntBoolOpDsc (intBoolOpDsc);
1858
1869
1859
- intBoolOpDsc->lclVarArrLength ++;
1860
- if (intBoolOpDsc->lclVarArr == nullptr )
1861
- {
1862
- intBoolOpDsc->lclVarArr =
1863
- reinterpret_cast <GenTree**>(malloc (sizeof (GenTree*) * intBoolOpDsc->lclVarArrLength ));
1864
- }
1865
- else
1866
- {
1867
- intBoolOpDsc->lclVarArr = reinterpret_cast <GenTree**>(
1868
- realloc (intBoolOpDsc->lclVarArr , sizeof (GenTree*) * intBoolOpDsc->lclVarArrLength ));
1869
- }
1870
+ if (!b4->OperIs (GT_OR))
1871
+ {
1872
+ b4 = GetNextOrOp (b4);
1873
+ }
1870
1874
1871
- intBoolOpDsc->lclVarArr [intBoolOpDsc->lclVarArrLength - 1 ] = b4;
1872
- orOpCount--;
1875
+ if (b4 != nullptr )
1876
+ {
1877
+ orOpCount = 2 ;
1878
+ intBoolOpDsc->start = b4->gtNext ;
1879
+ }
1880
+ else
1881
+ {
1873
1882
break ;
1874
1883
}
1875
- case GT_CNS_INT:
1884
+ }
1885
+ else
1886
+ {
1887
+ switch (b4->gtOper )
1876
1888
{
1877
- if (orOpCount <= 0 )
1889
+ case GT_LCL_VAR:
1878
1890
{
1879
- if (intBoolOpDsc->ctsArrayLength >= 2 && intBoolOpDsc->lclVarArrLength >= 2 )
1891
+ intBoolOpDsc->lclVarArrLength ++;
1892
+ if (intBoolOpDsc->lclVarArr == nullptr )
1880
1893
{
1881
- intBoolOpDsc->end = b4;
1882
- return intBoolOpDsc;
1894
+ intBoolOpDsc->lclVarArr =
1895
+ reinterpret_cast <GenTree**>(malloc (sizeof (GenTree*) * intBoolOpDsc->lclVarArrLength ));
1896
+ }
1897
+ else
1898
+ {
1899
+ intBoolOpDsc->lclVarArr = reinterpret_cast <GenTree**>(
1900
+ realloc (intBoolOpDsc->lclVarArr , sizeof (GenTree*) * intBoolOpDsc->lclVarArrLength ));
1883
1901
}
1884
1902
1885
- ReinitIntBoolOpDsc (intBoolOpDsc);
1903
+ intBoolOpDsc->lclVarArr [intBoolOpDsc->lclVarArrLength - 1 ] = b4;
1904
+ orOpCount--;
1886
1905
break ;
1887
1906
}
1888
-
1889
- intBoolOpDsc->ctsArrayLength ++;
1890
- if (intBoolOpDsc->ctsArray == nullptr )
1891
- {
1892
- intBoolOpDsc->ctsArray =
1893
- reinterpret_cast <ssize_t *>(malloc (sizeof (ssize_t ) * intBoolOpDsc->ctsArrayLength ));
1894
- }
1895
- else
1896
- {
1897
- intBoolOpDsc->ctsArray = reinterpret_cast <ssize_t *>(
1898
- realloc (intBoolOpDsc->ctsArray , sizeof (ssize_t ) * intBoolOpDsc->ctsArrayLength ));
1899
- }
1900
- ssize_t constant = b4->AsIntConCommon ()->IconValue ();
1901
- intBoolOpDsc->ctsArray [intBoolOpDsc->ctsArrayLength - 1 ] = constant;
1902
- orOpCount--;
1903
- break ;
1904
- }
1905
- case GT_OR:
1906
- if (orOpCount <= 0 )
1907
+ case GT_CNS_INT:
1907
1908
{
1908
- if (intBoolOpDsc->ctsArrayLength >= 2 && intBoolOpDsc->lclVarArrLength >= 2 )
1909
+ intBoolOpDsc->ctsArrayLength ++;
1910
+ if (intBoolOpDsc->ctsArray == nullptr )
1909
1911
{
1910
- intBoolOpDsc->end = b4;
1911
- return intBoolOpDsc;
1912
+ intBoolOpDsc->ctsArray =
1913
+ reinterpret_cast < ssize_t *>( malloc ( sizeof ( ssize_t ) * intBoolOpDsc-> ctsArrayLength )) ;
1912
1914
}
1913
-
1914
- ReinitIntBoolOpDsc (intBoolOpDsc);
1915
- orOpCount = 1 ;
1916
- intBoolOpDsc->start = b4->gtNext ;
1915
+ else
1916
+ {
1917
+ intBoolOpDsc->ctsArray = reinterpret_cast <ssize_t *>(
1918
+ realloc (intBoolOpDsc->ctsArray , sizeof (ssize_t ) * intBoolOpDsc->ctsArrayLength ));
1919
+ }
1920
+ ssize_t constant = b4->AsIntConCommon ()->IconValue ();
1921
+ intBoolOpDsc->ctsArray [intBoolOpDsc->ctsArrayLength - 1 ] = constant;
1922
+ orOpCount--;
1923
+ break ;
1924
+ }
1925
+ case GT_OR:
1926
+ orOpCount++;
1927
+ break ;
1928
+ default :
1929
+ {
1930
+ break ;
1917
1931
}
1918
-
1919
- orOpCount++;
1920
- break ;
1921
- default :
1922
- {
1923
- break ;
1924
1932
}
1925
1933
}
1926
1934
0 commit comments