[llvm-bugs] [Bug 33510] New: Clang ignores NANs with -ffast-math and -fhonor-nans (or -fno-finite-math-only)

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 19 08:37:51 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=33510

            Bug ID: 33510
           Summary: Clang ignores NANs with -ffast-math and -fhonor-nans
                    (or -fno-finite-math-only)
           Product: clang
           Version: 3.9
          Hardware: Macintosh
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: eborisch at gmail.com
                CC: llvm-bugs at lists.llvm.org

## 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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170619/6f3c61c2/attachment.html>


More information about the llvm-bugs mailing list