Issue 89820
Summary Suboptimal codegen for comparison of trivially equality comparable types
Labels
Assignees
Reporter AMP999
    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.

https://godbolt.org/z/GYdGc6xqa
```
#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; }

```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to