<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:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","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;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@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"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Hi Nadav,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">For the current Atom, LEAs are not always better. Compared to an ADD, the LEA requires its inputs to be available early, so that its output can be available
 early. Ideally, the code generator should use LEA only for operations whose result will be used in address calculations. It is not clear to me how one would do this.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The current X86 code generator tries to use LEA for some kinds of 3 address code, in order to eliminate the possibility of an unwanted move instruction. I tried
 to change that code to defer the time when an LEA would be used, but that caused some code to get worse, so the existing code for generating LEAs is not changed by the patch.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Because the decision as to whether or not it is profitable to use an LEA depends on the number of cycles between the LEA and the next use of its output, the
 pass in the patch runs after the code is register allocated and scheduled.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The convertToThreeAddress function is not guarded by the AfterRegAlloc flag. If the flag is false, then the function behaves exactly as it did before. If the
 flag is true, then it allows moves to be converted to LEAs when appropriate and it prevents the conversion of certain instructions taking an immediate operand when  the form of the immediate operand would be rejected by addImm().<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The patch uses the convertToThreeAddress function because it already handles all of the cases that would be needed.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">For EEMBC the overall difference in performance was negligible, several of the benchmarks saw improvements of 10-20% with this patch. For SPEC2000, there was
 a minor gain of about  0.35%.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">If there is anything else which you think I need to explain, or if you have a suggestion for a better approach, please let me know!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Preston<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Nadav Rotem [<a href="mailto:nrotem@apple.com">mailto:nrotem@apple.com</a>]
<br>
<b>Sent:</b> Thursday, April 11, 2013 7:36 PM<br>
<b>To:</b> <a href="mailto:reviews+D660+public+a10049d8ed57ba7c@llvm-reviews.chandlerc.com">
reviews+D660+public+a10049d8ed57ba7c@llvm-reviews.chandlerc.com</a><br>
<b>Cc:</b> Du Toit, Stefanus; Gurd, Preston; <a href="mailto:llvm-commits@cs.uiuc.edu">
llvm-commits@cs.uiuc.edu</a><br>
<b>Subject:</b> Re: [PATCH] Add peephole optimization to use LEA instructions of Intel Atom<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Hi Preston, <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Why are you doing this optimization after register allocation, or even during instruction selection ?  If LEAs are better, why not use them all the time ?  Why are you going through the convertToThreeAddress, and not just do the conversion
 ?  Other users of convertToThreeAddress won't benefit from it because it is guarded by the isAfterRA flag, and you don't really need any of the logic in convertToThreeAddress ?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Nadav<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Apr 11, 2013, at 3:09 PM, Preston Gurd <<a href="mailto:preston.gurd@intel.com">preston.gurd@intel.com</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<div>
<p class="MsoNormal">Hi nadav, sdt,<br>
<br>
This patch adds a pass which runs after register allocation when an Intel Atom processor is the target. The LEA instruction in the current Atom processor is specifically optimized to work best when its result is to be used as part of a memory address. This
 patch finds load or store instructions which use a base and/or an index register. It looks for an instruction in the current basic block which sets the base and/or index in the previous 5 instructions and then attempts to convert the instruction into an LEA,
 using the existing convertToThreeAddress code. For instance, it could convert an add or a move into an LEA. Since the result of an LEA is available earlier than the result of an ADD or a Move, there can be less delay in starting the load or store which references
 the register.<br>
<br>
This is done after register allocation. The convertToThreeAddress function needed to have slightly different behaviour when invoked after register allocation. It was then useful to convert move instructions to LEAs. Also, some instructions defined to take immediate
 operands can only be converted to LEAs after register allocation if the immediate operand is an absolute number.<br>
<br>
This patch adds a lit test which verifies that the replacement of an ADD by and LEA is NOT done if it is not needed.<br>
<br>
Please review.<span class="apple-converted-space"> </span><br>
<br>
<br>
<a href="http://llvm-reviews.chandlerc.com/D660">http://llvm-reviews.chandlerc.com/D660</a><br>
<br>
Files:<br>
 test/CodeGen/X86/atom-fixup-lea2.ll<br>
 test/CodeGen/X86/lsr-static-addr.ll<br>
 test/CodeGen/X86/atom-fixup-lea1.ll<br>
 test/CodeGen/X86/atom-fixup-lea3.ll<br>
 lib/Target/X86/X86.td<br>
 lib/Target/X86/X86Subtarget.cpp<br>
 lib/Target/X86/X86TargetMachine.cpp<br>
 lib/Target/X86/X86InstrInfo.cpp<br>
 lib/Target/X86/X86Subtarget.h<br>
 lib/Target/X86/X86InstrInfo.h<br>
 lib/Target/X86/X86.h<br>
 lib/Target/X86/X86FixupLEAs.cpp<br>
 lib/Target/X86/CMakeLists.txt<br>
<D660.1.patch>_______________________________________________<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">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>