<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - Clang ignores NANs with -ffast-math and -fhonor-nans (or -fno-finite-math-only)"
   href="https://bugs.llvm.org/show_bug.cgi?id=33510">33510</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang ignores NANs with -ffast-math and -fhonor-nans (or -fno-finite-math-only)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.9
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>eborisch@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>## Summary: In contrast with GCC -- and apparently its own internal
## attributes states -- clang ignores NANs when compiling with :
## -ffast-math and (-fhonor-nans or -fno-finite-math-only)

## Test code: (nanfunc.c)

int testfunc(float x) {return x == x;}


## TEST 1: clang -O3 -S -emit-llvm -o - nanfunc.c
## This version checks for NANs (fcmp ord)
## Outputs are trimmed to the interesting parts

define i32 @testfunc(float) local_unnamed_addr #0 {
  %2 = fcmp ord float %0, 0.000000e+00
  %3 = zext i1 %2 to i32
  ret i32 %3
}

attributes #0 = { norecurse nounwind readnone ssp uwtable
"disable-tail-calls"="false" "less-precise-fpmad"="false"
"no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
"no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false"
"no-signed-zeros-fp-math"="false" "stack-protector-buffer-size"="8"
"target-cpu"="core2"
"target-features"="+cx16,+fxsr,+mmx,+sse,+sse2,+sse3,+ssse3,+x87"
"unsafe-fp-math"="false" "use-soft-float"="false" }


## TEST 2: clang -O3 -ffast-math -S -emit-llvm -o - nanfunc.c
## This version converts (x==x) to (1) as expected for no NANs allowed.
## Note all the changes in attributes from -ffast-math, especially
## no-nans-fp-math=true

define i32 @testfunc(float) local_unnamed_addr #0 {
  ret i32 1
}

attributes #0 = { norecurse nounwind readnone ssp uwtable
"disable-tail-calls"="false" "less-precise-fpmad"="false"
"no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
"no-infs-fp-math"="true" "no-jump-tables"="false" "no-nans-fp-math"="true"
"no-signed-zeros-fp-math"="true" "stack-protector-buffer-size"="8"
"target-cpu"="core2"
"target-features"="+cx16,+fxsr,+mmx,+sse,+sse2,+sse3,+ssse3,+x87"
"unsafe-fp-math"="true" "use-soft-float"="false" }


## TEST 2: clang -O3 -ffast-math -fhonor-nans -S -emit-llvm -o - nanfunc.c
## This version still(!) converts (x==x) to (1). Note in the attributes
## that it has parsed the option and set no-nans-fp-math=false, but it
## doesn't seem to have followed that restriction.

define i32 @testfunc(float) local_unnamed_addr #0 {
  ret i32 1
}

attributes #0 = { norecurse nounwind readnone ssp uwtable
"disable-tail-calls"="false" "less-precise-fpmad"="false"
"no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
"no-infs-fp-math"="true" "no-jump-tables"="false" "no-nans-fp-math"="false"
"no-signed-zeros-fp-math"="true" "stack-protector-buffer-size"="8"
"target-cpu"="core2"
"target-features"="+cx16,+fxsr,+mmx,+sse,+sse2,+sse3,+ssse3,+x87"
"unsafe-fp-math"="true" "use-soft-float"="false" }


## TEST 3: clang -O3 -ffast-math -ffinite-math-only -S -emit-llvm -o -
nanfunc.c
## Same functional output as TEST 2; a few additional optimizations
## attributes change (no-infs-fp-math, signed-zeros)

; Function Attrs: norecurse nounwind readnone ssp uwtable
define i32 @testfunc(float) local_unnamed_addr #0 {
  ret i32 1
}

attributes #0 = { norecurse nounwind readnone ssp uwtable
"disable-tail-calls"="false" "less-precise-fpmad"="false"
"no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
"no-infs-fp-math"="true" "no-jump-tables"="false" "no-nans-fp-math"="true"
"no-signed-zeros-fp-math"="true" "stack-protector-buffer-size"="8"
"target-cpu"="core2"
"target-features"="+cx16,+fxsr,+mmx,+sse,+sse2,+sse3,+ssse3,+x87"
"unsafe-fp-math"="true" "use-soft-float"="false" }


## Note: this is different from GCC's behavior, where -ffast-math elides
## the (x==x) check, but '-ffast-math -fno-finite-math-only' does not.</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>