<HTML><HEAD><TITLE>Samsung Enterprise Portal mySingle</TITLE>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<STYLE id=mysingle_style type=text/css>P {
        MARGIN-TOP: 5px; FONT-FAMILY: Arial, arial; MARGIN-BOTTOM: 5px; FONT-SIZE: 9pt
}
TD {
        MARGIN-TOP: 5px; FONT-FAMILY: Arial, arial; MARGIN-BOTTOM: 5px; FONT-SIZE: 9pt
}
LI {
        MARGIN-TOP: 5px; FONT-FAMILY: Arial, arial; MARGIN-BOTTOM: 5px; FONT-SIZE: 9pt
}
BODY {
        LINE-HEIGHT: 1.4; MARGIN: 10px; FONT-FAMILY: Arial, arial; FONT-SIZE: 9pt
}
</STYLE>

<META name=GENERATOR content=ActiveSquare></HEAD>
<BODY>
<P>Hi Rafael,</P>
<P> </P>
<P>Got the point. I Agree with your patch.</P>
<P> </P>
<P>I updated my patch with the test cases. Can you please check if this is correct? </P>
<P>If it looks good to you, can you please commit it on my behalf?</P>
<P> </P>
<P>My patch also handles the case, where <SPAN style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"><SPAN class=Apple-converted-space> one of the operand </SPAN>has only 1 bit that is not known to</SPAN><BR style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"><SPAN style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px">be zero, but it is also not know to be one.</SPAN></P>
<P><SPAN style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px">((~RHSKnownZero).countpopulation == 1) will be able to determine if only one of the bit is unkown (it may be 1 or 0).</SPAN></P>
<P><SPAN style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"></SPAN> </P>
<P><SPAN style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px">As far as the test case :</SPAN></P>
<P><SPAN style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"><SPAN style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"><EM></EM></SPAN></SPAN> </P>
<P><SPAN style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"><SPAN style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"><EM>define i32 @foo(i32 %x, i32 %y) {</EM></SPAN><EM><BR style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"></EM><SPAN style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"><EM>  %v1 = and i32 %y, 1</EM></SPAN><EM><BR style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"></EM><SPAN style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"><EM>  %v2 = add i32 %x, %v1</EM></SPAN><EM><BR style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"></EM><SPAN style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"><EM>  ret i32 %v2</EM></SPAN><EM><BR style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"></EM><SPAN style="TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 13px arial, sans-serif; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(34,34,34); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"><EM>}</EM></SPAN></SPAN></P>
<P> </P>
<P>We know that only one of the bit is unknown of one of the operand, it may be 1 or 0.</P>
<P>But for the other operand, we do not know if it has 0 at any higher bit position. Hence we do not add 'nsw' in this case.</P>
<P> </P>
<P>Added this test case as well + test case to handle sext  i1(bitwidth = 1).</P>
<P> </P>
<P>Awaiting for your review.</P>
<P> </P>
<P>Thanks,</P>
<P>Suyog Sarda  </P>
<P> </P>
<P>------- <B>Original Message</B> -------</P>
<P><B>Sender</B> : Rafael Espíndola<rafael.espindola@gmail.com></P>
<P><B>Date</B> : Jun 03, 2014 06:56 (GMT+09:00)</P>
<P><B>Title</B> : Re: Re: [llvm] r209746 - InstCombine: Improvement to check if signed addition overflows.</P>
<P> </P>> I am afraid if this is correct. Its adding 'nsw' to all additions, even<BR>> where it is sure not to add 'nsw'.<BR>><BR>> ex:-<BR>><BR>> int foo(short x){<BR>> short v =  (x & ~4) ;<BR>> int u = (int)v + 8;<BR>> return u;<BR>> }<BR>><BR>> In this example we cannot determine if the addition will overflow of not,<BR>> because, one of the operand (x & ~4) has 0 bit at position 2 from LSB (LSB<BR>> position considered 0) while other operand 8 has 1 bit at position 3, which<BR>> is at higher significant position than position of 0. In this case its<BR>> giving IR as 'add nsw' which it should not.<BR><BR>Sorry, I got confused, but the code is actually correct.<BR><BR>In the above example we know that (int)v will be of the form 00... or<BR>11.... since it is an sext. Now, it is being added to 8, so lets<BR>consider both cases<BR><BR>00...  + 8 -> A carry can change the second 0, but not the sign bit.<BR><BR>11... + 8 -> A negative and a positive number are being added, no overflow.<BR><BR>Cheers,<BR>Rafael<BR>
<P> </P>
<P> </P><!--SP:suyog.sarda--><!--suyog.sarda:EP-->
<P> </P>
<TABLE id=confidentialsignimg>
<TBODY>
<TR>
<TD NAMO_LOCK>
<P><IMG border=0 src="cid:BEI0XT4NZ5JE@namo.co.kr" width=520></P></TD></TR></TBODY></TABLE></BODY></HTML><img src='http://ext.samsung.net/mailcheck/SeenTimeChecker?do=657c22a16bd00bda3a924cca373ece3a642a6f853d654fd903d6c441441d91b5b5b181570026814a8769d93e1d9e9a7cddaee51834417892db9fdddda33e82cbe4a391424e62fcf6cf878f9a26ce15a0' border=0 width=0 height=0 style='display:none'>