I was wondering if GCC will use the knowledge that the struct I created is overaligned and consider it simply as an integer when it comes to the generation of comparison asm.
It does not. I wonder if this is due to ABI issues, some other factor I missed or is it really a missing optimization?
code:
struct S{
short a,b;
bool operator == (const S&) const = default;
};
struct alignas(alignof(int)) S2 {
short a,b;
bool operator == (const S2&) const = default;
};
bool f(const S& s){
constinit static S c{11,22};
return c==s;
}
bool f2(const S2& s2){
constinit static S2 c2{11,22};
return c2==s2;
}
static_assert(alignof(S)==2);
static_assert(alignof(S2)==4);