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

Reply via email to