[Bug tree-optimization/89475] New: Teach ccp about __builtin_bswap{16,32,64}
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sat Feb 23 17:57:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89475
Bug ID: 89475
Summary: Teach ccp about __builtin_bswap{16,32,64}
Product: gcc
Version: 9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: jakub at gcc dot gnu.org
Target Milestone: ---
When looking at PR89435, I've noticed ccp should be able, but doesn't, optimize
__builtin_bswap{16,32,64}.
Those builtins should preserve both the mask and INTEGER_CST from the argument,
just bswapped.
Short testcase:
void link_error (void);
unsigned short
f0 (unsigned short x)
{
x &= 0xaa55;
x = __builtin_bswap16 (x);
if (x & 0xaa55)
link_error ();
return x;
}
unsigned short
f1 (unsigned short x)
{
x &= 0x55aa;
x = __builtin_bswap16 (x);
if (x & 0x55aa)
link_error ();
return x;
}
unsigned int
f2 (unsigned int x)
{
x &= 0x55aa5aa5U;
x = __builtin_bswap32 (x);
if (x & 0x5aa555aaU)
link_error ();
return x;
}
unsigned long long int
f3 (unsigned long long int x)
{
x &= 0x55aa5aa544cc2211ULL;
x = __builtin_bswap64 (x);
if (x & 0xeedd33bb5aa555aaULL)
link_error ();
return x;
}
unsigned short
f4 (unsigned short x)
{
x = __builtin_bswap32 (x);
if (x != 0)
link_error ();
return x;
}
unsigned int
f5 (unsigned int x)
{
x = __builtin_bswap64 (x);
if (x != 0)
link_error ();
return x;
}
unsigned short
f6 (unsigned short x)
{
x |= 0xaa55;
x = __builtin_bswap16 (x);
if ((x | 0xaa55) != 0xffff)
link_error ();
return x;
}
unsigned short
f7 (unsigned short x)
{
x |= 0x55aa;
x = __builtin_bswap16 (x);
if ((x | 0x55aa) != 0xffff)
link_error ();
return x;
}
unsigned int
f8 (unsigned int x)
{
x |= 0x55aa5aa5U;
x = __builtin_bswap32 (x);
if ((x | 0x5aa555aaU) != 0xffffffffU)
link_error ();
return x;
}
unsigned long long int
f9 (unsigned long long int x)
{
x |= 0x55aa5aa544cc2211ULL;
x = __builtin_bswap64 (x);
if ((x | 0xeedd33bb5aa555aaULL) != 0xffffffffffffffffULL)
link_error ();
return x;
}
Perhaps somewhat related to PR55177.
More information about the Gcc-bugs
mailing list