This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/86909] Missing common subexpression elimination for types other than int


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

--- Comment #1 from Antony Polukhin <antoshkka at gmail dot com> ---
Another std::variant related example where GCC fails to eliminate
subexpressions and generates 6 times bigger assembly:

using size_t = unsigned long long;

struct A {} a;
static const size_t variant_npos = -1;

struct variant {
    using __index_type = unsigned char; // !!!!  O_O !!!!!!
    __index_type _M_index;

    size_t index() const noexcept {
            return (_M_index == __index_type(variant_npos) ? variant_npos :
_M_index);
    }
};

template<size_t _Np>
static A* get_if(variant* __ptr) noexcept {
    return (__ptr->index() == _Np ? &a : nullptr);
}

A* foo(int i, variant& in) {
    if (i==0) return get_if<0>(&in);
    if (i==1) return get_if<1>(&in);
    if (i==2) return get_if<2>(&in);
    if (i==3) return get_if<3>(&in);
    if (i==4) return get_if<4>(&in);
    if (i==5) return get_if<5>(&in);
    if (i==6) return get_if<6>(&in);

    return get_if<7>(&in);
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]