From: Pan Li <[email protected]>

The build_and_insert_cast refactored to go the gimple_convert way, to
take care of the widen_mul.  Thus, the gimple layout from uint64_t
widen_mul to uint128_t doesn't need additional cast like other types
(uint32_t, uint16_t, uint8_t) widen to uint128_t for mul.  Thus, add
the simplifed pattern match for such forms of unsigned SAT_MUL.

The below test suites are passed for this patch:
1. The rv64gcv fully regression tests.
2. Fix rv64gcv SAT_MUL test failure of optimized .SAT_MUL check.
3. The x86 bootstrap tests.
4. The x86 fully regression tests.

gcc/ChangeLog:

        * match.pd: Add simplifed pattern for widen_mul based unsigned
        SAT_MUL.

Signed-off-by: Pan Li <[email protected]>
---
 gcc/match.pd | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index 4d0a803eaef..e81e34f1aad 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3717,6 +3717,36 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        bool c2_is_type_precision_p = tree_to_uhwi (@2) == prec;
       }
       (if (c2_is_type_precision_p && (mult_p || widen_mult_p)))))))
+ (match (unsigned_integer_sat_mul @0 @1)
+  (convert (min (widen_mult:c@3 @0 @1) INTEGER_CST@2))
+  (if (types_match (type, @0, @1))
+   (with
+    {
+     unsigned prec = TYPE_PRECISION (type);
+     unsigned widen_prec = TYPE_PRECISION (TREE_TYPE (@3));
+
+     wide_int max = wi::mask (prec, false, widen_prec);
+     bool c2_is_max_p = wi::eq_p (wi::to_wide (@2), max);
+     bool widen_mult_p = prec * 2 == widen_prec;
+    }
+    (if (c2_is_max_p && widen_mult_p)))))
+  (match (unsigned_integer_sat_mul @0 @1)
+   (convert1?
+    (bit_ior
+     (convert?
+      (negate
+       (convert (ne (convert2? (rshift @3 INTEGER_CST@2)) integer_zerop))))
+     (convert (widen_mult:c@3 @0 @1))))
+   (if (types_match (type, @0, @1))
+    (with
+     {
+      unsigned prec = TYPE_PRECISION (type);
+      unsigned widen_prec = TYPE_PRECISION (TREE_TYPE (@3));
+
+      bool c2_is_type_precision_p = tree_to_uhwi (@2) == prec;
+      bool widen_mult_p = prec * 2 == widen_prec;
+     }
+     (if (c2_is_type_precision_p && widen_mult_p)))))
 )
 
 /* The boundary condition for case 10: IMM = 1:
-- 
2.43.0

Reply via email to