<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 27, 2014 at 8:46 PM, Hao Liu <span dir="ltr"><<a href="mailto:Hao.Liu@arm.com" target="_blank">Hao.Liu@arm.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I think you concern about when the narrow LOADs are folded back, we can’t fuse the narrow STOREs back. Am I get your point?</span></p>
</blockquote><div><br></div><div>No, my concern is about when we completely remove the loads through GVN or even the mem2reg process that runs in SROA itself. The sliced loads are expected to go away and become SSA registers. We might well be able to then fold away the zext / shl / or / etc into the math that feeds those SSA values. But we will in most cases fail to fuse the stores back together once they are split.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">But I think the narrow LOADs won’t be folded back, as the SROA checks such LOAD can be split and removed. So if the narrow LOADs won’t exist, there are two choices for us:<u></u><u></u></span></p>
<p><u></u><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><span>(1)<span style="font:7.0pt "Times New Roman"">    </span></span></span><u></u><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">The additional ZEXT/SHL/OR and wide STORE.<u></u><u></u></span></p>
<p><u></u><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><span>(2)<span style="font:7.0pt "Times New Roman"">    </span></span></span><u></u><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Two narrow STOREs.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I still prefer the (2) than the (1). I think a better optimization for (1) is to split the STORE. Even if there are other optimizations to change the wide STORE, we’ll still have ZEXT/SHL/OR left. Such code with bit math seems not the best choice.</span></p>
</blockquote><div><br></div><div>I'm not really sure what you mean about having instructions left over.</div><div><br></div><div>The fundamental thing is this: the width of memory stored to is actually a very important property of the source program. It clarifies the maximum width of memory that is correct to store two in a single instruction. Splitting or narrowing a store is often irreversible because fusing or widening can introduce data races.</div>
<div><br></div><div>As a consequence, it is a conscious choice throughout the optimizer to preserve the maximal width of stores (and to a lesser extend loads). This preserves the information in the middle-end about what freedoms the source program has w.r.t. to memory accesses and data races.</div>
<div><br></div><div><br></div><div>Also, with the IR produced by SROA, the information needed is still present. I think the problem is that both backends need to be taught the trick of using multiple stores at indexed offsets to save math combining two values. That's my suggestion for how to improve the quality of code for these patterns.</div>
</div></div></div>