@@ -1777,6 +1777,25 @@ void ReinitIntBoolOpDsc(IntBoolOpDsc* intBoolOpDsc)
17771777 intBoolOpDsc->lclVarArrLength = 0 ;
17781778}
17791779
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+
17801799// -----------------------------------------------------------------------------
17811800// GetNextIntBoolOpToOptimize: Function used for searching constant INT OR operation that can be folded
17821801//
@@ -1802,25 +1821,20 @@ IntBoolOpDsc* GetNextIntBoolOpToOptimize(GenTree* b3)
18021821 intBoolOpDsc->lclVarArrLength = 0 ;
18031822 intBoolOpDsc->start = nullptr ;
18041823 intBoolOpDsc->end = nullptr ;
1805- int orOpCount = 1 ;
1824+ int orOpCount = 2 ;
18061825
1807- GenTree* b4 = b3->gtPrev ;
1826+ GenTree* b4 = GetNextOrOp ( b3->gtPrev ) ;
18081827
1809- while (b4 != nullptr && !b4-> OperIs (GT_OR) )
1828+ if (b4 != nullptr )
18101829 {
1811- b4 = b4->gtPrev ;
1830+ intBoolOpDsc->start = b4->gtNext ;
1831+ b4 = b4->gtPrev ;
18121832 }
18131833
18141834 while (b4 != nullptr )
18151835 {
18161836 if (!b4->OperIs (GT_OR, GT_LCL_VAR, GT_CNS_INT) || !b4->TypeIs (TYP_INT))
18171837 {
1818- if (intBoolOpDsc->start == nullptr )
1819- {
1820- b4 = b4->gtPrev ;
1821- continue ;
1822- }
1823-
18241838 if (intBoolOpDsc->ctsArrayLength >= 2 && intBoolOpDsc->lclVarArrLength >= 2 )
18251839 {
18261840 intBoolOpDsc->end = b4;
@@ -1829,98 +1843,92 @@ IntBoolOpDsc* GetNextIntBoolOpToOptimize(GenTree* b3)
18291843 else
18301844 {
18311845 ReinitIntBoolOpDsc (intBoolOpDsc);
1832- b4 = b4->gtPrev ;
1833- orOpCount = 0 ;
1834- continue ;
1835- }
1836- }
1846+ b4 = GetNextOrOp (b4);
18371847
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+ }
18411858 }
18421859
1843- switch (b4-> gtOper )
1860+ if (orOpCount <= 0 )
18441861 {
1845- case GT_LCL_VAR:
1862+ if (intBoolOpDsc-> ctsArrayLength >= 2 && intBoolOpDsc-> lclVarArrLength >= 2 )
18461863 {
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+ }
18541867
1855- ReinitIntBoolOpDsc (intBoolOpDsc);
1856- break ;
1857- }
1868+ ReinitIntBoolOpDsc (intBoolOpDsc);
18581869
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+ }
18701874
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+ {
18731882 break ;
18741883 }
1875- case GT_CNS_INT:
1884+ }
1885+ else
1886+ {
1887+ switch (b4->gtOper )
18761888 {
1877- if (orOpCount <= 0 )
1889+ case GT_LCL_VAR:
18781890 {
1879- if (intBoolOpDsc->ctsArrayLength >= 2 && intBoolOpDsc->lclVarArrLength >= 2 )
1891+ intBoolOpDsc->lclVarArrLength ++;
1892+ if (intBoolOpDsc->lclVarArr == nullptr )
18801893 {
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 ));
18831901 }
18841902
1885- ReinitIntBoolOpDsc (intBoolOpDsc);
1903+ intBoolOpDsc->lclVarArr [intBoolOpDsc->lclVarArrLength - 1 ] = b4;
1904+ orOpCount--;
18861905 break ;
18871906 }
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:
19071908 {
1908- if (intBoolOpDsc->ctsArrayLength >= 2 && intBoolOpDsc->lclVarArrLength >= 2 )
1909+ intBoolOpDsc->ctsArrayLength ++;
1910+ if (intBoolOpDsc->ctsArray == nullptr )
19091911 {
1910- intBoolOpDsc->end = b4;
1911- return intBoolOpDsc;
1912+ intBoolOpDsc->ctsArray =
1913+ reinterpret_cast < ssize_t *>( malloc ( sizeof ( ssize_t ) * intBoolOpDsc-> ctsArrayLength )) ;
19121914 }
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 ;
19171931 }
1918-
1919- orOpCount++;
1920- break ;
1921- default :
1922- {
1923- break ;
19241932 }
19251933 }
19261934
0 commit comments