-
- Downloads
Match: Support form 1 for scalar signed integer SAT_TRUNC
This patch would like to support the form 1 of the scalar signed
integer SAT_TRUNC. Aka below example:
Form 1:
#define DEF_SAT_S_TRUNC_FMT_1(NT, WT, NT_MIN, NT_MAX) \
NT __attribute__((noinline)) \
sat_s_trunc_##WT##_to_##NT##_fmt_1 (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_1(int64_t, int32_t, INT32_MIN, INT32_MAX)
Before this patch:
4 │ __attribute__((noinline))
5 │ int32_t sat_s_trunc_int64_t_to_int32_t_fmt_1 (int64_t x)
6 │ {
7 │ int32_t trunc;
8 │ unsigned long x.0_1;
9 │ unsigned long _2;
10 │ int32_t _3;
11 │ _Bool _7;
12 │ int _8;
13 │ int _9;
14 │ int _10;
15 │
16 │ ;; basic block 2, loop depth 0
17 │ ;; pred: ENTRY
18 │ x.0_1 = (unsigned long) x_4(D);
19 │ _2 = x.0_1 + 2147483648;
20 │ if (_2 > 4294967295)
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 = (int32_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 = (int) _7;
37 │ _9 = -_8;
38 │ _10 = _9 ^ 2147483647;
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 │ int32_t sat_s_trunc_int64_t_to_int32_t_fmt_1 (int64_t x)
6 │ {
7 │ int32_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 with pr116861-1.c failed.
* The x86 bootstrap test.
* The x86 fully regression test.
The failed pr116861-1.c ice will be fixed in underlying patch, as it
just trigger one existing bug.
gcc/ChangeLog:
* match.pd: Add case 1 matching pattern for signed SAT_TRUNC.
* tree-ssa-math-opts.cc (gimple_signed_integer_sat_trunc): Add
new decl for signed SAT_TRUNC.
(match_saturation_trunc): Add new func impl to try SAT_TRUNC
pattern on phi node.
(math_opts_dom_walker::after_dom_children): Add
match_saturation_trunc for phi node iteration.
Signed-off-by:
Pan Li <pan2.li@intel.com>
Loading
Please register or sign in to comment