<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 08/31/2017 04:31 PM, Richard Smith
      via cfe-dev wrote:<br>
    </div>
    <blockquote
cite="mid:CAOfiQqnZOvWcZhmym32dmFrXFGPcW=tTZasSCDhz61zCKFtDcw@mail.gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <div dir="ltr">I think that's also not enough; you'd get the same
        problem after inlining, and across modules with LTO. You would
        need to also prevent any interprocedural code motion across a
        FENV_ACCESS / non-FENV_ACCESS boundary.</div>
    </blockquote>
    <br>
    Or we prevent inlining. <br>
    <br>
    <blockquote
cite="mid:CAOfiQqnZOvWcZhmym32dmFrXFGPcW=tTZasSCDhz61zCKFtDcw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div><br>
        </div>
        <div>And even that doesn't seem to be enough. Suppose that some
          scalar optimization pass finds a clever way to converts some
          integer operation into a floating-point operation, such that
          it can prove that the FP values never overflow (I believe
          Chandler has an example of this that comes up in some real
          crypto code). Now suppose there's a case where the integer
          operands are undef, but that the code in question is bypassed
          in that case. If the FP operations get hoisted, and you happen
          to have FP exceptions enabled, you have a potential
          miscompile.</div>
      </div>
    </blockquote>
    <br>
    Good point. However, that's not a new problem, and we currently deal
    with this by respecting the noimplicitfloat attribute (and I think
    we'd definitely need to use that attribute if we allow fooling with
    the FP environment).<br>
    <br>
     -Hal<br>
    <br>
    <blockquote
cite="mid:CAOfiQqnZOvWcZhmym32dmFrXFGPcW=tTZasSCDhz61zCKFtDcw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div><br>
          </div>
          <div>Fundamentally, it seems to me that feenableexcept is
            unsound in the current LLVM IR model of floating point, if
            we assume that fadd, fmul, fsub etc do not have
            side-effects.
            <div class="gmail_extra"><br>
              <div class="gmail_quote">On 31 August 2017 at 14:20,
                Kaylor, Andrew via cfe-dev <span dir="ltr"><<a
                    moz-do-not-send="true"
                    href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-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 link="blue" vlink="purple" lang="EN-US">
                    <div class="m_-2075974219545047674WordSection1">
                      <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">If
                          that’s the case, we may need to use the
                          constrained intrinsics for all FP operations
                          when FENV_ACCESS is enabled anywhere in a
                          function.</span></p>
                      <p class="MsoNormal"><a moz-do-not-send="true"
                          name="m_-2075974219545047674__MailEndCompose"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span></a></p>
                      <p class="MsoNormal"><b><span
                            style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif">
                          Richard Smith [mailto:<a
                            moz-do-not-send="true"
                            href="mailto:richard@metafoo.co.uk"
                            target="_blank">richard@metafoo.co.uk</a>]
                          <br>
                          <b>Sent:</b> Thursday, August 31, 2017 2:18 PM<br>
                          <b>To:</b> Kaylor, Andrew <<a
                            moz-do-not-send="true"
                            href="mailto:andrew.kaylor@intel.com"
                            target="_blank">andrew.kaylor@intel.com</a>><br>
                          <b>Cc:</b> Clang Dev <<a
                            moz-do-not-send="true"
                            href="mailto:cfe-dev@lists.llvm.org"
                            target="_blank">cfe-dev@lists.llvm.org</a>>;
                          Marcus Johnson <<a moz-do-not-send="true"
                            href="mailto:bumblebritches57@gmail.com"
                            target="_blank">bumblebritches57@gmail.com</a>>;
                          <a moz-do-not-send="true"
                            href="mailto:wei.ding2@amd.com"
                            target="_blank">wei.ding2@amd.com</a></span></p>
                      <div>
                        <div class="h5"><br>
                          <b>Subject:</b> Re: [cfe-dev] Why is #pragma
                          STDC FENV_ACCESS not supported?</div>
                      </div>
                      <div>
                        <div class="h5">
                          <p class="MsoNormal"> </p>
                          <div>
                            <div>
                              <div>
                                <p class="MsoNormal">On 31 August 2017
                                  at 14:14, Kaylor, Andrew via cfe-dev
                                  <<a moz-do-not-send="true"
                                    href="mailto:cfe-dev@lists.llvm.org"
                                    target="_blank">cfe-dev@lists.llvm.org</a>>
                                  wrote:</p>
                                <blockquote
                                  style="border:none;border-left:solid
                                  #cccccc 1.0pt;padding:0in 0in 0in
                                  6.0pt;margin-left:4.8pt;margin-right:0in">
                                  <div>
                                    <div>
                                      <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">I
                                          believe that we will rely on
                                          fedisableexcept() being marked
                                          as having unmodeled
                                          side-effects to prevent a
                                          hoist like that.</span></p>
                                    </div>
                                  </div>
                                </blockquote>
                                <div>
                                  <p class="MsoNormal"> </p>
                                </div>
                                <div>
                                  <p class="MsoNormal">fadd can be
                                    hoisted past *anything*, can't it?</p>
                                </div>
                                <div>
                                  <p class="MsoNormal"><a
                                      moz-do-not-send="true"
                                      name="m_-2075974219545047674_m_2724022782041152477__MailEndCompose"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span></a></p>
                                </div>
                                <blockquote
                                  style="border:none;border-left:solid
                                  #cccccc 1.0pt;padding:0in 0in 0in
                                  6.0pt;margin-left:4.8pt;margin-right:0in">
                                  <div>
                                    <div>
                                      <p class="MsoNormal"><b><span
                                            style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif">
                                          Richard Smith [mailto:<a
                                            moz-do-not-send="true"
                                            href="mailto:richard@metafoo.co.uk"
                                            target="_blank">richard@metafoo.co.uk</a>]
                                          <br>
                                          <b>Sent:</b> Thursday, August
                                          31, 2017 2:09 PM<br>
                                          <b>To:</b> Kaylor, Andrew <<a
                                            moz-do-not-send="true"
                                            href="mailto:andrew.kaylor@intel.com"
                                            target="_blank">andrew.kaylor@intel.com</a>><br>
                                          <b>Cc:</b> Marcus Johnson <<a
                                            moz-do-not-send="true"
                                            href="mailto:bumblebritches57@gmail.com"
                                            target="_blank">bumblebritches57@gmail.com</a>>;
                                          Clang Dev <<a
                                            moz-do-not-send="true"
                                            href="mailto:cfe-dev@lists.llvm.org"
                                            target="_blank">cfe-dev@lists.llvm.org</a>>;
                                          <a moz-do-not-send="true"
                                            href="mailto:wei.ding2@amd.com"
                                            target="_blank">wei.ding2@amd.com</a></span></p>
                                      <div>
                                        <div>
                                          <p class="MsoNormal"><br>
                                            <b>Subject:</b> Re:
                                            [cfe-dev] Why is #pragma
                                            STDC FENV_ACCESS not
                                            supported?</p>
                                        </div>
                                      </div>
                                      <div>
                                        <div>
                                          <p class="MsoNormal"> </p>
                                          <div>
                                            <div>
                                              <div>
                                                <p class="MsoNormal">On
                                                  31 August 2017 at
                                                  11:09, Kaylor, Andrew
                                                  via cfe-dev <<a
                                                    moz-do-not-send="true"
href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>>
                                                  wrote:</p>
                                                <blockquote
                                                  style="border:none;border-left:solid
                                                  #cccccc
                                                  1.0pt;padding:0in 0in
                                                  0in
6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
                                                  <div>
                                                    <div>
                                                      <p
                                                        class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">There
                                                          are still a
                                                          few things
                                                          missing from
                                                          the optimizer
                                                          to get it
                                                          completely
                                                          robust, but I
                                                          think there is
                                                          enough in
                                                          place for
                                                          front end work
                                                          to begin.  As
                                                          I think I’ve
                                                          demonstrated
                                                          in my recent
                                                          attempt to
                                                          contribute a
                                                          clang patch
                                                          I’m not
                                                          skilled enough
                                                          with the front
                                                          end to be the
                                                          person to pull
                                                          this off
                                                          without an
                                                          excessive
                                                          amount of
                                                          oversight, but
                                                          as Erich
                                                          indicated we
                                                          do have some
                                                          good front end
                                                          people here
                                                          who have this
                                                          on their TODO
                                                          list.  It’s
                                                          just not at
                                                          the top of the
                                                          TODO list yet.</span></p>
                                                      <p
                                                        class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span></p>
                                                      <p
                                                        class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">If
                                                          anyone is
                                                          interested in
                                                          the details of
                                                          the LLVM side
                                                          of things,
                                                          there are
                                                          constrained FP
                                                          intrinisics
                                                          (still marked
                                                          as
                                                          experimental
                                                          at this point)
                                                          documented in
                                                          the language
                                                          reference. 
                                                          The initial
                                                          patch can be
                                                          seen here:</span></p>
                                                      <p
                                                        class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span></p>
                                                      <p
                                                        class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><a
moz-do-not-send="true" href="https://reviews.llvm.org/D27028"
                                                          target="_blank">https://reviews.llvm.org/<wbr>D27028</a></span></p>
                                                      <p
                                                        class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span></p>
                                                      <p
                                                        class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">I’ve
                                                          since added
                                                          another group
                                                          of intrinsics
                                                          to handle the
libm-equivalent intrinsics, and more recently Wei Ding contributed an
                                                          fma intrinsic.</span></p>
                                                      <p
                                                        class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span></p>
                                                      <p
                                                        class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">The
                                                          idea is that
                                                          the front end
                                                          will emit the
                                                          constrained
                                                          intrinsics in
                                                          place of
                                                          equivalent
                                                          general FP
                                                          operations or
                                                          intrinsics in
                                                          scopes where
                                                          FENV_ACCESS is
                                                          enabled.  This
                                                          will prevent
                                                          the optimizer
                                                          from making
                                                          optimizations
                                                          that assume
                                                          default fenv
                                                          settings
                                                          (which is what
                                                          we want the
                                                          optimizer to
                                                          do in all
                                                          other cases). 
                                                          Eventually,
                                                          we’ll want to
                                                          go back and
                                                          teach specific
                                                          optimizations
                                                          to understand
                                                          the intrinsics
                                                          so that where
                                                          possible
                                                          optimizations
                                                          can be
                                                          performed in a
                                                          manner
                                                          consistent
                                                          with dynamic
                                                          rounding modes
                                                          and strict
                                                          exception
                                                          handling.</span></p>
                                                    </div>
                                                  </div>
                                                </blockquote>
                                                <div>
                                                  <p class="MsoNormal"> </p>
                                                </div>
                                                <div>
                                                  <div>
                                                    <p class="MsoNormal"><span
style="font-size:9.5pt">How do you deal with the hoisting-into-<span
                                                          class="m_-2075974219545047674m2724022782041152477gmail-il">fenv_access</span> <wbr>problem?
                                                        Eg:</span></p>
                                                  </div>
                                                  <div>
                                                    <p class="MsoNormal"><span
style="font-size:9.5pt"> </span></p>
                                                  </div>
                                                  <div>
                                                    <p class="MsoNormal"><span
style="font-size:9.5pt">double f(double a, double b, double c) {</span></p>
                                                  </div>
                                                  <div>
                                                    <p class="MsoNormal"><span
style="font-size:9.5pt">  {</span></p>
                                                  </div>
                                                  <div>
                                                    <p class="MsoNormal"><span
style="font-size:9.5pt">#pragma STDC <span
                                                          class="m_-2075974219545047674m2724022782041152477gmail-il">FENV_ACCESS</span> ON</span></p>
                                                  </div>
                                                  <div>
                                                    <p class="MsoNormal"><span
style="font-size:9.5pt">    feenableexcept(FE_OVERFLOW);</span></p>
                                                  </div>
                                                  <div>
                                                    <p class="MsoNormal"><span
style="font-size:9.5pt">    double d = a * b;</span></p>
                                                  </div>
                                                  <div>
                                                    <p class="MsoNormal"><span
style="font-size:9.5pt">    fedisableexcept(FE_OVERFLOW);</span></p>
                                                  </div>
                                                  <div>
                                                    <p class="MsoNormal"><span
style="font-size:9.5pt">  }</span></p>
                                                  </div>
                                                  <div>
                                                    <p class="MsoNormal"><span
style="font-size:9.5pt">  return c * d;</span></p>
                                                  </div>
                                                  <div>
                                                    <p class="MsoNormal"><span
style="font-size:9.5pt">}</span></p>
                                                  </div>
                                                  <div>
                                                    <p class="MsoNormal"><span
style="font-size:9.5pt"> </span></p>
                                                  </div>
                                                  <div>
                                                    <p class="MsoNormal"><span
style="font-size:9.5pt">What stops llvm from hoisting the second fmul up
                                                        to before the
                                                        fedisableexcept?</span></p>
                                                  </div>
                                                </div>
                                                <div>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span></p>
                                                </div>
                                                <blockquote
                                                  style="border:none;border-left:solid
                                                  #cccccc
                                                  1.0pt;padding:0in 0in
                                                  0in
6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
                                                  <div>
                                                    <div>
                                                      <p
                                                        class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">-Andy</span></p>
                                                      <p
                                                        class="MsoNormal"><a
moz-do-not-send="true"
                                                          name="m_-2075974219545047674_m_2724022782041152477_m_1667421056975128"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span></a></p>
                                                      <div>
                                                        <div
                                                          style="border:none;border-top:solid
                                                          #e1e1e1
                                                          1.0pt;padding:3.0pt
                                                          0in 0in 0in">
                                                          <p
                                                          class="MsoNormal"><b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Hal
                                                          Finkel
                                                          [mailto:<a
                                                          moz-do-not-send="true"
href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>]
                                                          <br>
                                                          <b>Sent:</b>
                                                          Thursday,
                                                          August 31,
                                                          2017 10:45 AM<br>
                                                          <b>To:</b>
                                                          Richard Smith
                                                          <<a
                                                          moz-do-not-send="true"
href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>>;
                                                          Marcus Johnson
                                                          <<a
                                                          moz-do-not-send="true"
href="mailto:bumblebritches57@gmail.com" target="_blank">bumblebritches57@gmail.com</a>><br>
                                                          <b>Cc:</b>
                                                          Clang Dev <<a
moz-do-not-send="true" href="mailto:cfe-dev@lists.llvm.org"
                                                          target="_blank">cfe-dev@lists.llvm.org</a>>;
                                                          Kaylor, Andrew
                                                          <<a
                                                          moz-do-not-send="true"
href="mailto:andrew.kaylor@intel.com" target="_blank">andrew.kaylor@intel.com</a>><br>
                                                          <b>Subject:</b>
                                                          Re: [cfe-dev]
                                                          Why is #pragma
                                                          STDC
                                                          FENV_ACCESS
                                                          not supported?</span></p>
                                                        </div>
                                                      </div>
                                                      <div>
                                                        <div>
                                                          <p
                                                          class="MsoNormal"> </p>
                                                          <p> </p>
                                                          <div>
                                                          <p
                                                          class="MsoNormal">On
                                                          08/31/2017
                                                          12:10 PM,
                                                          Richard Smith
                                                          via cfe-dev
                                                          wrote:</p>
                                                          </div>
                                                          <blockquote
                                                          style="margin-top:5.0pt;margin-bottom:5.0pt">
                                                          <div>
                                                          <p
                                                          class="MsoNormal">Because
                                                          no-one has
                                                          implemented
                                                          it. Patches
                                                          would be
                                                          welcome, but
                                                          will need to
                                                          start with a
                                                          design and
                                                          implementation
                                                          of the
                                                          requisite llvm
                                                          extensions.</p>
                                                          </div>
                                                          </blockquote>
                                                          <p
                                                          class="MsoNormal"
style="margin-bottom:12.0pt"><br>
                                                          Yes. This is
                                                          what Andrew
                                                          Kaylor has
                                                          been working
                                                          on (cc'd).<br>
                                                          <br>
                                                           -Hal</p>
                                                          <blockquote
                                                          style="margin-top:5.0pt;margin-bottom:5.0pt">
                                                          <div>
                                                          <p
                                                          class="MsoNormal"> </p>
                                                          <div>
                                                          <p
                                                          class="MsoNormal">On
                                                          31 Aug 2017
                                                          10:06, "Marcus
                                                          Johnson via
                                                          cfe-dev" <<a
moz-do-not-send="true" href="mailto:cfe-dev@lists.llvm.org"
                                                          target="_blank">cfe-dev@lists.llvm.org</a>>
                                                          wrote:</p>
                                                          <blockquote
                                                          style="border:none;border-left:solid
                                                          #cccccc
                                                          1.0pt;padding:0in
                                                          0in 0in
6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
                                                          <div>
                                                          <div>
                                                          <p
                                                          class="MsoNormal"><span
style="font-size:18.0pt">^^^^^^</span></p>
                                                          </div>
                                                          </div>
                                                          <p
                                                          class="MsoNormal"
style="margin-bottom:12.0pt"><br>
______________________________<wbr>_________________<br>
                                                          cfe-dev
                                                          mailing list<br>
                                                          <a
                                                          moz-do-not-send="true"
href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
                                                          <a
                                                          moz-do-not-send="true"
href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev"
                                                          target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a></p>
                                                          </blockquote>
                                                          </div>
                                                          </div>
                                                          <p
                                                          class="MsoNormal"
style="margin-bottom:12.0pt"> </p>
                                                          <pre>______________________________<wbr>_________________</pre>
<pre>cfe-dev mailing list</pre>
<pre><a moz-do-not-send="true" href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a></pre>
<pre><a moz-do-not-send="true" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a></pre>
</blockquote>
<p class="MsoNormal" style="margin-bottom:12.0pt"> </p>
<pre>-- </pre>
<pre>Hal Finkel</pre>
<pre>Lead, Compiler Technology and Programming Languages</pre>
<pre>Leadership Computing Facility</pre>
<pre>Argonne National Laboratory</pre>
</div>
</div>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">

______________________________<wbr>_________________

cfe-dev mailing list

<a moz-do-not-send="true" href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>

<a moz-do-not-send="true" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a></p>
</blockquote>
</div>
<p class="MsoNormal"> </p>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">

______________________________<wbr>_________________

cfe-dev mailing list

<a moz-do-not-send="true" href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>

<a moz-do-not-send="true" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a></p>
</blockquote>
</div>
<p class="MsoNormal"> </p>
</div>
</div>
</div></div></div>
</div>


______________________________<wbr>_________________

cfe-dev mailing list

<a moz-do-not-send="true" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>

<a moz-do-not-send="true" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a>


</blockquote></div>
</div></div></div></div>


<fieldset class="mimeAttachmentHeader"></fieldset>
<pre wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>

</blockquote>
<pre class="moz-signature" cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre></body></html>