On Sun, Jul 28, 2024 at 5:25 AM <pan2...@intel.com> wrote:
>
> From: Pan Li <pan2...@intel.com>
>
> After add the matching for .SAT_SUB when one op is IMM,  there
> will be a new root PLUS_EXPR for the .SAT_SUB pattern.  For example,
>
> Form 3:
>   #define DEF_SAT_U_SUB_IMM_FMT_3(T, IMM) \
>   T __attribute__((noinline))             \
>   sat_u_sub_imm##IMM##_##T##_fmt_3 (T x)  \
>   {                                       \
>     return x >= IMM ? x - IMM : 0;        \
>   }
>
> DEF_SAT_U_SUB_IMM_FMT_3(uint64_t, 11)
>
> And then we will have gimple before widening-mul as below.  Thus,  try
> the .SAT_SUB for the PLUS_EXPR.
>
>    4   │ __attribute__((noinline))
>    5   │ uint64_t sat_u_sub_imm11_uint64_t_fmt_3 (uint64_t x)
>    6   │ {
>    7   │   long unsigned int _1;
>    8   │   uint64_t _3;
>    9   │
>   10   │   <bb 2> [local count: 1073741824]:
>   11   │   _1 = MAX_EXPR <x_2(D), 11>;
>   12   │   _3 = _1 + 18446744073709551605;
>   13   │   return _3;
>   14   │
>   15   │ }
>
> The below test suites are passed for this patch.
> 1. The rv64gcv fully regression tests.
> 2. The x86 bootstrap tests.
> 3. The x86 fully regression tests.

OK

> gcc/ChangeLog:
>
>         * tree-ssa-math-opts.cc (math_opts_dom_walker::after_dom_children):
>         Try .SAT_SUB for PLUS_EXPR case.
>
> Signed-off-by: Pan Li <pan2...@intel.com>
> ---
>  gcc/tree-ssa-math-opts.cc | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc
> index ac86be8eb94..8d96a4c964b 100644
> --- a/gcc/tree-ssa-math-opts.cc
> +++ b/gcc/tree-ssa-math-opts.cc
> @@ -6129,6 +6129,7 @@ math_opts_dom_walker::after_dom_children (basic_block 
> bb)
>
>             case PLUS_EXPR:
>               match_unsigned_saturation_add (&gsi, as_a<gassign *> (stmt));
> +             match_unsigned_saturation_sub (&gsi, as_a<gassign *> (stmt));
>               /* fall-through  */
>             case MINUS_EXPR:
>               if (!convert_plusminus_to_widen (&gsi, stmt, code))
> --
> 2.34.1
>

Reply via email to