<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 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"FrutigerNext LT Regular";}
@font-face
        {font-family:"Akkurat Pro Light";}
@font-face
        {font-family:"Akkurat Pro";}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
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-CA" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">For the following loop represented in llvm IR:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">for.body.lr.ph:                                   ; preds = %if.end19<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  %conv23 = zext i8 %conv2 to i32<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  <span style="color:#0070C0">%3 = zext i8 %ucInputNum.addr.0 to i64<o:p></o:p></span></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#0070C0">  %4 = shl i64 %3, 2<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  br label %for.body<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">for.body:                                         ; preds = %for.body, %for.body.lr.ph<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  %lsr.iv = phi i64 [ %lsr.iv.next, %for.body ], [ 0, %for.body.lr.ph ]<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  %ulTemp.0101 = phi i32 [ 0, %for.body.lr.ph ], [ %phitmp, %for.body ]<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  ……<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  %not.cmp39 = xor i1 %cmp39, true<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  %cond48 = zext i1 %not.cmp39 to i32<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  %add49 = add nuw nsw i32 %ulTemp.0101, %cond48<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  <span style="color:red">%phitmp = and i32 %add49, 65535                        <------ A</span><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  %lsr.iv.next = add nuw nsw i64 %lsr.iv, 4<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  %tmp = trunc i64 %lsr.iv.next to i32<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  %tmp106 = trunc i64 <span style="color:#0070C0">
%4</span> to i32<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  %exitcond = icmp eq i32 <span style="color:#0070C0">
%tmp106</span>, %tmp<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  br i1 %exitcond, label %for.end, label %for.body<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">for.end:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  ……<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The instruction A:  <span style="color:red">%phitmp = and i32 %add49, 65535
</span>is redundant and can be removed, because the trip count is at most 10 bits, and %add49 (from 0) is incremented by at most 1 per iteration. That is %add49 is at most 10 bits and there is no need for the 16-bit mask of and operation.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Where and how should this optimization implemented?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thanks.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Best,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Ning<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="0" style="width:482.4pt;border-collapse:collapse">
<tbody>
<tr style="height:28.5pt">
<td width="384" valign="top" style="width:288.0pt;padding:0cm 5.4pt 0cm 5.4pt;height:28.5pt">
<p class="MsoNormal"><img width="367" height="104" id="Picture_x0020_10" src="cid:image001.jpg@01D4BE1A.01369B10" alt="cid:image001.jpg@01D25BA7.447BB630"><span lang="EN-US"><o:p></o:p></span></p>
</td>
<td width="259" valign="top" style="width:194.4pt;padding:0cm 5.4pt 0cm 5.4pt;height:28.5pt">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:8.0pt;font-family:"Akkurat Pro";color:#1F497D"><o:p> </o:p></span></b></p>
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:8.0pt;font-family:"Akkurat Pro";color:#1F497D">Ning Xie<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:8.0pt;font-family:"Akkurat Pro";color:#1F497D"><o:p> </o:p></span></b></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:8.0pt;font-family:"Akkurat Pro Light";color:#7B7B7B">Huawei Canada Research Centre<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:8.0pt;font-family:"Akkurat Pro Light";color:#7B7B7B">O. +1 905-944-5000 ext. 7587<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:8.0pt;font-family:"Akkurat Pro Light";color:#7B7B7B">Email:
</span><a href="mailto:ning.xie@huawei.com"><span lang="EN-US" style="font-size:8.0pt;font-family:"Akkurat Pro Light"">ning.xie@huawei.com</span></a><span lang="EN-US" style="font-size:8.0pt;font-family:"Akkurat Pro Light";color:#7B7B7B">                   
<o:p></o:p></span></p>
<p class="MsoNormal"><a href="http://www.huawei.ca/"><b><span lang="EN-US" style="font-size:8.0pt;font-family:"Akkurat Pro Light";color:#7B7B7B">www.huawei.ca</span></b></a><b><span lang="EN-US" style="font-size:8.0pt;font-family:"Akkurat Pro Light";color:#7B7B7B"><o:p></o:p></span></b></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="text-align:justify"><span lang="EN-US" style="font-size:6.0pt;font-family:"FrutigerNext LT Regular";color:#C9C9C9">           
</span><a href="https://www.facebook.com/HuaweimobileCAN/"><span style="font-size:6.0pt;font-family:"FrutigerNext LT Regular";text-decoration:none"><img border="0" width="16" height="16" id="Picture_x0020_2" src="cid:image002.jpg@01D4BE1A.01369B10" alt="Facebook"></span></a><span lang="EN-US" style="font-size:6.0pt;font-family:"FrutigerNext LT Regular";color:#C9C9C9">  </span><a href="https://www.instagram.com/huaweicanada/"><span style="font-size:6.0pt;font-family:"FrutigerNext LT Regular";text-decoration:none"><img border="0" width="16" height="16" id="Picture_x0020_3" src="cid:image003.jpg@01D4BE1A.01369B10" alt="Instagram"></span></a><span lang="EN-US" style="font-size:6.0pt;font-family:"FrutigerNext LT Regular";color:#C9C9C9">  </span><a href="https://www.linkedin.com/company-beta/3014?pathWildcard=3014"><span style="font-size:6.0pt;font-family:"FrutigerNext LT Regular";text-decoration:none"><img border="0" width="15" height="16" id="Picture_x0020_4" src="cid:image004.jpg@01D4BE1A.01369B10" alt="LinkedIn"></span></a><span lang="EN-US" style="font-size:6.0pt;font-family:"FrutigerNext LT Regular";color:#C9C9C9">  </span><a href="https://twitter.com/huawei_canada?lang=en"><span style="font-size:6.0pt;font-family:"FrutigerNext LT Regular";text-decoration:none"><img border="0" width="16" height="16" id="Picture_x0020_5" src="cid:image005.jpg@01D4BE1A.01369B10" alt="Twitter"></span></a><span lang="EN-US" style="font-size:6.0pt;font-family:"FrutigerNext LT Regular";color:#C9C9C9"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align:justify"><span lang="EN-US" style="font-size:6.0pt;font-family:"FrutigerNext LT Regular";color:#C9C9C9"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-align:justify"><span lang="EN-US" style="font-size:6.0pt;font-family:"FrutigerNext LT Regular";color:#C9C9C9">This e-mail is intended only for the named recipient(s) and may contain information that is privileged, confidential
 to Huawei Technologies Canada Co., Ltd. and/or exempt from disclosure under applicable law.  No waiver of privilege, confidence or otherwise is intended by virtue of communication via the internet.  Any unauthorized use, dissemination or copying is strictly
 prohibited.  If you have received this e-mail in error, or are not named as a recipient, please immediately notify the sender and
</span><span lang="EN-US" style="font-size:6.0pt;font-family:"FrutigerNext LT Regular";color:#BFBFBF">destroy all copies of this e-mail.</span><span lang="EN-US" style="font-size:6.0pt;font-family:"FrutigerNext LT Regular";color:#C9C9C9"><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>