<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi, Even:<br>
    <br>
        Thank you for your feedback. Yes, I should put the comment on
    the code.<br>
    <br>
         These statement embody this rule:<br>
    <br>
       Suppose mem1 and mem2 are two memory accesses,  and O1 and O2 are
    corresponding <br>
    objects (obtained via getUnderlyingObject()).  mem1 and mem2 are
    disjointed if:<br>
    <br>
        o. O1 (or O2) is a global variable without address taken, and<br>
        o. O2 ! = O1 (this is condition enclosing these statement) <br>
    <br>
       We can prove this way: Let O1 be a global variable without
    address taken, O2 is another<br>
    object. O2 could be a named variable, or an anonymous, imaginary
    "memory location" accessed <br>
    via indirect load/store. <br>
    <br>
        In the first case, O1 and O2 will not alias (O1 and O2 are
    distinct variable); for <br>
    the 2nd case, since O1 dose not has its address taken, it cannot be
    indirectly accessed, <br>
    hence O1 and O2 are disjointed. <br>
    <br>
        One might asked what if the global variable is volatile? The
    answer is we will not mark a volatile<br>
    variable "not-address-taken". <br>
    <br>
    Thanks<br>
    Shuxin<br>
    <br>
    <div class="moz-cite-prefix">On 10/21/13 2:29 PM, Evan Cheng wrote:<br>
    </div>
    <blockquote
      cite="mid:46539B3A-D8D0-4E34-B763-9B8C166B33A7@apple.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      Hi Shuxin,
      <div><br>
      </div>
      <div>This needs some comments:</div>
      <div><br>
      </div>
      <div>
        <div>+    if (const GlobalVariable *GV =
          dyn_cast<GlobalVariable>(O1))</div>
        <div>+      if (GV->notAddressTaken())</div>
        <div>+        return NoAlias;</div>
        <div>+</div>
        <div>+    if (const GlobalVariable *GV =
          dyn_cast<GlobalVariable>(O2))</div>
        <div>+      if (GV->notAddressTaken())</div>
        <div>+        return NoAlias;</div>
        <div><br>
        </div>
        <div>Evan</div>
        <div><br>
        </div>
        <div>
          <div>On Oct 21, 2013, at 11:27 AM, Shuxin Yang <<a
              moz-do-not-send="true" href="mailto:shuxin.llvm@gmail.com">shuxin.llvm@gmail.com</a>>
            wrote:</div>
          <br class="Apple-interchange-newline">
          <blockquote type="cite">
            <meta http-equiv="content-type" content="text/html;
              charset=ISO-8859-1">
            <div bgcolor="#FFFFFF" text="#000000"> Ping.<br>
              <br>
              (add testing cases. Forget attaching testing case in my
              previous mail). <br>
              <div class="moz-forward-container">Thanks<br>
                Shuxin<br>
                <br>
                <br>
                -------- Original Message --------
                <table class="moz-email-headers-table" border="0"
                  cellpadding="0" cellspacing="0">
                  <tbody>
                    <tr>
                      <th align="RIGHT" nowrap="nowrap"
                        valign="BASELINE">Subject: </th>
                      <td>[Patch] Use address-taken to disambiguate
                        global var and indirect accesses</td>
                    </tr>
                    <tr>
                      <th align="RIGHT" nowrap="nowrap"
                        valign="BASELINE">Date: </th>
                      <td>Tue, 15 Oct 2013 14:39:51 -0700</td>
                    </tr>
                    <tr>
                      <th align="RIGHT" nowrap="nowrap"
                        valign="BASELINE">From: </th>
                      <td>Shuxin Yang <a moz-do-not-send="true"
                          class="moz-txt-link-rfc2396E"
                          href="mailto:shuxin.llvm@gmail.com"><shuxin.llvm@gmail.com></a></td>
                    </tr>
                    <tr>
                      <th align="RIGHT" nowrap="nowrap"
                        valign="BASELINE">To: </th>
                      <td>Commit Messages and Patches for LLVM <a
                          moz-do-not-send="true"
                          class="moz-txt-link-rfc2396E"
                          href="mailto:llvm-commits@cs.uiuc.edu"><llvm-commits@cs.uiuc.edu></a></td>
                    </tr>
                  </tbody>
                </table>
                <br>
                <br>
                <pre>Hi,

     The attached patch is to take advantage of address-taken to 
disambiguate global
  variable and indirect memory accesses.

  The motivation
  ===========
      I was asked to investigate the problem where the static variable 
is not hoisted as
loop invariant:

     ---------------
      static int xyz;
      void foo(int *p) {
          for (int i = 0; i < xyz; i++)
             *p++ = ....
      }
    -----------------

    The compiler dose have a concept call "addr-capture". However, I 
don't think it can
be used for disambiguate global variable and indirect access. The 
reasons is that
a variable dose not have its address *CAPTURED*, dose not necessarily 
mean this variable
cannot be indirectly accessed.

    So, I rely on "address taken"

  How it works
  ========
       1. In globalopt, when a global var is identified as 
not-addr-taken, cache the result
           to GlobalVariable::notAddrTaken.

       2. In alias-analyzer, supposed the mem-op involved are m1 and m2. 
Let o1 and o2
           be the "object" (obtained via get_underlying_object() of m1 
and m2 respectively.

          if O1 != O2 && one of the them are global-variable without 
address taken,
          then m1 and m2 are disjointed access.

  Misc:
  =========
       Note that I *cache* the result of not-addr-taken. Unlike 
function, it is far more expensive
to figure out if a globalvar has its address taken or not. So, it is not 
appropriate to analyze
the address-taken on the fly.

      On the other hand,  I personally think not-addr-taken flag is 
almost maintenance free.
(FIXME) Only few optimizer could make a not-addr-taken variable become 
addr-taken (say, outlining),
and I don't think currently we have such passes (FIXME again!).  In case 
such rare cases take place,
it is up to the pass the to reset the not-addr-taken flags.

     Of course, a variable previously considered addr-taken may later on 
proved to be not-addr-taken.
In that case, compiler dose not have to update it -- it is 
conservatively correct.

  Performance impact
=============
   Measured on an oldish Mac Tower with 2x 2.26Ghz Quad-Core Xeon. Both 
base-line and
the change are measured for couple of times.  I did take a look of why 
Olden/power is sped up --
the loads of static variable "P" and "Q" are promoted in many places.  I 
have not yet got chance
to investigate why the speedup to pairlocalalign with O3 disappear in 
O3+LTO.


o. test-suite w/ O3:
-------------------
Benchmarks/Olden/power/power                  1.6129 1.354       
-16.0518321036642
Benchmarks/mafft/pairlocalalign               31.4211 26.5794     
-15.4090722476298
Benchmarks/Ptrdist/yacr2/yacr2                0.881 0.804       
-8.74006810442678

o. test-suite w/ O3 + LTO
-------------------------
Benchmarks/Olden/power/power  1.6143      1.3419 -16.8741869540978
Applications/spiff/spiff      2.9203      2.849 -2.44152997979659

o. spec2kint w/ O3+LTO
----------------------
bzip2  75.02 73.92 -1.4


Thanks
Shuxin



</pre>
                <br>
              </div>
              <br>
            </div>
            <span><addrtaken.patch></span><span><addrtaken.test.patch></span>_______________________________________________<br>
            llvm-commits mailing list<br>
            <a moz-do-not-send="true"
              href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
            <a class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>