https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80588
Bug ID: 80588 Summary: GCC can't simplify static inline function with xor/xnor Product: gcc Version: 7.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: SztfG at yandex dot ru Target Milestone: --- GCC can't simplify static inline function for xor/xnor, but can, if used macro instead. Testcase: #include <inttypes.h> #define TYPE uint8_t #define M_XOR(a,b) ((!!(a))^(!!(b))) #define M_NXOR(a,b) (!((!!(a))^(!!(b)))) __attribute__((__always_inline__, const)) static inline TYPE m_xor (const TYPE a, const TYPE b) { return M_XOR(a,b); } __attribute__((__always_inline__, const)) static inline TYPE m_xnor (const TYPE a, const TYPE b) { return M_NXOR(a,b); } // bad assembly output int test1b(const TYPE a, const TYPE b) { return m_xor(a,b) == !m_xnor(a,b); } int test2b(const TYPE a, const TYPE b) { return !m_xor(a,b) == m_xnor(a,b); } int test3b(const TYPE a, const TYPE b) { return M_XOR(a,b) == !m_xnor(a,b); } // good assembly output int test1g(const TYPE a, const TYPE b) { return m_xor(a,b) == M_XOR(a,b); } int test2g(const TYPE a, const TYPE b) { return M_XOR(a,b) == !M_NXOR(a,b); } int test3g(const TYPE a, const TYPE b) { return M_XOR(a,b) != !M_NXOR(a,b);; }