LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 43725 - Bad floating-point "optimizations"
Summary: Bad floating-point "optimizations"
Status: NEW
Alias: None
Product: clang
Classification: Unclassified
Component: C (show other bugs)
Version: 8.0
Hardware: PC Linux
: P enhancement
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-19 19:15 PDT by Fred J. Tydeman
Modified: 2020-07-03 17:59 PDT (History)
6 users (show)

See Also:
Fixed By Commit(s):


Attachments
Command line options for clang to try to get good floating-point conformance (615 bytes, text/plain)
2020-07-03 17:56 PDT, Fred J. Tydeman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Fred J. Tydeman 2019-10-19 19:15:44 PDT
Is there a way to disable ALL "optimizations" related to floating-point?
My testing has shown that clang does the following:
  1. * x  => x
  0. * x  => 0.
  x / 1.  => x
  x / x   => 1.
  0. / x  => 0.
  x + 0.  => x
  x - 0.  => x
  x - x   => 0.
They are all invalid "optimizations" if x is a signaling NaN.
In addition, some are invalid if x is a signed zero or infinity.
In the above, 'x' can be either a variable or a constant.
It might matter if 'x' is float, double, or long double.
Comment 1 Kevin P. Neal 2019-10-23 08:04:11 PDT
Currently clang and llvm assume that floating point generates no side effects. There is work in progress to teach llvm and clang to be strict with floating point so many optimizations don't fire. 

If you want to follow the progress the tickets at reviews.llvm.org tend to have "[FPEnv]" in the name somewhere, and this is sometimes true for the mailing lists as well. See also the "constrained floating point intrinsics" in the Language Reference: https://llvm.org/docs/LangRef.html#constrained-floating-point-intrinsics
Comment 2 Fred J. Tydeman 2019-10-23 09:28:46 PDT
I am glad to see that some work is being done on this issue.
  http://www.tybor.com/tflt2int.c
is a good test case for 
‘llvm.experimental.constrained.fptoui’ Intrinsic
‘llvm.experimental.constrained.fptosi’ Intrinsic

However, it appears to me that those intrinsics would not work for integer bit fields with respect to raising invalid for FP numbers too big to fit.
Comment 3 Kevin P. Neal 2019-10-23 09:35:43 PDT
It is a work in progress. I haven't looked at bitfields, but this ticket may get us closer:

"Add constrained int->FP intrinsics"
https://reviews.llvm.org/D69275
Comment 4 Fred J. Tydeman 2020-07-03 17:56:23 PDT
Created attachment 23677 [details]
Command line options for clang to try to get good floating-point conformance

clang command line options to try to get conformance to IEEE-754 and Standard C.
Comment 5 Fred J. Tydeman 2020-07-03 17:59:23 PDT
With those command line options, the test case
  http://www.tybor.com/tflt2int.c
still is getting 183 failures.

I tried those options after reading bug 8100.  
I tried what it suggested and reporting a bug in that 'fix'.