<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Keno,</div><div class=""> Perhaps you can view the problem to be the memcpys themselves,</div><div class="">We humans can look at the memcpys and see loads and stores</div><div class="">but to almost all optimizer passes they aren’t what it is looking for,</div><div class="">They instead see function calls which they mostly don’t touch,</div><div class=""><br class=""></div><div class="">If these memcpys were inlined into plain old loads and stores</div><div class="">The redundant loads and stores should be deleted by existing opts</div><div class=""><br class=""></div><div class="">A question I have for you is, because this looks like “copy-in-copy-out” argument semantics,</div><div class="">Which to me looks more like Ada than C, what was the source language ?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Peter Lawrence.</div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On May 16, 2017, at 12:00 PM, via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><span style="display: inline !important; float: none;" class="">On May 16, 2017, at 12:37 PM, Keno Fischer via llvm-dev <</span><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><span style="display: inline !important; float: none;" class=""><</span><a href="mailto:llvm-dev@lists.llvm.org" class="">mailto:llvm-dev@lists.llvm.org</a><span style="display: inline !important; float: none;" class="">>> wrote:</span><br class=""><br class=""><span style="display: inline !important; float: none;" class="">Consider the following IR example:</span><br class=""><br class=""><span style="display: inline !important; float: none;" class="">define void @simple([4 x double] *%ptr, i64 %idx) {</span><br class=""><span style="display: inline !important; float: none;" class=""> %stack = alloca [4 x double]</span><br class=""><span style="display: inline !important; float: none;" class=""> %ptri8 = bitcast [4 x double] *%ptr to i8*</span><br class=""><span style="display: inline !important; float: none;" class=""> %stacki8 = bitcast [4 x double] *%stack to i8*</span><br class=""><span style="display: inline !important; float: none;" class=""> call void @llvm.memcpy.p0i8.p0i8.i32(i8 *%stacki8, i8 *%ptri8, i32 32, i32 0, i1 0)</span><br class=""><span style="display: inline !important; float: none;" class=""> %dataptr = getelementptr inbounds [4 x double], [4 x double] *%ptr, i32 0, i64 %idx</span><br class=""><span style="display: inline !important; float: none;" class=""> store double 0.0, double *%dataptr</span><br class=""><span style="display: inline !important; float: none;" class=""> call void @llvm.memcpy.p0i8.p0i8.i32(i8 *%ptri8, i8 *%stacki8, i32 32, i32 0, i1 0)</span><br class=""><span style="display: inline !important; float: none;" class=""> ret void</span><br class=""><span style="display: inline !important; float: none;" class="">}</span><br class=""><br class=""><br class=""><span style="display: inline !important; float: none;" class="">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.</span><br class=""><br class=""><span style="display: inline !important; float: none;" class="">Thanks,</span><br class=""><span style="display: inline !important; float: none;" class="">Keno</span></div></blockquote></div><br class=""></body></html>