Bug 68235 - gimple optimisations always use global -fmath-errno setting
Summary: gimple optimisations always use global -fmath-errno setting
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-06 11:02 UTC by Richard Sandiford
Modified: 2018-11-19 13:48 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-11-06 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Sandiford 2015-11-06 11:02:34 UTC
At the moment the ECF_* flags for a gimple call to a built-in
function are derived from the function decl, which in turn is
derived from the global command-line options.  So if the compiler
is run with -fno-math-errno, we always assume functions don't set
errno, regardless of local optimisation options.  Similarly if the
compiler is run with -fmath-errno, we always assume functions set errno.

This shows up in gcc.dg/lto/20110201-1_0.c, where we compile
the file with -O0 and use -O2 -ffast-math for a specific function.
-O2 -ffast-math is enough for us to convert cabs to sqrt as hoped,
but because of the global -fmath-errno setting, we assume that the
call to sqrt is not pure or const and create vops for it.  This makes
it appear to the gimple code that a simple sqrt optab isn't enough.
Comment 1 Richard Biener 2015-11-06 11:33:19 UTC
Confirmed.  The solution for this specific case is to have distinct builtins for
no-math-errno, like __builtin_sqrt_no_math_errno ().

Note that slightly related is -frounding-math which causes math functions
to become pure rather than const (and thus get a VUSE).
Comment 2 Richard Sandiford 2015-11-07 09:59:04 UTC
Author: rsandifo
Date: Sat Nov  7 09:58:32 2015
New Revision: 229917

URL: https://gcc.gnu.org/viewcvs?rev=229917&root=gcc&view=rev
Log:
Add -fno-math-errno to gcc.dg/lto/20110201-1_0.c

At the moment the ECF_* flags for a gimple call to a built-in
function are derived from the function decl, which in turn is
derived from the global command-line options.  So if the compiler
is run with -fno-math-errno, we always assume functions don't set
errno, regardless of local optimization options.  Similarly if the
compiler is run with -fmath-errno, we always assume functions set errno.

This shows up in gcc.dg/lto/20110201-1_0.c, where we compile
the file with -O0 and use -O2 -ffast-math for a specific function.
-O2 -ffast-math is enough for us to convert cabs to sqrt as hoped,
but because of the global -fmath-errno setting, we assume that the
call to sqrt is not pure or const and create vops for it.  This makes
it appear to the gimple code that a simple sqrt optab isn't enough.

Later patches move more decisions about maths functions to gimple
and think that in this case we should use:

        y = sqrt (x);
        if (!(x >= 0))
            sqrt (x); // to set errno.

This is being tracked as PR68235.  For now the patch adds
-fno-math-errno to the dg-options for this test.

Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.

gcc/testsuite/
	PR tree-optimization/68235
	* gcc.dg/lto/20110201-1_0.c: Add -fno-math-errno.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/lto/20110201-1_0.c
Comment 3 Martin Liška 2018-11-19 13:42:51 UTC
Can the bug be marked as resolved?
Comment 4 jsm-csl@polyomino.org.uk 2018-11-19 13:48:02 UTC
I'm not aware of any fix for this bug (the only commit shown is a change 
to testcase options, not a fix).