public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/63401] New: "optimize" attribute overwrites other options
@ 2014-09-28 22:08 fxcoudert at gcc dot gnu.org
  2024-03-10  1:27 ` [Bug middle-end/63401] " pinskia at gcc dot gnu.org
  2024-03-10  1:31 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2014-09-28 22:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63401

            Bug ID: 63401
           Summary: "optimize" attribute overwrites other options
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fxcoudert at gcc dot gnu.org

I stumbled onto this bug while implementing some IEEE features in the Fortran
front-end, where we need to compile certain functions with specific options to
ensure full IEEE conformance. The backstory is here:
https://gcc.gnu.org/ml/gcc/2014-09/msg00396.html

Take this two-line C code:

//__attribute__ ((optimize("strength-reduce")))
int foo (float x) { return __builtin_isnan(x); }

Compiled with -O3 -ffast-math, the isnan is simplified out (fast math means no
NaNs). If you uncomment the attribute (I chose -fstrength-reduce because it's
actually a NOP), and compile again with -O3 -ffast-math: the isnan test is not
simplified any more.

This is because the codepath through default_options_optimization() has
overwritten the value of the flags handled in set_fast_math_flags():
flag_finite_math_only, flag_signed_zeros, flag_trapping_math and
flag_unsafe_math_optimizations.

In more detail: opts.c:set_fast_math_flags() is called three times:

  1. first, from toplev_main -> decode_options -> default_options_optimization
-> handle_generated_option -> handle_option -> common_handle_option
  2. then, from toplev_main -> decode_options -> read_cmdline_option ->
handle_option -> common_handle_option
  3. then, from my own build_function_decl -> parse_optimize_options ->
decode_options -> default_options_optimization -> handle_generated_option ->
handle_option -> common_handle_option

At 1 and 3, it’s called with value = 0, and at 2, with value = 1. So it is
indeed a bug: because we re-parse the defaults at 3, we reset some of the flags
dependent on -ffast-math (the ones quoted before), overwriting their earlier
value.




PS: There is also something similar with
align_functions/align_jumps/align_loops flags, but I don’t have time to chase
it right now.
>From gcc-bugs-return-462794-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sun Sep 28 22:14:57 2014
Return-Path: <gcc-bugs-return-462794-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 6510 invoked by alias); 28 Sep 2014 22:14:55 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 6467 invoked by uid 48); 28 Sep 2014 22:14:51 -0000
From: "steven at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/63401] "optimize" attribute overwrites other options
Date: Sun, 28 Sep 2014 22:14:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: middle-end
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords: wrong-code
X-Bugzilla-Severity: normal
X-Bugzilla-Who: steven at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: keywords bug_status cf_reconfirmed_on cc everconfirmed cf_known_to_fail
Message-ID: <bug-63401-4-vZXeiFH1ki@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-63401-4@http.gcc.gnu.org/bugzilla/>
References: <bug-63401-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-09/txt/msg02628.txt.bz2
Content-length: 760

https://gcc.gnu.org/bugzilla/show_bug.cgi?idc401

Steven Bosscher <steven at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-09-28
                 CC|                            |steven at gcc dot gnu.org
     Ever confirmed|0                           |1
      Known to fail|                            |4.8.0, 4.9.0, 5.0

--- Comment #1 from Steven Bosscher <steven at gcc dot gnu.org> ---
Fails with all GCC releases that support the 'optimize' attribute
(GCC4.4 and later).


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/63401] "optimize" attribute overwrites other options
  2014-09-28 22:08 [Bug middle-end/63401] New: "optimize" attribute overwrites other options fxcoudert at gcc dot gnu.org
@ 2024-03-10  1:27 ` pinskia at gcc dot gnu.org
  2024-03-10  1:31 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-10  1:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63401

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |11.4.0
           Keywords|                            |needs-bisection
   Target Milestone|---                         |12.0
      Known to work|                            |12.1.0

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Both this and the duplicate was fixed in GCC 12 ...

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/63401] "optimize" attribute overwrites other options
  2014-09-28 22:08 [Bug middle-end/63401] New: "optimize" attribute overwrites other options fxcoudert at gcc dot gnu.org
  2024-03-10  1:27 ` [Bug middle-end/63401] " pinskia at gcc dot gnu.org
@ 2024-03-10  1:31 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-10  1:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63401

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=92860

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed by the patches which fixed PR 92860 (there were a few) so closing.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-10  1:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-28 22:08 [Bug middle-end/63401] New: "optimize" attribute overwrites other options fxcoudert at gcc dot gnu.org
2024-03-10  1:27 ` [Bug middle-end/63401] " pinskia at gcc dot gnu.org
2024-03-10  1:31 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).