]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Match: Simplify (T1)(a bit_op (T2)b) to (T1)a bit_op (T1)b
authorPan Li <pan2.li@intel.com>
Sat, 15 Nov 2025 03:20:37 +0000 (11:20 +0800)
committerPan Li <pan2.li@intel.com>
Sun, 23 Nov 2025 10:36:39 +0000 (18:36 +0800)
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 <pan2.li@intel.com>
gcc/match.pd

index 63d56b0819250252deda74e6ef3cb6a74d8bffc7..22b1bd054b0e69ecb24f07b8a9d2484d4363830c 100644 (file)
@@ -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)