<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - -fno-associative-math is not honored"
   href="https://llvm.org/bugs/show_bug.cgi?id=27372">27372</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-fno-associative-math is not honored
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>warren_ristow@playstation.sony.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Re-association enabled via '-ffast-math' is not suppressed with
'-fno-associative-math'.  Consider the following test-case:

        // -O1 -ffast-math -fno-associative-math
        float foo(float a, float x)
        {
          return ((a + x) - x);
        }

Compiling at -O1, results in an Add and a Subtract, as expected.  Enabling
fast-math, allows re-association to happen, and the arithmetic ops are folded
away, also as expected.  But enabling fast-math while explicitly disabling
associative-math doesn't suppress the re-association (the arithmetic ops are
still folded away).  Specifically:

        $ clang++ --version
        clang version 3.9.0 (trunk 266451)
        Target: x86_64-unknown-linux-gnu
        Thread model: posix
        InstalledDir: /home/warren/llvm/bin
        $ clang++ -c -O1 test.cpp
        $ objdump -d test.o

        test.o:     file format elf64-x86-64
          ...
        0000000000000000 <_Z3fooff>:
           0:   f3 0f 58 c1             addss  %xmm1,%xmm0
           4:   f3 0f 5c c1             subss  %xmm1,%xmm0
           8:   c3                      retq
        $ clang++ -c -O1 -ffast-math test.cpp
        $ objdump -d test.o
          ...
        0000000000000000 <_Z3fooff>:
           0:   c3                      retq
        $ clang++ -c -O1 -ffast-math -fno-associative-math test.cpp
        $ objdump -d test.o
          ...
        0000000000000000 <_Z3fooff>:
           0:   c3                      retq
        $

GCC does honor the '-fno-associative-math' switch (tested with GCC 4.9.2):

        $ g++ -c -O1 test.cpp
        $ objdump -d test.o

        test.o:     file format elf64-x86-64
          ...
        0000000000000000 <_Z3fooff>:
           0:   f3 0f 58 c1             addss  %xmm1,%xmm0
           4:   f3 0f 5c c1             subss  %xmm1,%xmm0
           8:   c3                      retq
        $ g++ -c -O1 -ffast-math test.cpp
        $ objdump -d test.o
          ...
        0000000000000000 <_Z3fooff>:
           0:   f3 c3                   repz retq
        $ g++ -c -O1 -ffast-math -fno-associative-math test.cpp
        $ objdump -d test.o
          ...
        0000000000000000 <_Z3fooff>:
           0:   f3 0f 58 c1             addss  %xmm1,%xmm0
           4:   f3 0f 5c c1             subss  %xmm1,%xmm0
           8:   c3                      retq
        $

This appears to be target-independent behavior (noticed on X86, but tried with
a few other architectures, and observed the same issue).

Also, tested with a handful of Clang versions, and it's a longstanding
behavior.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>