<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:"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:0cm;
        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.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
span.EmailStyle18
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.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;}
/* List Definitions */
@list l0
        {mso-list-id:783773023;
        mso-list-type:hybrid;
        mso-list-template-ids:-1877211434 273685024 134807555 134807557 134807553 134807555 134807557 134807553 134807555 134807557;}
@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:-18.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-font-family:Calibri;
        mso-bidi-font-family:"Times New Roman";}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level3
        {mso-level-tab-stop:108.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level4
        {mso-level-tab-stop:144.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level5
        {mso-level-tab-stop:180.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level6
        {mso-level-tab-stop:216.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level7
        {mso-level-tab-stop:252.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level8
        {mso-level-tab-stop:288.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level9
        {mso-level-tab-stop:324.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></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-GB link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Hi all,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>This patch-set aims to fix PR19972 (<a href="http://llvm.org/bugs/show_bug.cgi?id=19972">http://llvm.org/bugs/show_bug.cgi?id=19972</a>).<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The Thumb-1 specific parts of the load/store optimizer in its previous iteration had some correctness issues:<o:p></o:p></p><p class=MsoListParagraph style='text-indent:-18.0pt;mso-list:l0 level1 lfo2'><![if !supportLists]><span style='mso-list:Ignore'>-<span style='font:7.0pt "Times New Roman"'>          </span></span><![endif]>Base register liveness information wasn’t correctly transferred<o:p></o:p></p><p class=MsoListParagraph style='text-indent:-18.0pt;mso-list:l0 level1 lfo2'><![if !supportLists]><span style='mso-list:Ignore'>-<span style='font:7.0pt "Times New Roman"'>          </span></span><![endif]>It didn’t handle stores of the base register after writeback correctly<o:p></o:p></p><p class=MsoListParagraph style='text-indent:-18.0pt;mso-list:l0 level1 lfo2'><![if !supportLists]><span style='mso-list:Ignore'>-<span style='font:7.0pt "Times New Roman"'>          </span></span><![endif]>It was possible to generate illegal instructions such as STMs including the base register<o:p></o:p></p><p class=MsoListParagraph style='text-indent:-18.0pt;mso-list:l0 level1 lfo2'><![if !supportLists]><span style='mso-list:Ignore'>-<span style='font:7.0pt "Times New Roman"'>          </span></span><![endif]>It would try to undo the base register writeback using a SUBS in unsafe conditions. SUBS sets the conditions flags, so cases like this (taken from a failing LNT program) could occur, merged from two LDRs:<o:p></o:p></p><p class=MsoNormal style='margin-left:36.0pt'>        cmp     r5, #1                                                                                              <o:p></o:p></p><p class=MsoNormal style='margin-left:36.0pt'>        ldm     r6!, {r0, r4}                                                                                       <o:p></o:p></p><p class=MsoNormal style='margin-left:36.0pt'>        subs    r6, #8                                                                                              <o:p></o:p></p><p class=MsoNormal style='margin-left:36.0pt'>        blt     .LBB177_10<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I’ve addressed these bugs in the patches as follows:<o:p></o:p></p><p class=MsoNormal>0001: Correctly transfer kill flags on the base register. Since the MemOps list may be in a different order, we need to transfer the kill flags of the last instruction as it occurred in the original instruction stream, not the last index of MemOps. The test case “merge-ldr-call.ll” from patch 0003 is affected by this, however this patch on its own should not affect codegen.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>0002: Make the merging more conservative on Thumb1. For now, we only merge LDRs/STRs when it’s clearly safe to do so: if there is no writeback (LDM into base register), or the base register is dead after the merged instruction (so the writeback doesn’t need to be handled). Tests for each of the cases are in patch 0003.<o:p></o:p></p><p class=MsoNormal>Since this has the side-effect of not allowing merges of more than one LDM/STM of the same base register in a row, I’ve also modified the memcpy inliner for Thumb1 to use a library call if copying more than a single LDM/STM can handle (16 bytes). I’m working on a patch to remove this limitation again, but it’s not quite ready for review yet. This patch on its own is always a clear win both in code size and performance however, so I think it’s worth committing.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>0003: Re-enable the pass, and add test cases for the previous two patches. There are three new regression tests created from simple test programs that were miscompiled previously, and I’ve added –verify-machineinstrs to each of the tests as well.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I’ve tested the patches with SPEC2000, SPEC2006, LNT and EEMBC and everything looks fine on v6M and v7, but any additional testing or validation is of course welcome! Please let me know what you think.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Cheers<o:p></o:p></p><p class=MsoNormal>Moritz<o:p></o:p></p></div></body></html>