On Mon, Oct 21, 2024 at 6:13 AM Li Xu <xu...@eswincomputing.com> wrote: > > From: xuli <xu...@eswincomputing.com> > > This patch would like to support .SAT_SUB when one of the op > is IMM = 1 of form1. > > Form 1: > #define DEF_SAT_U_SUB_IMM_FMT_1(T, IMM) \ > T __attribute__((noinline)) \ > sat_u_sub_imm##IMM##_##T##_fmt_1 (T y) \ > { \ > return IMM >= y ? IMM - y : 0; \ > } > > Take below form 1 as example: > DEF_SAT_U_SUB_IMM_FMT_1(uint8_t, 1) > > Before this patch: > __attribute__((noinline)) > uint8_t sat_u_sub_imm1_uint8_t_fmt_1 (uint8_t y) > { > uint8_t _1; > uint8_t _3; > > <bb 2> [local count: 1073741824]: > if (y_2(D) <= 1) > goto <bb 3>; [41.00%] > else > goto <bb 4>; [59.00%] > > <bb 3> [local count: 440234144]: > _3 = y_2(D) ^ 1; > > <bb 4> [local count: 1073741824]: > # _1 = PHI <0(2), _3(3)> > return _1; > > } > > After this patch: > __attribute__((noinline)) > uint8_t sat_u_sub_imm1_uint8_t_fmt_1 (uint8_t y) > { > uint8_t _1; > > ;; basic block 2, loop depth 0 > ;; pred: ENTRY > _1 = .SAT_SUB (1, y_2(D)); [tail call] > return _1; > ;; succ: EXIT > > } > > 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. > > Change-Id: I534212f76075685389fc8256a4d12362339fb4d0 > Signed-off-by: Li Xu <xu...@eswincomputing.com> > gcc/ChangeLog: > > * match.pd: Support IMM=1. > > --- > gcc/match.pd | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/gcc/match.pd b/gcc/match.pd > index 9aa2129814b..1cdb10a40b9 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -3360,6 +3360,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > } > (if (wi::eq_p (c2, max) && wi::eq_p (c0_add_1, max)))))) > > +/* The boundary condition for case 9: IMM = 1 (branch with le): > + SAT_U_SUB = IMM >= Y ? (IMM - Y) : 0. */ > +(match (unsigned_integer_sat_sub @0 @1) > + (cond^ (le @1 integer_onep@0) (bit_xor @1 integer_onep@0) integer_zerop) > + (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) > + && types_match (type, @1) && int_fits_type_p (@0, type))))
Same here. OK with same fix. Richard. > + > /* Unsigned saturation sub with op_1 imm, case 10: > SAT_U_SUB = X > IMM ? (X - IMM) : 0. > = X >= IMM ? (X - IMM) : 0. */ > -- > 2.17.1 >