GCC with patches for OS216
修訂 | 553c6572061f6f9ef92514e8f13de95d509ad614 (tree) |
---|---|
時間 | 2020-07-02 05:49:30 |
作者 | Jeff Law <law@redh...> |
Commiter | Jeff Law |
match.pd: (x & y) - (x | y) - 1 -> ~(x y) simplification [PR94882]
gcc/
PR tree-optimization/94882
* match.pd (x & y) - (x | y) - 1 -> ~(x y): New simplification.
gcc/testsuite/
PR tree-optimization/94882
* gcc.dg/tree-ssa/pr94882.c: New test.
* gcc.dg/tree-ssa/pr94882-1.c: New test.
* gcc.dg/tree-ssa/pr94882-2.c: New test.
* gcc.dg/tree-ssa/pr94882-3.c: New test.
@@ -1144,6 +1144,35 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) | ||
1144 | 1144 | (bit_xor (bit_ior:c (bit_not @0) @1) (bit_ior:c @0 (bit_not @1))) |
1145 | 1145 | (bit_xor @0 @1)) |
1146 | 1146 | |
1147 | +/* ((x & y) - (x | y)) - 1 -> ~(x ^ y) */ | |
1148 | +(simplify | |
1149 | + (plus (nop_convert1? (minus@2 (nop_convert2? (bit_and:c @0 @1)) | |
1150 | + (nop_convert2? (bit_ior @0 @1)))) | |
1151 | + integer_all_onesp) | |
1152 | + (if (!TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_TRAPS (type) | |
1153 | + && !TYPE_SATURATING (type) && !TYPE_OVERFLOW_SANITIZED (TREE_TYPE (@2)) | |
1154 | + && !TYPE_OVERFLOW_TRAPS (TREE_TYPE (@2)) | |
1155 | + && !TYPE_SATURATING (TREE_TYPE (@2))) | |
1156 | + (bit_not (convert (bit_xor @0 @1))))) | |
1157 | +(simplify | |
1158 | + (minus (nop_convert1? (plus@2 (nop_convert2? (bit_and:c @0 @1)) | |
1159 | + integer_all_onesp)) | |
1160 | + (nop_convert3? (bit_ior @0 @1))) | |
1161 | + (if (!TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_TRAPS (type) | |
1162 | + && !TYPE_SATURATING (type) && !TYPE_OVERFLOW_SANITIZED (TREE_TYPE (@2)) | |
1163 | + && !TYPE_OVERFLOW_TRAPS (TREE_TYPE (@2)) | |
1164 | + && !TYPE_SATURATING (TREE_TYPE (@2))) | |
1165 | + (bit_not (convert (bit_xor @0 @1))))) | |
1166 | +(simplify | |
1167 | + (minus (nop_convert1? (bit_and @0 @1)) | |
1168 | + (nop_convert2? (plus@2 (nop_convert3? (bit_ior:c @0 @1)) | |
1169 | + integer_onep))) | |
1170 | + (if (!TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_TRAPS (type) | |
1171 | + && !TYPE_SATURATING (type) && !TYPE_OVERFLOW_SANITIZED (TREE_TYPE (@2)) | |
1172 | + && !TYPE_OVERFLOW_TRAPS (TREE_TYPE (@2)) | |
1173 | + && !TYPE_SATURATING (TREE_TYPE (@2))) | |
1174 | + (bit_not (convert (bit_xor @0 @1))))) | |
1175 | + | |
1147 | 1176 | /* ~x & ~y -> ~(x | y) |
1148 | 1177 | ~x | ~y -> ~(x & y) */ |
1149 | 1178 | (for op (bit_and bit_ior) |
@@ -0,0 +1,42 @@ | ||
1 | +/* { dg-do compile } */ | |
2 | +/* { dg-options "-O2 -fdump-tree-optimized" } */ | |
3 | +/* { dg-final { scan-tree-dump-not "x_\[0-9]+\\\(D\\\) & y_\[0-9]+\\\(D\\\);" "optimized" } } */ | |
4 | +/* { dg-final { scan-tree-dump-not "x_\[0-9]+\\\(D\\\) \\| y_\[0-9]+\\\(D\\\);" "optimized" } } */ | |
5 | +/* { dg-final { scan-tree-dump-times "x_\[0-9]+\\\(D\\\) \\^ y_\[0-9]+\\\(D\\\);" 4 "optimized" } } */ | |
6 | +/* { dg-final { scan-tree-dump-times "~_\[0-9]\+" 4 "optimized" } } */ | |
7 | + | |
8 | +int | |
9 | +a (int x, int y) | |
10 | +{ | |
11 | + int t = x & y; | |
12 | + int tt = x | y; | |
13 | + t = t - tt; | |
14 | + return t + -1; | |
15 | +} | |
16 | + | |
17 | +int | |
18 | +b (int x, int y) | |
19 | +{ | |
20 | + int t = x & y; | |
21 | + int tt = x | y; | |
22 | + t = t - 1; | |
23 | + return t - tt; | |
24 | +} | |
25 | + | |
26 | +int | |
27 | +c (int x, int y) | |
28 | +{ | |
29 | + int t = x & y; | |
30 | + int tt = x | y; | |
31 | + tt = tt + 1; | |
32 | + return t - tt; | |
33 | +} | |
34 | + | |
35 | +int | |
36 | +d (int x, int y) | |
37 | +{ | |
38 | + int t = x & y; | |
39 | + int tt = x | y; | |
40 | + tt = tt + 1; | |
41 | + return t - tt; | |
42 | +} |
@@ -0,0 +1,78 @@ | ||
1 | +/* { dg-do compile } */ | |
2 | +/* { dg-options "-O2 -fdump-tree-optimized" } */ | |
3 | +/* { dg-final { scan-tree-dump-not "x_\[0-9]+\\\(D\\\) & y_\[0-9]+\\\(D\\\);" "optimized" } } */ | |
4 | +/* { dg-final { scan-tree-dump-not "x_\[0-9]+\\\(D\\\) \\| y_\[0-9]+\\\(D\\\);" "optimized" } } */ | |
5 | +/* { dg-final { scan-tree-dump-times "x_\[0-9]+\\\(D\\\) \\^ y_\[0-9]+\\\(D\\\);" 8 "optimized" } } */ | |
6 | +/* { dg-final { scan-tree-dump-times "~_\[0-9]\+" 8 "optimized" } } */ | |
7 | + | |
8 | +int | |
9 | +a (int x, int y) | |
10 | +{ | |
11 | + unsigned t = x & y; | |
12 | + unsigned tt = x | y; | |
13 | + t = t - tt; | |
14 | + return t + -1; | |
15 | +} | |
16 | + | |
17 | +int | |
18 | +a1 (int x, int y) | |
19 | +{ | |
20 | + int t = x & y; | |
21 | + int tt = x | y; | |
22 | + unsigned t1 = t - tt; | |
23 | + return t1 + -1; | |
24 | +} | |
25 | + | |
26 | +int | |
27 | +b (int x, int y) | |
28 | +{ | |
29 | + unsigned t = x & y; | |
30 | + unsigned tt = x | y; | |
31 | + t = t - 1; | |
32 | + return t - tt; | |
33 | +} | |
34 | + | |
35 | +int | |
36 | +b1 (int x, int y) | |
37 | +{ | |
38 | + int t = x & y; | |
39 | + int tt = x | y; | |
40 | + unsigned t1 = t - 1; | |
41 | + return t1 - tt; | |
42 | +} | |
43 | + | |
44 | +int | |
45 | +c (int x, int y) | |
46 | +{ | |
47 | + unsigned t = x & y; | |
48 | + unsigned tt = x | y; | |
49 | + tt = tt + 1; | |
50 | + return t - tt; | |
51 | +} | |
52 | + | |
53 | +int | |
54 | +c1 (int x, int y) | |
55 | +{ | |
56 | + int t = x & y; | |
57 | + int tt = x | y; | |
58 | + unsigned tt1 = tt + 1; | |
59 | + return t - tt1; | |
60 | +} | |
61 | + | |
62 | +int | |
63 | +d (int x, int y) | |
64 | +{ | |
65 | + unsigned t = x & y; | |
66 | + unsigned tt = x | y; | |
67 | + tt = tt + 1; | |
68 | + return t - tt; | |
69 | +} | |
70 | + | |
71 | +int | |
72 | +d1 (int x, int y) | |
73 | +{ | |
74 | + int t = x & y; | |
75 | + int tt = x | y; | |
76 | + unsigned tt1 = tt + 1; | |
77 | + return t - tt1; | |
78 | +} |
@@ -0,0 +1,79 @@ | ||
1 | +/* { dg-do compile } */ | |
2 | +/* { dg-options "-O2 -fdump-tree-optimized" } */ | |
3 | +/* { dg-final { scan-tree-dump-not "x_\[0-9]+\\\(D\\\) & y_\[0-9]+\\\(D\\\);" "optimized" } } */ | |
4 | +/* { dg-final { scan-tree-dump-not "x_\[0-9]+\\\(D\\\) \\| y_\[0-9]+\\\(D\\\);" "optimized" } } */ | |
5 | +/* { dg-final { scan-tree-dump-times "x_\[0-9]+\\\(D\\\) \\^ y_\[0-9]+\\\(D\\\);" 4 "optimized" } } */ | |
6 | +/* { dg-final { scan-tree-dump-times "_\[0-9] \\^ _\[0-9]" 4 "optimized" } } */ | |
7 | +/* { dg-final { scan-tree-dump-times "~_\[0-9]\+" 8 "optimized" } } */ | |
8 | + | |
9 | +signed char | |
10 | +a (short x, short y) | |
11 | +{ | |
12 | + unsigned char t = (unsigned char) (x & y); | |
13 | + unsigned char tt = (unsigned char) (x | y); | |
14 | + t = t - tt; | |
15 | + return (signed char) (t + -1); | |
16 | +} | |
17 | + | |
18 | +unsigned char | |
19 | +a1 (signed char x, signed char y) | |
20 | +{ | |
21 | + short t = (short) (x & y); | |
22 | + short tt = (short) (x | y); | |
23 | + unsigned char t1 = (unsigned char) (t - tt); | |
24 | + return t1 + -1; | |
25 | +} | |
26 | + | |
27 | +signed char | |
28 | +b (short x, short y) | |
29 | +{ | |
30 | + unsigned char t = (unsigned char) (x & y); | |
31 | + signed char tt = (signed char) (x | y); | |
32 | + t = t - 1; | |
33 | + return ((signed char) t - tt); | |
34 | +} | |
35 | + | |
36 | +short | |
37 | +b1 (short x, short y) | |
38 | +{ | |
39 | + int t = (int) (x & y); | |
40 | + int tt = (int) (x | y); | |
41 | + short t1 = (short) (t - 1); | |
42 | + return (short) (t1 - tt); | |
43 | +} | |
44 | + | |
45 | +signed char | |
46 | +c (unsigned x, unsigned y) | |
47 | +{ | |
48 | + unsigned char t = (unsigned char) (x & y); | |
49 | + signed char tt = (signed char) (x | y); | |
50 | + tt = tt + 1; | |
51 | + return (signed char) (t - tt); | |
52 | +} | |
53 | + | |
54 | +unsigned char | |
55 | +c1 (signed char x, signed char y) | |
56 | +{ | |
57 | + unsigned char t = (unsigned char) (x & y); | |
58 | + short tt = (short) (x | y); | |
59 | + unsigned char tt1 = (unsigned char) (tt + 1); | |
60 | + return t - tt1; | |
61 | +} | |
62 | + | |
63 | +signed char | |
64 | +d (unsigned char x, unsigned char y) | |
65 | +{ | |
66 | + int t = (int) (x & y); | |
67 | + int tt = (int) (x | y); | |
68 | + tt = tt + 1; | |
69 | + return (signed char) (t - tt); | |
70 | +} | |
71 | + | |
72 | +unsigned char | |
73 | +d1 (int x, int y) | |
74 | +{ | |
75 | + signed char t = (signed char) (x & y); | |
76 | + signed char tt = (signed char) (x | y); | |
77 | + unsigned char tt1 = (unsigned char) (tt + 1); | |
78 | + return (unsigned char) (t - tt1); | |
79 | +} |
@@ -0,0 +1,36 @@ | ||
1 | +/* { dg-do compile } */ | |
2 | +/* { dg-options "-O2 -fdump-tree-optimized" } */ | |
3 | +/* { dg-final { scan-tree-dump-not "x_\[0-9]+\\\(D\\\) & y_\[0-9]+\\\(D\\\);" "optimized" } } */ | |
4 | +/* { dg-final { scan-tree-dump-not "x_\[0-9]+\\\(D\\\) \\| y_\[0-9]+\\\(D\\\);" "optimized" } } */ | |
5 | +/* { dg-final { scan-tree-dump-times "x_\[0-9]+\\\(D\\\) \\^ y_\[0-9]+\\\(D\\\);" 5 "optimized" } } */ | |
6 | +/* { dg-final { scan-tree-dump-times "~_\[0-9]\+" 5 "optimized" } } */ | |
7 | + | |
8 | +int | |
9 | +a (int x, int y) | |
10 | +{ | |
11 | + return (x & y) - (x | y) - 1; | |
12 | +} | |
13 | + | |
14 | +int | |
15 | +b (int x, int y) | |
16 | +{ | |
17 | + return (x & y) - 1 - (x | y); | |
18 | +} | |
19 | + | |
20 | +int | |
21 | +c (int x, int y) | |
22 | +{ | |
23 | + return (x & y) - ((x | y) + 1); | |
24 | +} | |
25 | + | |
26 | +int | |
27 | +d (int x, int y) | |
28 | +{ | |
29 | + return (x & y) - (1 + (x | y)); | |
30 | +} | |
31 | + | |
32 | +int | |
33 | +e (int x, int y) | |
34 | +{ | |
35 | + return (unsigned) ((x & y) - (x | y)) + -1u; | |
36 | +} |