<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 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@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;}
/* 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;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle20
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.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;}
/* List Definitions */
@list l0
        {mso-list-id:816721836;
        mso-list-type:hybrid;
        mso-list-template-ids:1785477298 1319773324 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
        {mso-level-start-at:0;
        mso-level-number-format:bullet;
        mso-level-text:-;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Calibri","sans-serif";
        mso-fareast-font-family:Calibri;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></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><b>Description: <o:p></o:p></b></p><p class=MsoNormal>This contribution extends LLVM greedy Register Allocator to optimize for code size when LLVM compiler targets ARM Thumb 2 instruction set. This heuristic favors<b><i><span style='color:#1F497D'> </span></i></b>assigning register R0 through R7 to operands used in instruction that can be encoded in 16 bits (16-bit is allowed only if R0-7 are used). Operands that appear most frequently in a function (and in instructions that qualify) get R0-7 register.<o:p></o:p></p><p class=MsoNormal>This heuristic is turned on by default and has impact on generated code only if -mthumb compiler switch is used. To turn this heuristic off use -disable-favor-r0-7 feature flag. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>This patch modifies: <br>1) The LLVM greedy register allocator located in LLVM/CodeGen directory: To add the new code size heuristic.<br>2) The ARM-specific flies located in LLVM/Target/ARM directory: To add the function that determines<span style='color:#1F497D'> </span>which instruction can be encoded in 16-bits and a fix to enable the compiler to emit CMN instruction in 16-bits encoding. <br>3) The LLVM test suite: fix test/CodeGen/Thumb2/thumb2-cmn.ll test.<o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b>Performance impact: <o:p></o:p></b></p><p class=MsoNormal>I focused on –Os and –mthumb  flags. But observed similar improvement  with –O3 and –mthumb. Runtime measured on Qualcomm 8660.<o:p></o:p></p><p class=MsoNormal>Code size:<o:p></o:p></p><p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>-<span style='font:7.0pt "Times New Roman"'>          </span></span><![endif]>SPEC2000  benchmarks between 0 to 0.6% code size reduction (with no noticeable regression).    <o:p></o:p></p><p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>-<span style='font:7.0pt "Times New Roman"'>          </span></span><![endif]>EEMBC benchmarks between 0 to  6% reduction (no noticeable regression).  Automotive and Networking average about 1% code size reduction  and Consumer about 0.5%.<o:p></o:p></p><p class=MsoNormal>Runtime:<o:p></o:p></p><p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>-<span style='font:7.0pt "Times New Roman"'>          </span></span><![endif]>SPEC2000 between -1% and 6% speed up (Spec2k/ammp 6%)<o:p></o:p></p><p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>-<span style='font:7.0pt "Times New Roman"'>          </span></span><![endif]>EEMBC overall averages faster -1 to 5%.<o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> <o:p></o:p></span></p><p class=MsoNormal><b>Modified:<o:p></o:p></b></p><p class=MsoNormal>   test/CodeGen/Thumb2/thumb2-cmn.ll<o:p></o:p></p><p class=MsoNormal>   include/llvm/Target/TargetInstrInfo.h<o:p></o:p></p><p class=MsoNormal>   include/llvm/CodeGen/LiveInterval.h<o:p></o:p></p><p class=MsoNormal>   lib/Target/ARM/Thumb2SizeReduction.cpp<o:p></o:p></p><p class=MsoNormal>   lib/Target/ARM/ARMBaseInstrInfo.cpp<o:p></o:p></p><p class=MsoNormal>   lib/Target/ARM/ARMBaseInstrInfo.h<o:p></o:p></p><p class=MsoNormal>   lib/CodeGen/RegAllocGreedy.cpp<o:p></o:p></p><p class=MsoNormal>   lib/CodeGen/CalcSpillWeights.cpp<o:p></o:p></p><p class=MsoNormal>   <o:p></o:p></p><p class=MsoNormal>for details see RACodeSize.txt <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><b>Testing: <o:p></o:p></b></p><p class=MsoNormal>See ARMTestSuiteResult.txt and ARMSimple-Os-mthumb.txt<o:p></o:p></p><p class=MsoNormal>Note –O3 is also completed on X86 and ARM CPUs<span style='color:#1F497D'><o:p></o:p></span></p></div></body></html>