<div dir="ltr"><div>Hi all,</div><div><br></div><div>I've just thrashed this out further with Chandler on IRC, and thought I'd summarize what came up here. Chandler will rebutt if I make a mistake, I'm sure :)</div>
<div><br></div><div>The main point is that there are instcombines and bunch of arithmetic-simplifying optimizations that rely on SROA producing wide stores. In fact, it isn't the fact that the store is wide that matters, it is that there is a merged SSA node.</div>
<div><br></div><div><font face="courier new, monospace">%a = i32 ...</font></div><div><font face="courier new, monospace">%b = i32 ...</font></div><div><font face="courier new, monospace">%c = shl i64 (zext i32 %a to i64), i32 32</font></div>
<div><font face="courier new, monospace">%d = or i64 %c, (zext i32 %b to i64)</font></div><div><font face="courier new, monospace">store i64* %p, i64 %d</font></div><div><font face="courier new, monospace"><br></font></div>
<div><font face="courier new, monospace">%e = load i64* %p</font></div><div><font face="courier new, monospace">...</font></div><div><br></div><div>In the above example, optimizers can follow the load of %p through, via the store and end up with two constituent i32's that they can then do magic with. In the alternative scenario:</div>
<div><br></div><div><font face="courier new, monospace">%a = i32 ...</font></div><div><font face="courier new, monospace">%b = i32 ...</font></div><div><font face="courier new, monospace">%q = bitcast i64* %p to i32*</font></div>
<div><font face="courier new, monospace">store i32* (getelementptr i32* %q, i32 0), i32 %a</font></div><div><font face="courier new, monospace">store i32* (getelementptr i32* %a, i32 1), i32 %b</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">%e = load i64* %p</font></div><div>...</div><div><br></div><div>The optimizer can no longer see easily that %e is the concatenation of %a and %b.</div><div><br></div><div>
This is an important property, and is the main reason for not splitting wide stores to match their loads. Most importantly, this optimization happens in InstCombine and we run InstCombine after SLP and Loop Vectorization, which means the IR should be in this form at least up until the end of vectorization (or we lose this optimization after vectorization).</div>
<div><br></div><div>This then means that we need to teach the vectorizers and code metrics about the cost of splitting concatenated stores, which is likely to be awkward but we are left with little choice.</div><div><br></div>
<div>Cheers,</div><div><br></div><div>James</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 2 September 2014 11:20, Jiangning Liu <span dir="ltr"><<a href="mailto:liujiangning1@gmail.com" target="_blank">liujiangning1@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Chandler,<div><br><div class="gmail_extra"><div class="gmail_quote"><div class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Once you start slicing up memory accesses, *you break SSA form* and all of the analyses that depend on it. I cannot express how strongly I feel this is a very bad idea and the wrong direction in the middle end.</div>
<div><div><br></div></div></div></div></div></blockquote><div><br></div></div><div>What do you mean by "you break SSA form" for the case Hao's patch is solving? Do you mean some SSA form info could be lost?</div>
<div><br></div><div>The transformation of Hao's patch is to change a single wide store to two separate narrow stores, but the address of those two narrow stores are still sequential. For the memory stored here we don't have any SSA information attached at all, right?</div>
<div><br></div><div>So what SSA form information could be lost? And what optimization could be affected? Can you give an example?</div><div><br></div><div>Thanks,<br></div><div>-Jiangning </div></div></div></div></div>
</blockquote></div><br></div>