public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* pragma GCC optimize prevents inlining
@ 2024-01-04  9:01 Hashan Gayasri
  2024-01-04  9:27 ` LIU Hao
  2024-01-04 14:51 ` David Brown
  0 siblings, 2 replies; 17+ messages in thread
From: Hashan Gayasri @ 2024-01-04  9:01 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1399 bytes --]

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

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

end of thread, other threads:[~2024-01-09 13:38 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-04  9:01 pragma GCC optimize prevents inlining 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
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

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).