Message ID | 20241010065339.1446003-1-pan2.li@intel.com |
---|---|
State | New |
Headers | show |
Series | [v1,1/2] Match: Support form 4 for scalar signed integer SAT_TRUNC | expand |
On Thu, Oct 10, 2024 at 8:55 AM <pan2.li@intel.com> wrote: > > From: Pan Li <pan2.li@intel.com> > > This patch would like to support the form 4 of the scalar signed > integer SAT_TRUNC. Aka below example: > > Form 4: > #define DEF_SAT_S_TRUNC_FMT_4(NT, WT, NT_MIN, NT_MAX) \ > NT __attribute__((noinline)) \ > sat_s_trunc_##WT##_to_##NT##_fmt_4 (WT x) \ > { \ > NT trunc = (NT)x; \ > return (WT)NT_MIN <= x && x < (WT)NT_MAX \ > ? trunc \ > : x < 0 ? NT_MIN : NT_MAX; \ > } > > DEF_SAT_S_TRUNC_FMT_4(int8_t, int16_t, INT8_MIN, INT8_MAX) > > Before this patch: > 4 │ __attribute__((noinline)) > 5 │ int8_t sat_s_trunc_int16_t_to_int8_t_fmt_4 (int16_t x) > 6 │ { > 7 │ int8_t trunc; > 8 │ unsigned short x.0_1; > 9 │ unsigned short _2; > 10 │ int8_t _3; > 11 │ _Bool _7; > 12 │ signed char _8; > 13 │ signed char _9; > 14 │ signed char _10; > 15 │ > 16 │ ;; basic block 2, loop depth 0 > 17 │ ;; pred: ENTRY > 18 │ x.0_1 = (unsigned short) x_4(D); > 19 │ _2 = x.0_1 + 128; > 20 │ if (_2 > 254) > 21 │ goto <bb 4>; [50.00%] > 22 │ else > 23 │ goto <bb 3>; [50.00%] > 24 │ ;; succ: 4 > 25 │ ;; 3 > 26 │ > 27 │ ;; basic block 3, loop depth 0 > 28 │ ;; pred: 2 > 29 │ trunc_5 = (int8_t) x_4(D); > 30 │ goto <bb 5>; [100.00%] > 31 │ ;; succ: 5 > 32 │ > 33 │ ;; basic block 4, loop depth 0 > 34 │ ;; pred: 2 > 35 │ _7 = x_4(D) < 0; > 36 │ _8 = (signed char) _7; > 37 │ _9 = -_8; > 38 │ _10 = _9 ^ 127; > 39 │ ;; succ: 5 > 40 │ > 41 │ ;; basic block 5, loop depth 0 > 42 │ ;; pred: 3 > 43 │ ;; 4 > 44 │ # _3 = PHI <trunc_5(3), _10(4)> > 45 │ return _3; > 46 │ ;; succ: EXIT > 47 │ > 48 │ } > > After this patch: > 4 │ __attribute__((noinline)) > 5 │ int8_t sat_s_trunc_int16_t_to_int8_t_fmt_4 (int16_t x) > 6 │ { > 7 │ int8_t _3; > 8 │ > 9 │ ;; basic block 2, loop depth 0 > 10 │ ;; pred: ENTRY > 11 │ _3 = .SAT_TRUNC (x_4(D)); [tail call] > 12 │ return _3; > 13 │ ;; succ: EXIT > 14 │ > 15 │ } > > The below test suites are passed for this patch. > * The rv64gcv fully regression test. > * The x86 bootstrap test. > * The x86 fully regression test. OK. > gcc/ChangeLog: > > * match.pd: Add case 4 matching pattern for signed SAT_TRUNC. > > Signed-off-by: Pan Li <pan2.li@intel.com> > --- > gcc/match.pd | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/gcc/match.pd b/gcc/match.pd > index 5e20651c8ce..6bd515fdd87 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -3488,6 +3488,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > } > (if (((wi::eq_p (int_cst_1, offset) && wi::eq_p (int_cst_2, limit_0)) > || (wi::eq_p (int_cst_1, itype_max) && wi::eq_p (int_cst_2, limit_2)) > + || (wi::eq_p (int_cst_1, offset) && wi::eq_p (int_cst_2, limit_2)) > || (wi::eq_p (int_cst_1, itype_max) && wi::eq_p (int_cst_2, limit_1))) > && wi::eq_p (int_cst_3, otype_max)))))) > > -- > 2.43.0 >
diff --git a/gcc/match.pd b/gcc/match.pd index 5e20651c8ce..6bd515fdd87 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3488,6 +3488,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) } (if (((wi::eq_p (int_cst_1, offset) && wi::eq_p (int_cst_2, limit_0)) || (wi::eq_p (int_cst_1, itype_max) && wi::eq_p (int_cst_2, limit_2)) + || (wi::eq_p (int_cst_1, offset) && wi::eq_p (int_cst_2, limit_2)) || (wi::eq_p (int_cst_1, itype_max) && wi::eq_p (int_cst_2, limit_1))) && wi::eq_p (int_cst_3, otype_max))))))