Right now eqcompare_T has good codegen but eqcompare_U and eqcompare_O have worse codegen. Ideally, they'd all have the same codegen, since the comparison semantics for each of them are identical.
#include <compare>
struct T {
int i;
int j;
friend auto operator<=>(const T&, const T&) = default;
};
static_assert(__is_trivially_equality_comparable(T));
struct U {
int i;
short a, b;
friend auto operator<=>(const U&, const U&) = default;
};
static_assert(__is_trivially_equality_comparable(U));
struct ObjRep {
alignas(T) char data[sizeof(T)];
friend auto operator<=>(const ObjRep&, const ObjRep&) = default;
};
static_assert(__is_trivially_equality_comparable(ObjRep));
// Since all three are trivially equality-comparable, these should have the same codegen.
// Clang fails to optimize.
bool eqcompare_T(T *a, T *b) { return *a == *b; }
bool eqcompare_U(U *a, U *b) { return *a == *b; }
bool eqcompare_O(ObjRep *a, ObjRep *b) { return *a == *b; }
Right now
eqcompare_T
has good codegen buteqcompare_U
andeqcompare_O
have worse codegen. Ideally, they'd all have the same codegen, since the comparison semantics for each of them are identical.https://godbolt.org/z/GYdGc6xqa