<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="">On Mar 28, 2016, at 9:32 AM, Jia Chen via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:<br class=""><div><blockquote type="cite" class=""><div class=""><div bgcolor="#FFFFFF" text="#000000" class=""><blockquote cite="mid:6836018.103.1459180251927.JavaMail.javamailuser@localhost" type="cite" class=""><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt;" class="">Can you elaborate on what you mean by flow sensitive? We have a
        mod/ref query interface that can return answers specific to a
        particular instruction/call pair. The code above could easily
        live in a single basic block, and if we had function attribute
        deduction on the 'argmemonly' attribute, we could probably do
        this now.<br class="">
        <br class="">
         -Hal<span name="x" class=""></span><br class="">
      </div>
    </blockquote>
    <br class="">
    What I meant is that the CSE needs to be aware of the execution
    order, i.e. the call to V1.pop_back() should not be in the middle of
    the two V1.size() for zero to be 0. If there exists more complicated
    control flows, CSE needs to be able to make the same kind of
    argument across basic blocks.<br class="">
    <br class="">
    I didn't follow LLVM development very closely to be familiar with
    how LLVM handles CSE. If what I said above is exactly how it works
    today, then yes we could probably do this now.<br class=""></div></div></blockquote><div><br class=""></div>The existing LLVM passes and infrastructure already do this.</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div bgcolor="#FFFFFF" text="#000000" class="">
    But still, there is no APIs that answers "are p and q aliases before
    this instruction x?". The same can be done for mod-ref today (if I
    remembered correctly this isn't even the case before the AAResult
    class came into existence), but not for aliases. <br class=""></div></div></blockquote><div><br class=""></div></div>This is already handled correctly by LLVM.  The sequence in question is:<div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div bgcolor="#FFFFFF" text="#000000" class=""><blockquote cite="mid:B017C534-9BF7-4C40-B2DF-A6BA3790C356@apple.com" type="cite" class=""><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class="">auto length = V1.size();</div></blockquote></blockquote></div></blockquote><div class=""><br class=""></div><div class="">“V1.size()” (which is effectively a load) is available after this instruction.</div><br class=""><blockquote type="cite" class=""><div bgcolor="#FFFFFF" text="#000000" class=""><blockquote cite="mid:B017C534-9BF7-4C40-B2DF-A6BA3790C356@apple.com" type="cite" class=""><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><div class="">V2.pop_back();    // Mutates *this</div></div></blockquote></blockquote></div></blockquote><div class=""><br class=""></div><div class="">Alias analysis is queried to say “does std::vector::pop_back(&V2) mod/ref &V1”?</div><div class=""><br class=""></div><div class="">If it returns mod, then “length” is removed from the available set.</div><br class=""><blockquote type="cite" class=""><div bgcolor="#FFFFFF" text="#000000" class=""><blockquote cite="mid:B017C534-9BF7-4C40-B2DF-A6BA3790C356@apple.com" type="cite" class=""><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class="">auto zero = length - V1.size()</div></blockquote></blockquote></div></blockquote></div><div class=""><div bgcolor="#FFFFFF" text="#000000" class=""><br class=""></div></div><div bgcolor="#FFFFFF" text="#000000" class="">The access to V1.size() also a load, if it is in the available set, it is replaced with the SSA value for “length”.  A later simplification pass turns "length-length" into 0, allowing the original load to be removed as dead.</div><div bgcolor="#FFFFFF" text="#000000" class=""><br class=""></div><div bgcolor="#FFFFFF" text="#000000" class="">-Chris</div></body></html>