From: Pan Li <[email protected]>

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 <[email protected]>
---
 gcc/match.pd | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

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)
-- 
2.43.0

Reply via email to