This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/80574] GCC fail to optimize nested ternary
- From: "SztfG at yandex dot ru" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 01 May 2017 08:10:24 +0000
- Subject: [Bug tree-optimization/80574] GCC fail to optimize nested ternary
- Auto-submitted: auto-generated
- References: <bug-80574-4@http.gcc.gnu.org/bugzilla/>
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);;
}