https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121714
Bug ID: 121714 Summary: memcmp == 0 optimization should use MAX_FIXED_MODE_SIZE rather than word_mode Product: gcc Version: 16.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: pinskia at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Currently strlen_pass::handle_builtin_memcmp uses: && (leni = tree_to_uhwi (len)) <= GET_MODE_SIZE (word_mode) But I think this should be changed to use MAX_FIXED_MODE_SIZE instead. This at least could optimize: ``` #include <vector> struct s1 { long a[2]; bool operator==(const s1 &o) const { return __builtin_memcmp(this, &o, sizeof(o)); } }; bool test_(std::vector<s1> &in) { #if 1 if (in.size() != 1) return false; if (in.begin() == in.end()) __builtin_unreachable(); if (in.begin()+1 != in.end()) __builtin_unreachable(); #endif return in == std::vector<s1>{{0,0}}; } ``` Note the __builtin_unreachables there is give GCC hints; see PR 121712 and PR 121710 on why those are needed.