]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Widening-Mul: Try .SAT_SUB for PLUS_EXPR when one op is IMM
authorPan Li <pan2.li@intel.com>
Sat, 27 Jul 2024 03:29:42 +0000 (11:29 +0800)
committerPan Li <pan2.li@intel.com>
Mon, 29 Jul 2024 12:18:37 +0000 (20:18 +0800)
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>
gcc/tree-ssa-math-opts.cc

index ac86be8eb9475e7fe93410a20eaf1b29d58620a9..8d96a4c964b313c6526a035cffba0aeaa8c494e2 100644 (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))