Match: Support form 1 for scalar signed integer .SAT_ADD
This patch would like to support the form 1 of the scalar signed
integer .SAT_ADD. Aka below example:
Form 1:
#define DEF_SAT_S_ADD_FMT_1(T, UT, MIN, MAX) \
T __attribute__((noinline)) \
sat_s_add_##T##_fmt_1 (T x, T y) \
{ \
T sum = (UT)x + (UT)y; \
return (x ^ y) < 0 \
? sum \
: (sum ^ x) >= 0 \
? sum \
: x < 0 ? MIN : MAX; \
}
DEF_SAT_S_ADD_FMT_1(int64_t, uint64_t, INT64_MIN, INT64_MAX)
We can tell the difference before and after this patch if backend
implemented the ssadd<m>3 pattern similar as below.
Before this patch:
4 │ __attribute__((noinline))
5 │ int64_t sat_s_add_int64_t_fmt_1 (int64_t x, int64_t y)
6 │ {
7 │ int64_t sum;
8 │ long unsigned int x.0_1;
9 │ long unsigned int y.1_2;
10 │ long unsigned int _3;
11 │ long int _4;
12 │ long int _5;
13 │ int64_t _6;
14 │ _Bool _11;
15 │ long int _12;
16 │ long int _13;
17 │ long int _14;
18 │ long int _16;
19 │ long int _17;
20 │
21 │ ;; basic block 2, loop depth 0
22 │ ;; pred: ENTRY
23 │ x.0_1 = (long unsigned int) x_7(D);
24 │ y.1_2 = (long unsigned int) y_8(D);
25 │ _3 = x.0_1 + y.1_2;
26 │ sum_9 = (int64_t) _3;
27 │ _4 = x_7(D) ^ y_8(D);
28 │ _5 = x_7(D) ^ sum_9;
29 │ _17 = ~_4;
30 │ _16 = _5 & _17;
31 │ if (_16 < 0)
32 │ goto <bb 3>; [41.00%]
33 │ else
34 │ goto <bb 4>; [59.00%]
35 │ ;; succ: 3
36 │ ;; 4
37 │
38 │ ;; basic block 3, loop depth 0
39 │ ;; pred: 2
40 │ _11 = x_7(D) < 0;
41 │ _12 = (long int) _11;
42 │ _13 = -_12;
43 │ _14 = _13 ^ 9223372036854775807;
44 │ ;; succ: 4
45 │
46 │ ;; basic block 4, loop depth 0
47 │ ;; pred: 2
48 │ ;; 3
49 │ # _6 = PHI <sum_9(2), _14(3)>
50 │ return _6;
51 │ ;; succ: EXIT
52 │
53 │ }
After this patch:
4 │ __attribute__((noinline))
5 │ int64_t sat_s_add_int64_t_fmt_1 (int64_t x, int64_t y)
6 │ {
7 │ int64_t _4;
8 │
9 │ ;; basic block 2, loop depth 0
10 │ ;; pred: ENTRY
11 │ _4 = .SAT_ADD (x_5(D), y_6(D)); [tail call]
12 │ return _4;
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.
gcc/ChangeLog:
* match.pd: Add the matching for signed .SAT_ADD.
* tree-ssa-math-opts.cc (gimple_signed_integer_sat_add): Add new
matching func decl.
(match_unsigned_saturation_add): Try signed .SAT_ADD and rename
to ...
(match_saturation_add): ... here.
(math_opts_dom_walker::after_dom_children): Update the above renamed
func from caller.
Signed-off-by:
Pan Li <pan2.li@intel.com>
Loading
Please register or sign in to comment