<div dir="ltr">So,<div>both GVN's we have mainly exist to eliminate redundancies, they don't perform general transforms.</div><div>So in your example, it would be "easy" to make NewGVN see through the memcpys</div><div><br></div><div>ie</div><div>teach it that memcpy(a, b, full size of b and a) means a = b, and propagate it through, and whatever goodness this entails.</div><div><br></div><div>It also currently knows how to coerce loads of memset/memcpy to pull the value out of the original piece, even when they are *not* full size memcpy.</div><div>This requires instruction insertion in non-constant cases.</div><div>So it only does this for constants ATM (but I have code to extend it to the general case and it works fine, it's in my patch list).</div><div><br></div><div>The infrastructure i'm about to commit tomorrow also makes it know that it can use alternative "fake" instructions to represent values, and make the instructions real later.</div><div><br></div><div>So for example, for</div><div><br></div><div>if (foo)</div><div>  a = 5, b = 2</div><div>else</div><div>  b = 5, a = 2</div><div><br></div><div>return a + b</div><div>it knows that a+b is equivalent to 7</div><div><br></div><div>and when faced with:<br><div>if (foo)</div><div>  a = 5, b = 2</div><div>else</div><div>  b = 5, a = 3</div><div><br></div><div>return a+b<br></div></div><div>it knows that a+b is equivalent to phi(7, 8) (which doesn't exist in the original program), and that it can insert that phi to eliminate c.</div><div><br></div><div>You could use that infrastructure to teach it that the memcpy's are equivalent to stores that it could insert.</div><div><br></div><div>I would actually start by teaching it about memcpy in general, and that full size memcpy implies value equivalence (this would require wiring it into performSymbolicCallEvaluation), that store of a memcpy target and memcpy are equivalent when they copy/store the same value (see the FIXME in performSymbolicStoreEvaluation).</div><div><br></div><div>If you want to teach it to try to see memcpy's as stores, that's possible too.</div><div>It's a bit trickier because NewGVN is ruthless. It terminates only at fixpoint.  So you have to make the conditions under which you do things like "see memcpy as store" totally deterministic and ordered, or someone will come up with a testcase where we bounce forever between two the possible values for the same thing.</div><div><br></div><div>We have a bunch of verifiers to try to help with this, but as Davide can tell you, it can be a workout sometimes :)</div><div><br></div><div>At this point, in the base, it's really rare to be able to trigger this behavior (and all cases i'm aware of involve undef).</div><div>But if you add symbolic evaluation code, it usually takes a few tries to get it right.</div><div><br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 16, 2017 at 12:28 PM, Keno Fischer via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</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"><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Tue, May 16, 2017 at 2:16 PM, Davide Italiano <span dir="ltr"><<a href="mailto:davide@freebsd.org" target="_blank">davide@freebsd.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id="m_7547933600193433619:29k" class="m_7547933600193433619a3s m_7547933600193433619aXjCH m_7547933600193433619m15c127a99811326a">This seems like a GVN job to me.</div></blockquote><div><br></div></span><div>Cool. If I wanted to try to implement this in NewGVN, any hints on how to start?</div></div><br></div></div>
<br>______________________________<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>