This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/80574] GCC fail to optimize nested ternary


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80574

--- Comment #3 from SztfG at yandex dot ru ---
Georg-Johann Lay, GCC not always do things better if use static inline function
instead macro. For example, this code:

#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);;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]