public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Brown <david@westcontrol.com>
To: gcc-help@gcc.gnu.org
Subject: Re: pragma GCC optimize prevents inlining
Date: Fri, 5 Jan 2024 15:24:48 +0100	[thread overview]
Message-ID: <un93fg$43g$1@ciao.gmane.io> (raw)
In-Reply-To: <20240104165517.GB19790@gate.crashing.org>

On 04/01/2024 17:55, Segher Boessenkool wrote:
> On Thu, Jan 04, 2024 at 04:24:20PM +0100, David Brown via Gcc-help wrote:
>> In my case, I wrote it in that second version!  But had "-fwrapv" worked
>> through inlining, it would have been convenient and neat, especially as
>> I had several related functions (for a wrapping-integer class).
> 
> Most things work on function basis; almost nothing works per RTL
> instruction.  There is no per-instruction representation for -fwrapv
> in the RTL stream.
> 

Yes, I appreciate that.  And I can also imagine that carrying such 
option information in the AST to make this possible would be a 
significant burden, and very rarely of benefit - so unless there is some 
other important use-case then it is not a good trade-off.

> Things are even worse for -O2 vs. -O3 etc.
> 
>> More generally, I think the expected semantics are that the additional
>> options apply to code inside the function, and at the boundary you don't
>> care which set of options apply.  So if you have normal floating point
>> code that sets "x", and then call an inline function with -ffast-math
>> using "x" as a parameter and returning "y", then the inlined could can
>> assume "x" is finite and not a NaN, and the later code can assume the
>> returned value "y" is similarly finite.  If the calculations for "x"
>> produce a NaN, then the code will be UB - that's the programmer's fault.
> 
> Yes, but that is only true for -ffast-math (which means "the user does
> not care about correct results" anyway).

(Getting a little off-topic...

Um, that's not what "-ffast-math" means.  It means "the user is using 
floating point as a close approximation to real number arithmetic, and 
promises to stick to numerically stable calculations".  All my uses of 
floating point are done with "-ffast-math", and I /do/ care that the 
results are correct.  But the definition of "correct" for my work is "as 
close to the theoretical real number result as you can get with a 
limited accuracy format, plus or minus small rounding errors".

For other people, full IEEE compliance, support for NaNs, and 
bit-perfect repeatable results regardless of optimisations and target 
details, are important for correctness.  And that's fine, and it's great 
that gcc supports both kinds of code - though I believe that 
"-ffast-math" would actually be more appropriate for a large proportion 
of programs.)

> 
> You would not typically want random nearby code to use -fwrapv as well,
> for example.
> 

No, not normally.  (Some people would like C to work that way, but not me!)

> 
> Segher
> 



  reply	other threads:[~2024-01-05 14:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-04  9:01 Hashan Gayasri
2024-01-04  9:27 ` LIU Hao
2024-01-05  0:56   ` Hashan Gayasri
2024-01-04 14:51 ` David Brown
2024-01-04 15:03   ` Segher Boessenkool
2024-01-04 15:24     ` David Brown
2024-01-04 16:37       ` Richard Earnshaw
2024-01-09 13:38         ` Florian Weimer
2024-01-04 16:55       ` Segher Boessenkool
2024-01-05 14:24         ` David Brown [this message]
2024-01-05 15:00           ` Segher Boessenkool
2024-01-05 15:53             ` David Brown
2024-01-05 18:19               ` Segher Boessenkool
2024-01-06 17:02                 ` David Brown
2024-01-07 17:51                   ` Segher Boessenkool
2024-01-07 18:36                     ` Gabriel Ravier
2024-01-08 15:53                     ` David Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='un93fg$43g$1@ciao.gmane.io' \
    --to=david@westcontrol.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).