diff --git a/gcc/match.pd b/gcc/match.pd index c3b8816..3d7a0db 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3410,6 +3410,35 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bswap (bitop:c (bswap @0) @1)) (bitop @0 (bswap @1))))) +/* Recognize ((T)bswap32(x)<<32)|bswap32(x>>32) as bswap64(x). */ +(for op (bit_ior bit_xor plus) + (simplify + (op:c + (lshift (convert (BUILT_IN_BSWAP32 (convert@0 @1))) + INTEGER_CST@2) + (convert (BUILT_IN_BSWAP32 (convert@3 (rshift @1 @2))))) + (if (INTEGRAL_TYPE_P (type) + && TYPE_PRECISION (type) == 64 + && types_match (TREE_TYPE (@1), uint64_type_node) + && types_match (TREE_TYPE (@0), uint32_type_node) + && types_match (TREE_TYPE (@3), uint32_type_node) + && wi::to_widest (@2) == 32) + (convert (BUILT_IN_BSWAP64 @1))))) + +/* Recognize ((T)bswap16(x)<<16)|bswap16(x>>16) as bswap32(x). */ +(for op (bit_ior bit_xor plus) + (simplify + (op:c + (lshift + (convert (BUILT_IN_BSWAP16 (convert (bit_and @0 INTEGER_CST@1)))) + (INTEGER_CST@2)) + (convert (BUILT_IN_BSWAP16 (convert (rshift @0 @2))))) + (if (INTEGRAL_TYPE_P (type) + && TYPE_PRECISION (type) == 32 + && types_match (TREE_TYPE (@0), uint32_type_node) + && wi::to_widest (@1) == 65535 + && wi::to_widest (@2) == 16) + (convert (BUILT_IN_BSWAP32 @0))))) /* Combine COND_EXPRs and VEC_COND_EXPRs. */