<div dir="ltr">Hi Daniel,<div><br></div><div>as far as I can tell that handles turning small memcpys into store instructions. What I'm looking for</div><div>is something that can simplify (copy to stack) -> (modify stack) -> (copy back to heap) into a single</div><div>heap modification.</div><div><br></div><div>Keno</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 16, 2017 at 1:50 PM, Daniel Neilson <span dir="ltr"><<a href="mailto:dneilson@azul.com" target="_blank">dneilson@azul.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> The InstCombine transform does exactly what you want. Take a look at lib/Transforms/Scalar/<wbr>InstCombine/InstCombineCalls.<wbr>cpp — InstCombiner::<wbr>SimplifyMemTransfer<br>
<br>
With your align parameter on the memcpy being zero you are likely hitting the first conditional in that function:<br>
if (CopyAlign < MinAlign) {<br>
MI->setAlignment(ConstantInt::<wbr>get(MI->getAlignmentType(), MinAlign, false));<br>
return MI;<br>
}<br>
<br>
Arguably, instcombine probably shouldn’t bail on trying to simplify the memcpy just because it could update the alignment on the call...<br>
<br>
-Daniel<br>
<div><div class="h5"><br>
> On May 16, 2017, at 12:37 PM, Keno Fischer via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Consider the following IR example:<br>
><br>
> define void @simple([4 x double] *%ptr, i64 %idx) {<br>
> %stack = alloca [4 x double]<br>
> %ptri8 = bitcast [4 x double] *%ptr to i8*<br>
> %stacki8 = bitcast [4 x double] *%stack to i8*<br>
> call void @llvm.memcpy.p0i8.p0i8.i32(i8 *%stacki8, i8 *%ptri8, i32 32, i32 0, i1 0)<br>
> %dataptr = getelementptr inbounds [4 x double], [4 x double] *%ptr, i32 0, i64 %idx<br>
> store double 0.0, double *%dataptr<br>
> call void @llvm.memcpy.p0i8.p0i8.i32(i8 *%ptri8, i8 *%stacki8, i32 32, i32 0, i1 0)<br>
> ret void<br>
> }<br>
><br>
><br>
> I would like to see this optimized to just a single store (into %ptr). Right now, even at -O3 that doesn't happen. My frontend guarantees that idx is always inbounds for the allocation, but I do think the transformation should be valid regardless because accessing beyond the bounds of the alloca should be undefined behavior. Now, my question is which pass should be responsible for doing this? SROA? DSE? GVN? A new pass just to do this kind of thing? Maybe there already is some pass that does this, just not in the default pipeline? Any hints would be much appreciated.<br>
><br>
> Thanks,<br>
> Keno<br>
</div></div>> ______________________________<wbr>_________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br>
</blockquote></div><br></div>