public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113478] New: -Os does not inline single instruction function
@ 2024-01-18 12:56 jari.helaakoski at qt dot io
  2024-01-18 13:12 ` [Bug ipa/113478] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: jari.helaakoski at qt dot io @ 2024-01-18 12:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113478
           Summary: -Os does not inline single instruction function
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jari.helaakoski at qt dot io
  Target Milestone: ---

GCC -Os option does not inline single instruction std::atomic function when
accessed via template class. Inlining works ok with -O2. Inlining is also
working if std::atomic is used directly. 

Test case and compilation result found from godbolt:
https://godbolt.org/z/nh758aT3K

Problem reproduces all GCC versions with x86 and aarch64 target and with and
without specific -march and -mtune options.

And here's test case pasted in case of godbolt is not accessable:
template <typename T>
class D {
    public:
#if 1
    inline T test() { return i.load(std::memory_order_relaxed); }
#else
    __attribute__((always_inline)) T test() { return
i.load(std::memory_order_relaxed); }
#endif
    std::atomic<T> i {0};
};

D<char> a1;
D<long> a2;
D<int> a3;
D<short> a4;
D<long long> a5;
D<wchar_t> a6;

extern void mod();

int main()
{
    int ret = 0;
    mod();
    ret |= a1.test();
    ret |= a1.test();
    ret |= a1.test();
    ret |= a1.test();
    ret |= a1.test();
    ret |= a1.test();
    ret |= a1.test();
    ret |= a1.test();
    ret |= a1.test();
    ret |= a1.test();
    ret |= a2.test();
    ret |= a3.test();
    ret |= a4.test();
    ret |= a5.test();
    ret |= a6.test();
    return ret;
}

Function that should be inlined
D<char>::test():
        ldrb    w0, [x0]
        ret

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

end of thread, other threads:[~2024-01-19 16:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-18 12:56 [Bug c++/113478] New: -Os does not inline single instruction function jari.helaakoski at qt dot io
2024-01-18 13:12 ` [Bug ipa/113478] " rguenth at gcc dot gnu.org
2024-01-19 10:51 ` hubicka at ucw dot cz
2024-01-19 11:09 ` rguenth at gcc dot gnu.org
2024-01-19 16:43 ` hubicka at ucw dot cz

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