Widening-Mul: Try .SAT_SUB for PLUS_EXPR when one op is IMM

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.

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.li@intel.com>
This commit is contained in:
Pan Li 2024-07-27 11:29:42 +08:00
parent 29b1587e7d
commit 696d8b9bf3

View file

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