{ 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. */
(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))
--- /dev/null
+/* { 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" } } */
+
--- /dev/null
+/* { 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" } } */
+