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: Thu, 4 Jan 2024 15:51:23 +0100	[thread overview]
Message-ID: <un6glc$192$1@ciao.gmane.io> (raw)
In-Reply-To: <CAA6G1fpuHiyDYne5=psCJO0A+gRAbaP65we1UBQjJDcrenDeQw@mail.gmail.com>

On 04/01/2024 10:01, Hashan Gayasri via Gcc-help wrote:
> Hi,
> 
> I noticed that GCC doesn't inline functions that have extra optimization
> options added via pragma GCC optimize after the pop_options statement.
> 
> If the optimizations are different between the caller and the callee, seems
> like gcc behaves as if the called function's definition is opaque and not
> visible at all (as if it was declared in a different translation unit). It
> doesn't even notice that the function doesn't have side effects unless
> marked so explicitly.
> 
> I wanted the following to be to be optimized:
> 
> #pragma GCC push_options
> #pragma GCC optimize ("-ffast-math")
> 
> inline int64_t __attribute__ ((const)) RoundToNearestLong (double v)
> {
>      assert(fegetround() == FE_TONEAREST);
>      return std::lrint(v);
> }
> 
> #pragma GCC pop_options
> 
> 
> So that std::lrint uses the vcvtsd2si instruction on X86 with SSE2.  It
> does that but prevents the instruction from being inlined. I complied with
> - O3 -march=native -DNDEBUG.
> 
> If I used attribute always_inline, the inlined version didn't seem to
> respect the additional optimization options I provided.
> const and pure function attributes helped in removing unused/no side effect
> code paths but the function still got called.
> 
> 
> Please advice if there's any way work around for this. Using intrinsics
> works but less than ideal.
> 
> (Also let me know if I should be sending this to a different mailing list)
> 
> Thanks in advance!
> 
> Best Regards,
> Hashan Gayasri
> 

This is a general limitation in GCC, as far as I know.  I have come 
across it myself (in my case it was the "-fwrapv" flag).  As far as I 
remember from a previous discussion long ago, there is no easy workaround.




  parent reply	other threads:[~2024-01-04 14:51 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 [this message]
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
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='un6glc$192$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).