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

<META name=GENERATOR content=ActiveSquare></HEAD>
<BODY>
<P>Hi Sean,</P>
<P>Thanks for the review.</P>
<P>I think I get how that could be confusing.</P>
<P> </P>
<P>Actually, the expression </P>
<P>icmp eq/ne (shl Const2, A), Const1</P>
<P> </P>
<P>can be converted to</P>
<P>icmp eq/ne A, (TrailingZeros(Const1) - TrailingZeros(Const2))</P>
<P> </P>
<P>only when Const2 << (TrailingZeros(Const1) - TrailingZeros(Const2)) is equal to Const 1</P>
<P> </P>
<P>if Const2  left-shifted by the amount of difference between the number of trailing zeros between const1 and const2, is not equal to Const1, </P>
<P>then no amount of left shifting of Const2 can make it equal to Const1. For those cases, simply returning false (or true, depending on the operator - eq/ne) will do.</P>
<P> </P>
<P>Similarly, if the number of Trailing Zeros of Const2 are greater than Const1, then also, no amount of left shifting of Const2 will make it equal to Const1.</P>
<P>So, we can simply return a constant in that case as well.</P>
<P> </P>
<P>In the example you have stated, </P>
<P>(1 << A) == 0b1100</P>
<P>Shift = TrailingZeros(Const1) - TrailingZeros(Const2) = 2 - 0 = 2</P>
<P> </P>
<P>But, Const2 << Shift != Const1 (1 << 2 != 12)</P>
<P> </P>
<P>So, Const2 << A, can  never be equal to Const1, so the code returns false, as it should.</P>
<P> </P>
<P>I have tried to handle all these cases in my code. I guess, I haven't described the transformation very well in the description. I hope this clear it.</P>
<P> </P>
<P>Thanks.</P>
<P>Ankur Garg</P>
<P> </P>
<P>------- <B>Original Message</B> -------</P>
<P><B>Sender</B> : Sean Silva<chisophugis@gmail.com></P>
<P><B>Date</B> : Oct 18, 2014 04:58 (GMT+05:30)</P>
<P><B>Title</B> : Re: [PATCH] [InstCombineCompares] Added shl optimization for the instruction - icmp eq/ne (shl Const2, A), Const1</P>
<P> </P>
<DIV dir=ltr><BR>
<DIV class=gmail_extra><BR>
<DIV class=gmail_quote>On Fri, Oct 17, 2014 at 3:00 AM, Ankur Garg <SPAN dir=ltr><<A href="mailto:ankur29.garg@samsung.com" target=_blank>ankur29.garg@samsung.com</A>></SPAN> wrote:<BR>
<BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi majnemer, dexonsmith, suyog,<BR><BR>Hi,<BR>The following patch implements the optimization for the instructions of the type:<BR>icmp eq/ne (shl Const2, A), Const1<BR><BR>Such instructions can be converted to:<BR>icmp eq/ne A, (TrailingZeros(Const1) - TrailingZeros(Const2))<BR></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>What?</DIV>
<DIV><BR></DIV>
<DIV>(1 << A) == 0b1100</DIV>
<DIV>is equivalent to</DIV>
<DIV>A == 2</DIV>
<DIV>?</DIV>
<DIV><BR></DIV>
<DIV>Notice that the produced expression in the proposed optimization is invariant under the following transformation of the constants: changing any bit above the least significant 1. However, the recognized expression is not invariant under that change.</DIV>
<DIV><BR></DIV>
<DIV>-- Sean Silva</DIV>
<DIV> </DIV>
<BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><BR>This handles only the equality operators for now. Other operators need to be handled.<BR><BR>This patch is related to the <A href="http://reviews.llvm.org/D4068" target=_blank>http://reviews.llvm.org/D4068</A>. The D4068 implements this optimization for ashr/lshr operators. The following patch implements the optimization for shl operator.<BR><BR>Please help in reviewing it.<BR><BR>Thanks.<BR>Ankur<BR><BR><A href="http://reviews.llvm.org/D5839" target=_blank>http://reviews.llvm.org/D5839</A><BR><BR>Files:<BR>  lib/Transforms/InstCombine/InstCombine.h<BR>  lib/Transforms/InstCombine/InstCombineCompares.cpp<BR>  test/Transforms/InstCombine/icmp.ll<BR><BR>_______________________________________________<BR>llvm-commits mailing list<BR><A href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</A><BR><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target=_blank>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</A><BR><BR></BLOCKQUOTE></DIV><BR></DIV></DIV>
<P> </P><!--SP:ankur29.garg--><!--ankur29.garg:EP-->
<P> </P>
<TABLE id=confidentialsignimg>
<TBODY>
<TR>
<TD NAMO_LOCK>
<P><IMG border=0 src="cid:MKNRCZHWKC3T@namo.co.kr"></P></TD></TR></TBODY></TABLE></BODY></HTML><img src='http://ext.samsung.net/mailcheck/SeenTimeChecker?do=98934eddeedafa1ea7ed3d7791caab50454eee752797e514b59c266d84ffddcaa081912eeadc9ac284383d2d4cb3b62c1d70666c366810d91b20909a04efd4d2748cfe1d4e847419cf878f9a26ce15a0' border=0 width=0 height=0 style='display:none'>