diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/match.pd | 24 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/fold-eqbswap-1.c | 113 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/fold-eqrotate-1.c | 46 |
3 files changed, 183 insertions, 0 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index beb8d27..4d41b70 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3312,6 +3312,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) { tree rotate_type = TREE_TYPE (@0); } (convert (rotate (convert:rotate_type @1) @2)))))) +(for cmp (eq ne) + (for rotate (lrotate rrotate) + invrot (rrotate lrotate) + /* (X >>r Y) cmp (Z >>r Y) may simplify to X cmp Y. */ + (simplify + (cmp (rotate @1 @0) (rotate @2 @0)) + (cmp @1 @2)) + /* (X >>r C1) cmp C2 may simplify to X cmp C3. */ + (simplify + (cmp (rotate @0 INTEGER_CST@1) INTEGER_CST@2) + (cmp @0 { const_binop (invrot, TREE_TYPE (@0), @2, @1); })) + /* (X >>r Y) cmp C where C is 0 or ~0, may simplify to X cmp C. */ + (simplify + (cmp (rotate @0 @1) INTEGER_CST@2) + (if (integer_zerop (@2) || integer_all_onesp (@2)) + (cmp @0 @2))))) + /* Simplifications of conversions. */ /* Basic strip-useless-type-conversions / strip_nops. */ @@ -3622,6 +3639,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (bswap (bitop:c (bswap @0) @1)) (bitop @0 (bswap @1)))) + (for cmp (eq ne) + (simplify + (cmp (bswap @0) (bswap @1)) + (cmp @0 @1)) + (simplify + (cmp (bswap @0) INTEGER_CST@1) + (cmp @0 (bswap @1)))) /* (bswap(x) >> C1) & C2 can sometimes be simplified to (x >> C3) & C2. */ (simplify (bit_and (convert1? (rshift@0 (convert2? (bswap@4 @1)) INTEGER_CST@2)) diff --git a/gcc/testsuite/gcc.dg/fold-eqbswap-1.c b/gcc/testsuite/gcc.dg/fold-eqbswap-1.c new file mode 100644 index 0000000..ed9820b --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-eqbswap-1.c @@ -0,0 +1,113 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +int test1(int x, int y) +{ +#if __SIZEOF_INT__ == 4 + return __builtin_bswap32(x) == __builtin_bswap32(y); +#else + return x == y; +#endif +} + +int test2(int x, int y) +{ +#if __SIZEOF_INT__ == 4 + return __builtin_bswap32(x) != __builtin_bswap32(y); +#else + return x != y; +#endif +} + +int test3(int x) +{ +#if __SIZEOF_INT__ == 4 + return __builtin_bswap32(x) == 12345; +#else + return x; +#endif +} + +int test4(int x) +{ +#if __SIZEOF_INT__ == 4 + return __builtin_bswap32(x) != 12345; +#else + return x; +#endif +} + +int test1ll(long long x, long long y) +{ +#if __SIZEOF_LONG_LONG__ == 8 + return __builtin_bswap64(x) == __builtin_bswap64(y); +#else + return x == y; +#endif +} + +int test2ll(long long x, long long y) +{ +#if __SIZEOF_LONG_LONG__ == 8 + return __builtin_bswap64(x) != __builtin_bswap64(y); +#else + return x != y; +#endif +} + +int test3ll(long long x) +{ +#if __SIZEOF_LONG_LONG__ == 8 + return __builtin_bswap64(x) == 12345; +#else + return (int)x; +#endif +} + +int test4ll(long long x) +{ +#if __SIZEOF_LONG_LONG__ == 8 + return __builtin_bswap64(x) != 12345; +#else + return (int)x; +#endif +} + +int test1s(short x, short y) +{ +#if __SIZEOF_SHORT__ == 2 + return __builtin_bswap16(x) == __builtin_bswap16(y); +#else + return x == y; +#endif +} + +int test2s(short x, short y) +{ +#if __SIZEOF_SHORT__ == 2 + return __builtin_bswap16(x) != __builtin_bswap16(y); +#else + return x != y; +#endif +} + +int test3s(short x) +{ +#if __SIZEOF_SHORT__ == 2 + return __builtin_bswap16(x) == 12345; +#else + return (int)x; +#endif +} + +int test4s(short x) +{ +#if __SIZEOF_SHORT__ == 2 + return __builtin_bswap16(x) != 12345; +#else + return (int)x; +#endif +} + +/* { dg-final { scan-tree-dump-times "__builtin_bswap" 0 "optimized" } } */ + diff --git a/gcc/testsuite/gcc.dg/fold-eqrotate-1.c b/gcc/testsuite/gcc.dg/fold-eqrotate-1.c new file mode 100644 index 0000000..7d2b637 --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-eqrotate-1.c @@ -0,0 +1,46 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +int test1(unsigned int x, unsigned int y) +{ +#if __SIZEOF_INT__ == 4 + unsigned int r1 = (x << 16) | (x >> 16); + unsigned int r2 = (y << 16) | (y >> 16); + return r1 == r2; +#else + return x == y; +#endif +} + +int test2(unsigned int x) +{ +#if __SIZEOF_INT__ == 4 + unsigned int r1 = (x << 16) | (x >> 16); + return r1 == 12345; +#else + return x == 12345; +#endif +} + +int test3(unsigned int x) +{ +#if __SIZEOF_INT__ == 4 + unsigned int r1 = (x << 16) | (x >> 16); + return r1 == 0; +#else + return x == 0; +#endif +} + +int test4(unsigned int x) +{ +#if __SIZEOF_INT__ == 4 + unsigned int r1 = (x << 16) | (x >> 16); + return r1 == ~0; +#else + return x == ~0; +#endif +} + +/* { dg-final { scan-tree-dump-times "r>>" 0 "optimized" } } */ + |