From: Pan Li Date: Sat, 15 Nov 2025 03:20:37 +0000 (+0800) Subject: Match: Simplify (T1)(a bit_op (T2)b) to (T1)a bit_op (T1)b X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bcdfc8bda79ca4540832262a901359e120de800;p=thirdparty%2Fgcc.git Match: Simplify (T1)(a bit_op (T2)b) to (T1)a bit_op (T1)b During the match pattern of SAT_U_MUL form 7, we found there is a pattern like below: (nop_convert)(a bit_op (convert b)) which result in the pattern match of SAT_U_MUL complicated and unintuitive. According to the suggestion of Richard, we would like to simply it to blew: (convert a) bit_op (convert b) which is more friendly for reading and bit_op. There are three bit_op here, aka bit_ior, bit_and and bit_xor. gcc/ChangeLog: * match.pd: Add simplfy to fold outer convert of bit_op to inner captures. Signed-off-by: Pan Li --- diff --git a/gcc/match.pd b/gcc/match.pd index 63d56b08192..22b1bd054b0 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2310,7 +2310,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && types_match (type, @0) && !POINTER_TYPE_P (TREE_TYPE (@0)) && TREE_CODE (TREE_TYPE (@0)) != OFFSET_TYPE) - (bitop @0 (convert @1))))) + (bitop @0 (convert @1)))) + /* Similar as above, but @0 has a widen type. */ + (simplify + (convert (bitop:cs@2 (convert:s @0) @1)) + (if (GIMPLE + && INTEGRAL_TYPE_P (type) + && INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TREE_CODE (@1) != INTEGER_CST + && tree_nop_conversion_p (type, TREE_TYPE (@2)) + && !POINTER_TYPE_P (TREE_TYPE (@0)) + && TREE_CODE (TREE_TYPE (@0)) != OFFSET_TYPE + && TYPE_PRECISION (TREE_TYPE (@0)) > TYPE_PRECISION (type)) + (bitop:type (convert @0) (convert @1))))) (for bitop (bit_and bit_ior) rbitop (bit_ior bit_and)