<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 7/14/20 11:28 AM, Fangqing Du wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CAKg0ixx5PM_eWtY4SY3dYmwiCpOfs7iZc5uCwYjvv5b5qjNSxA@mail.gmail.com">
      
      <div dir="ltr">Thank you Hal and 
        Stefan!
        <div><br>
        </div>
        <div>Bug report is filed: <a href="https://bugs.llvm.org/show_bug.cgi?id=46717" moz-do-not-send="true">https://bugs.llvm.org/show_bug.cgi?id=46717</a></div>
        <div><br>
        </div>
        <div>And Stefan,</div>
        <div>I think 'attributor' is a really nice pass, and can infer
          more precise and useful attributes, which may give more
          opportunities for optimization.</div>
        <div>But we shouldn't depend on 'attributor' to correct wrong
          function attributes, because we cannot run 'attributor' after
          every pass, right?</div>
      </div>
    </blockquote>
    <p>Correct. Each pass must be correct on its own. We need to fix
      ipsccp.</p>
    <p> -Hal<br>
    </p>
    <p><br>
    </p>
    <blockquote type="cite" cite="mid:CAKg0ixx5PM_eWtY4SY3dYmwiCpOfs7iZc5uCwYjvv5b5qjNSxA@mail.gmail.com">
      <div dir="ltr">
        <div><br>
        </div>
        <div>Thanks,</div>
        <div>Fangqing</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Sat, Jul 11, 2020 at 5:12
          AM Hal Finkel <<a href="mailto:hfinkel@anl.gov" moz-do-not-send="true">hfinkel@anl.gov</a>> wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div>
            <p>Hi, Fangqing,</p>
            <p>Yes, this seems like a bug. Can you please file a bug
              report at <a href="https://bugs.llvm.org/" target="_blank" moz-do-not-send="true">https://bugs.llvm.org/</a>
              ? If you need someone else to do this on your behalf,
              please let us know.</p>
            <p> -Hal<br>
            </p>
            <div>On 7/10/20 9:04 PM, Fangqing Du via llvm-dev wrote:<br>
            </div>
            <blockquote type="cite">
              <div dir="ltr">Hi all,
                <div><br>
                </div>
                <div>Let's see an example (from Alexandre Isoard) first:</div>
                <div>****************************************************************************************</div>
                <div><font face="monospace" color="#666666">; RUN: opt
                    -ipsccp -deadargelim -licm -O2 -S < %s<br>
                    <br>
                  </font>
                  <div style="color:rgb(0,0,0);background-color:rgb(255,255,254)">
                    <div><font face="monospace"><span style="color:rgb(0,17,136)">@g</span> = <span style="color:rgb(0,0,255)">internal</span> <span style="color:rgb(0,0,255)">global</span> <span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(9,134,88)">0</span></font></div>
                    <font face="monospace"><br>
                    </font>
                    <div><span style="color:rgb(0,128,0)"><font face="monospace">; Function Attrs: argmemonly</font></span></div>
                    <div><font face="monospace"><span style="color:rgb(0,0,255)">define</span> <span style="color:rgb(0,0,255)">internal</span> <span style="color:rgb(0,128,128)">void</span> <span style="color:rgb(0,17,136)">@foo</span>(<span style="color:rgb(0,128,128)">i32*</span> <span style="color:rgb(0,0,255)">nonnull</span> <span style="color:rgb(0,0,255)">dereferenceable</span>(<span style="color:rgb(9,134,88)">4</span>) <span style="color:rgb(0,17,136)">%arg</span>, <span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(0,17,136)">%val</span>) #<span style="color:rgb(9,134,88)">0</span> {</font></div>
                    <div><span style="color:rgb(128,0,0)"><font face="monospace">entry:</font></span></div>
                    <div><font face="monospace">  store <span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(0,17,136)">%val</span>, <span style="color:rgb(0,128,128)">i32*</span> <span style="color:rgb(0,17,136)">%arg</span></font></div>
                    <div><font face="monospace">  ret <span style="color:rgb(0,128,128)">void</span></font></div>
                    <div><font face="monospace">}</font></div>
                    <font face="monospace"><br>
                    </font>
                    <div><font face="monospace"><span style="color:rgb(0,0,255)">define</span> <span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(0,17,136)">@bar</span>(<span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(0,17,136)">%n</span>) {</font></div>
                    <div><span style="color:rgb(128,0,0)"><font face="monospace">entry:</font></span></div>
                    <div><font face="monospace">  store <span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(9,134,88)">1</span>, <span style="color:rgb(0,128,128)">i32*</span> <span style="color:rgb(0,17,136)">@g</span></font></div>
                    <div><font face="monospace">  br <span style="color:rgb(0,128,128)">label</span> <span style="color:rgb(0,17,136)">%loop</span></font></div>
                    <font face="monospace"><br>
                    </font>
                    <div><font face="monospace"><span style="color:rgb(128,0,0)">loop:</span>                                              <span style="color:rgb(0,128,0)">; preds = %bb1, %bb</span></font></div>
                    <div><font face="monospace">  <span style="color:rgb(0,17,136)">%i</span> = phi <span style="color:rgb(0,128,128)">i32</span> [ <span style="color:rgb(0,17,136)">%i.inc</span>, <span style="color:rgb(0,17,136)">%loop</span> ], [ <span style="color:rgb(9,134,88)">0</span>, <span style="color:rgb(0,17,136)">%entry</span> ]</font></div>
                    <div><font face="monospace">  <span style="color:rgb(0,17,136)">%g.val</span> = load <span style="color:rgb(0,128,128)">i32</span>, <span style="color:rgb(0,128,128)">i32*</span> <span style="color:rgb(0,17,136)">@g</span></font></div>
                    <div><font face="monospace">  <span style="color:rgb(0,17,136)">%g.inc</span> = add nuw <span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(0,17,136)">%g.val</span>, <span style="color:rgb(9,134,88)">1</span></font></div>
                    <div><font face="monospace">  <span style="color:rgb(0,0,255)">tail</span> call <span style="color:rgb(0,128,128)">void</span> <span style="color:rgb(0,17,136)">@foo</span>(<span style="color:rgb(0,128,128)">i32*</span> <span style="color:rgb(0,17,136)">@g</span>, <span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(0,17,136)">%g.inc</span>)</font></div>
                    <div><font face="monospace">  <span style="color:rgb(0,17,136)">%i.inc</span> = add nuw <span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(0,17,136)">%i</span>, <span style="color:rgb(9,134,88)">1</span></font></div>
                    <div><font face="monospace">  <span style="color:rgb(0,17,136)">%cond</span> = icmp eq <span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(0,17,136)">%i.inc</span>, <span style="color:rgb(0,17,136)">%n</span></font></div>
                    <div><font face="monospace">  br <span style="color:rgb(0,128,128)">i1</span> <span style="color:rgb(0,17,136)">%cond</span>, <span style="color:rgb(0,128,128)">label</span> <span style="color:rgb(0,17,136)">%exit</span>, <span style="color:rgb(0,128,128)">label</span> <span style="color:rgb(0,17,136)">%loop</span></font></div>
                    <font face="monospace"><br>
                    </font>
                    <div><font face="monospace"><span style="color:rgb(128,0,0)">exit:</span>                                              <span style="color:rgb(0,128,0)">; preds = %bb1</span></font></div>
                    <div><font face="monospace">  ret <span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(0,17,136)">%g.val</span></font></div>
                    <div><font face="monospace">}</font></div>
                    <font face="monospace"><br>
                    </font>
                    <div><font face="monospace"><span style="color:rgb(0,0,255)">declare</span> <span style="color:rgb(0,128,128)">void</span> <span style="color:rgb(0,17,136)">@llvm.assume</span>(<span style="color:rgb(0,128,128)">i1</span>)</font></div>
                    <font face="monospace"><br>
                    </font>
                    <div><font face="monospace">attributes #<span style="color:rgb(9,134,88)">0</span> = { <span style="color:rgb(0,0,255)">argmemonly</span> }</font></div>
                  </div>
                </div>
                <div>****************************************************************************************  <br>
                </div>
                <div>With opt cmd '-ipsccp -deadargelim -licm -O2',
                  function @bar will return constant value 1, instead of
                  correct value %n. This is crazy, right?</div>
                <div>Let's see what happens here.</div>
                <div>Due to pass 'ipsccp' replaced the argument of
                  function '@foo' with global variable '@g', but keeps
                  attr 'argmemonly' there, so pass 'licm' will hoist the
                  load of '@g' before the loop (as the value of @g isn't
                  changed, but it is changed), and will cause function
                  return wrong constant value '1', instead of '%n' (the
                  correct value) , like following:<br>
                </div>
                <div>**************************************************************************************** 
                    <br>
                </div>
                <div>
                  <div style="color:rgb(0,0,0);background-color:rgb(255,255,254)">
                    <div><span style="color:rgb(0,128,0)"><font face="monospace">; Function Attrs: nofree norecurse nounwind writeonly</font></span></div>
                    <div><font face="monospace"><span style="color:rgb(0,0,255)">define</span> <span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(0,128,128)">@bar</span>(<span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(0,128,128)">%n</span>) <span style="color:rgb(0,128,128)">local_unnamed_addr</span> <span style="color:rgb(9,134,88)">#0</span> {</font></div>
                    <div><span style="color:rgb(0,128,128)"><font face="monospace">entry:</font></span></div>
                    <div><font face="monospace">  <span style="color:rgb(0,0,255)">ret</span> <span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(9,134,88)">1</span></font></div>
                    <div><font face="monospace">}</font></div>
                    <font face="monospace"><br>
                    </font>
                    <div><font face="monospace"><span style="color:rgb(0,128,128)">attributes #0 =</span> { <span style="color:rgb(0,128,128)">nofree</span> <span style="color:rgb(0,128,128)">norecurse</span> <span style="color:rgb(0,128,128)">nounwind</span> <span style="color:rgb(0,128,128)">writeonly</span> }</font></div>
                  </div>
                </div>
                <div>**************************************************************************************** 
                    <br>
                </div>
                <div><br>
                </div>
                <div>And if remove the 'argmemonly' attribute,
                  function @bar will return the correct value:</div>
                <div>
                  <div>**************************************************************************************** 
                      <br>
                  </div>
                  <div>
                    <div style="color:rgb(0,0,0);background-color:rgb(255,255,254)">
                      <div>
                        <div><span style="color:rgb(0,128,0)"><font face="monospace">; Function Attrs: nofree norecurse nounwind</font></span></div>
                        <div><font face="monospace"><span style="color:rgb(0,0,255)">define</span> <span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(0,128,128)">@bar</span>(<span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(0,128,128)">%n</span>) <span style="color:rgb(0,128,128)">local_unnamed_addr</span> <span style="color:rgb(9,134,88)">#0</span> {</font></div>
                        <div><span style="color:rgb(0,128,128)"><font face="monospace">entry:</font></span></div>
                        <div><font face="monospace">  <span style="color:rgb(0,0,255)">ret</span> <span style="color:rgb(0,128,128)">i32</span> <span style="color:rgb(0,128,128)">%n</span></font></div>
                        <div><font face="monospace">}</font></div>
                      </div>
                    </div>
                  </div>
                  <div>**************************************************************************************** 
                      </div>
                </div>
                <div><br>
                </div>
                <div>So if function attribute 'argmemonly' on
                  function @foo is correct, then there's a bug in pass
                  'ipsccp'. When it replaces the function local value
                  with global variable, then it shoud remember to remove
                  this function attribute.</div>
                <div><br>
                </div>
                <div>Thanks,</div>
                <div>Fangqing</div>
              </div>
              <br>
              <fieldset></fieldset>
              <pre>_______________________________________________
LLVM Developers mailing list
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" moz-do-not-send="true">llvm-dev@lists.llvm.org</a>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank" moz-do-not-send="true">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
            </blockquote>
            <pre cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
          </div>
        </blockquote>
      </div>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
  </body>
</html>