<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;
        font-weight:normal;
        font-style:normal;
        text-decoration:none none;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Hi,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I have a question about some code in ScalarEvolution.cpp, in the function HowManyLessThans.  Specifically, this function returns CouldNotCompute if the iteration step is greater than one even when the NoWrap flags are set (if the step goes past the limit and wraps).    Here’s the comment:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>   } else if (isKnownPositive(Step)) {<o:p></o:p></p><p class=MsoNormal>      // Test whether a positive iteration can step past the limit<o:p></o:p></p><p class=MsoNormal>      // value and past the maximum value for its type in a single step.<o:p></o:p></p><p class=MsoNormal>      // Note that it's not sufficient to check NoWrap here, because even<o:p></o:p></p><p class=MsoNormal>      // though the value after a wrap is undefined, it's not undefined<o:p></o:p></p><p class=MsoNormal>      // behavior, so if wrap does occur, the loop could either terminate or<o:p></o:p></p><p class=MsoNormal>      // loop infinitely, but in either case, the loop is guaranteed to<o:p></o:p></p><p class=MsoNormal>      // iterate at least until the iteration where the wrapping occurs.<o:p></o:p></p><p class=MsoNormal>      <o:p></o:p></p><p class=MsoNormal>I have no doubt that there is a good reason for this code to work this way (there is a specific check in trip-count9.ll).  I’m just trying to understand it better.  I’m assuming that when the previous version of this code checked the NoWrap flag, that it caused a problem with some optimization pass?  If so, does anyone recall the pass.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I’m also curious if the –f[no]-strict-overflow flag has any impact on the assumptions?  Or, could the function check NoWrap for the unsigned case only?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The motivating example for this question occurs because we’re not unrolling loops with a run-time trip count when the loop induction variable is a pointer and the loop end check is another pointer.  For example,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>  void ex( int n, int* a, int* c ) {<o:p></o:p></p><p class=MsoNormal>    int b  = 1; int *ae = a + n;<o:p></o:p></p><p class=MsoNormal>    while ( a < ae) {<o:p></o:p></p><p class=MsoNormal>      c ++; b += *c; *a++ = b;<o:p></o:p></p><p class=MsoNormal>    }<o:p></o:p></p><p class=MsoNormal>  }<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thanks,<o:p></o:p></p><p class=MsoNormal>Brendon<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-size:10.5pt;font-family:Consolas'>--<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.5pt;font-family:Consolas'>Qualcomm Innovation Center, Inc is a member of Code Aurora Forum, hosted by The Linux Foundation<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>