<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 12/14/2017 03:49 PM, Liu, Yaxun
      (Sam) wrote:<br>
    </div>
    <blockquote
cite="mid:DM5PR1201MB025265404523BC1587CB2AD7F80A0@DM5PR1201MB0252.namprd12.prod.outlook.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:black;}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.EmailStyle22
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal"><span style="color:windowtext">Hal,<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="color:windowtext"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span style="color:windowtext">Thanks for
            your suggestion. I think that makes sense.<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="color:windowtext"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span style="color:windowtext">Currently,
            non-zero alloca address space is already represented by data
            layout, e.g., the last component of the data layout of
            amdgcn---amdgiz target is -A5, which means alloca is in
            address space 5. How about adding a letter z to -A5 to
            indicate alloca may have zero value? i.e. -A5 means alloca
            is in address space 5 and always has non-zero value, -A5z
            means alloca is in address space 5 and may have zero value.<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="color:windowtext"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span style="color:windowtext">Then we can
            add function DataLayout::isAllocaPtrValueNonZero() to check
            whether alloca always has non-zero value.</span></p>
      </div>
    </blockquote>
    <br>
    I believe that we should phrase this in a way not directly connected
    to alloca, but to dereferenceability. We currently assume that
    dereferenceable pointers can't be null in address space 0, but we
    don't make that assumption about other address spaces (where null
    might be a valid address). I think that we should address this
    problem, and then simply apply the result to alloca.<br>
    <br>
    We currently have, for address spaces:<br>
    <br>
    <blockquote type="cite">
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <dt style="color: rgb(0, 0, 0); font-family: "Lucida
        Grande", "Lucida Sans Unicode", Geneva, Verdana,
        sans-serif; font-size: 14px; font-style: normal;
        font-variant-ligatures: normal; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: left; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
        255); text-decoration-style: initial; text-decoration-color:
        initial;"><code class="docutils literal" style="font-family:
          Consolas, "Deja Vu Sans Mono", "Bitstream Vera
          Sans Mono", monospace; font-size: 0.95em;"><span
            class="pre" style="hyphens: none;">p[n]:<size>:<abi>:<pref></span></code></dt>
      <dd style="margin-top: 3px; margin-bottom: 10px; margin-left:
        30px; color: rgb(0, 0, 0); font-family: "Lucida
        Grande", "Lucida Sans Unicode", Geneva, Verdana,
        sans-serif; font-size: 14px; font-style: normal;
        font-variant-ligatures: normal; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: left; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
        255); text-decoration-style: initial; text-decoration-color:
        initial;">This specifies the<span> </span><em>size</em><span> </span>of
        a pointer and its<span> </span><code class="docutils literal"
          style="font-family: Consolas, "Deja Vu Sans Mono",
          "Bitstream Vera Sans Mono", monospace; font-size:
          0.95em;"><span class="pre" style="hyphens: none;"><abi></span></code><span> </span>and<span> </span><code
          class="docutils literal" style="font-family: Consolas,
          "Deja Vu Sans Mono", "Bitstream Vera Sans
          Mono", monospace; font-size: 0.95em;"><span class="pre"
            style="hyphens: none;"><pref></span></code>erred
        alignments for address space<span> </span><code class="docutils
          literal" style="font-family: Consolas, "Deja Vu Sans
          Mono", "Bitstream Vera Sans Mono", monospace;
          font-size: 0.95em;"><span class="pre" style="hyphens: none;">n</span></code>.
        All sizes are in bits. The address space,<span> </span><code
          class="docutils literal" style="font-family: Consolas,
          "Deja Vu Sans Mono", "Bitstream Vera Sans
          Mono", monospace; font-size: 0.95em;"><span class="pre"
            style="hyphens: none;">n</span></code>, is optional, and if
        not specified, denotes the default address space 0. The value of<span> </span><code
          class="docutils literal" style="font-family: Consolas,
          "Deja Vu Sans Mono", "Bitstream Vera Sans
          Mono", monospace; font-size: 0.95em;"><span class="pre"
            style="hyphens: none;">n</span></code><span> </span>must be
        in the range [1,2^23).</dd>
    </blockquote>
    <br>
    How about we allow the addition of 'n' (for non-zero) after the
    address-space number. This, implied by default for address space
    zero but not others, will imply that dereferenceable address are
    non-null. We can then apply this in isKnownNonZero in the places
    where we currently check for address space zero.<br>
    <br>
    Would that address your use case? Or can you have null
    dereferenceable pointers in that address space, just not ones from
    alloca?<br>
    <br>
     -Hal<br>
    <br>
    <blockquote
cite="mid:DM5PR1201MB025265404523BC1587CB2AD7F80A0@DM5PR1201MB0252.namprd12.prod.outlook.com"
      type="cite">
      <div class="WordSection1">
        <p class="MsoNormal"><span style="color:windowtext"><o:p></o:p></span></p>
        <p class="MsoNormal"><span style="color:windowtext"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span style="color:windowtext">Sam<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="color:windowtext"><o:p> </o:p></span></p>
        <div>
          <div style="border:none;border-top:solid #E1E1E1
            1.0pt;padding:3.0pt 0in 0in 0in">
            <p class="MsoNormal"><b><span style="color:windowtext">From:</span></b><span
                style="color:windowtext"> Hal Finkel
                [<a class="moz-txt-link-freetext" href="mailto:hfinkel@anl.gov">mailto:hfinkel@anl.gov</a>]
                <br>
                <b>Sent:</b> Thursday, December 14, 2017 4:06 PM<br>
                <b>To:</b> Liu, Yaxun (Sam) <a class="moz-txt-link-rfc2396E" href="mailto:Yaxun.Liu@amd.com"><Yaxun.Liu@amd.com></a>;
                llvm-dev <a class="moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org"><llvm-dev@lists.llvm.org></a><br>
                <b>Subject:</b> Re: [llvm-dev] [RFC] Add
                TargetTransformInfo::isAllocaPtrValueNonZero and let
                ValueTracking depend on TargetTransformInfo<o:p></o:p></span></p>
          </div>
        </div>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p>Hi, Sam,<o:p></o:p></p>
        <p>Our general design has been that TTI is for cost modeling,
          not for providing semantic information. This piece of
          information can go in DataLayout, and I think we should put it
          there. Especially given that this affects our canonicalization
          process, or preference should be to avoid TTI. The more than
          TTI affects our canonical form, the more fragmented it
          becomes, and the harder it is to understand. Putting it in
          DataLayout also prevents us from having to propagate TTI into
          a bunch of ValueTracking functions (and maximally retains our
          ability to process IR without backends compiled in).<o:p></o:p></p>
        <p class="MsoNormal" style="margin-bottom:12.0pt">Thanks again,<br>
          Hal<o:p></o:p></p>
        <div>
          <p class="MsoNormal">On 12/14/2017 02:32 PM, Liu, Yaxun (Sam)
            via llvm-dev wrote:<o:p></o:p></p>
        </div>
        <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
          <p class="MsoNormal">Some optimizations depend on whether
            alloca instruction always has non-zero value. Currently,
            this checking is done by
            <span style="font-size:10.0pt">isKnownNonZero() in
              ValueTracking, and it assumes alloca in address space 0
              always has non-zero value but alloca in non-zero address
              spaces does not always have non-zero value.</span><o:p></o:p></p>
          <p class="MsoNormal"><span style="font-size:10.0pt"> </span><o:p></o:p></p>
          <p class="MsoNormal"><span style="font-size:10.0pt">However,
              this assumption is incorrect for certain targets. For
              example, amdgcn---amdgiz target has alloca in address
              space 5, and its alloca always has non-zero value. This
              assumption causes some optimizations disabled for
              amdgcn---amdgiz target.</span><o:p></o:p></p>
          <p class="MsoNormal"><span style="font-size:10.0pt"> </span><o:p></o:p></p>
          <p class="MsoNormal">After discussions at <a
              moz-do-not-send="true"
              href="https://reviews.llvm.org/D40670">
              https://reviews.llvm.org/D40670</a>, I propose to
            introduce TargetTransformInfo::isAllocaPtrValueNonZero for
            representing whether alloca instruction always has non-zero
            value, and add a TargetTransformInfo argument to
            ValueTracking functions e.g.
            <span style="font-size:10.0pt">isKnownNonZero().</span><o:p></o:p></p>
          <p class="MsoNormal"><span style="font-size:10.0pt"> </span><o:p></o:p></p>
          <p class="MsoNormal"><span style="font-size:10.0pt">As a
              result, passes using ValueTracking will require
              TargetTransformInfo.</span><o:p></o:p></p>
          <p class="MsoNormal"><span style="font-size:10.0pt"> </span><o:p></o:p></p>
          <p class="MsoNormal"><span style="font-size:10.0pt">Comments
              are welcome.</span><o:p></o:p></p>
          <p class="MsoNormal"><span style="font-size:10.0pt"> </span><o:p></o:p></p>
          <p class="MsoNormal"><span style="font-size:10.0pt">Thanks.</span><o:p></o:p></p>
          <p class="MsoNormal"><span style="font-size:10.0pt"> </span><o:p></o:p></p>
          <p class="MsoNormal"><span style="font-size:10.0pt">Sam</span><o:p></o:p></p>
          <p class="MsoNormal"><br>
            <br>
            <br>
            <o:p></o:p></p>
          <pre>_______________________________________________<o:p></o:p></pre>
          <pre>LLVM Developers mailing list<o:p></o:p></pre>
          <pre><a moz-do-not-send="true" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><o:p></o:p></pre>
          <pre><a moz-do-not-send="true" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></pre>
        </blockquote>
        <p class="MsoNormal"><br>
          <br>
          <o:p></o:p></p>
        <pre>-- <o:p></o:p></pre>
        <pre>Hal Finkel<o:p></o:p></pre>
        <pre>Lead, Compiler Technology and Programming Languages<o:p></o:p></pre>
        <pre>Leadership Computing Facility<o:p></o:p></pre>
        <pre>Argonne National Laboratory<o:p></o:p></pre>
      </div>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
  </body>
</html>