This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/86909] Missing common subexpression elimination for types other than int
- From: "antoshkka at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 10 Aug 2018 10:53:06 +0000
- Subject: [Bug middle-end/86909] Missing common subexpression elimination for types other than int
- Auto-submitted: auto-generated
- References: <bug-86909-4@http.gcc.gnu.org/bugzilla/>
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);
}