From: "Hurugalawadi, Naveen" <Naveen.Hurugalawadi@caviumnetworks.com>
To: Richard Biener <richard.guenther@gmail.com>,
Marc Glisse <marc.glisse@inria.fr>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: Move some bit and binary optimizations in simplify and match
Date: Fri, 23 Oct 2015 05:11:00 -0000 [thread overview]
Message-ID: <SN2PR0701MB102493AB9A401CC25D600B478E260@SN2PR0701MB1024.namprd07.prod.outlook.com> (raw)
In-Reply-To: <CAFiYyc2XZfLKBRJj1ynpRgVpiWj6fMhp9s1YRJAASSaYe=-GYA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 164 bytes --]
Hi,
>> So I suggest to modify your patch to do
Done.
Please find attached the modified patch.
Regression tested successfully on X86_64.
Thanks,
Naveen
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bit-bin7.patch --]
[-- Type: text/x-patch; name="bit-bin7.patch", Size: 3189 bytes --]
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 1e7fbb4..23c6fa9 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -9692,28 +9692,6 @@ fold_binary_loc (location_t loc,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)));
- if (! FLOAT_TYPE_P (type))
- {
- /* Fold (A & ~B) - (A & B) into (A ^ B) - B, where B is
- any power of 2 minus 1. */
- if (TREE_CODE (arg0) == BIT_AND_EXPR
- && TREE_CODE (arg1) == BIT_AND_EXPR
- && operand_equal_p (TREE_OPERAND (arg0, 0),
- TREE_OPERAND (arg1, 0), 0))
- {
- tree mask0 = TREE_OPERAND (arg0, 1);
- tree mask1 = TREE_OPERAND (arg1, 1);
- tree tem = fold_build1_loc (loc, BIT_NOT_EXPR, type, mask0);
-
- if (operand_equal_p (tem, mask1, 0))
- {
- tem = fold_build2_loc (loc, BIT_XOR_EXPR, type,
- TREE_OPERAND (arg0, 0), mask1);
- return fold_build2_loc (loc, MINUS_EXPR, type, tem, mask1);
- }
- }
- }
-
/* Fold __complex__ ( x, 0 ) - __complex__ ( 0, y ) to
__complex__ ( x, -y ). This is not the same for SNaNs or if
signed zeros are involved. */
@@ -9974,28 +9952,6 @@ fold_binary_loc (location_t loc,
arg1);
}
- /* (X & ~Y) | (~X & Y) is X ^ Y */
- if (TREE_CODE (arg0) == BIT_AND_EXPR
- && TREE_CODE (arg1) == BIT_AND_EXPR)
- {
- tree a0, a1, l0, l1, n0, n1;
-
- a0 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 0));
- a1 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 1));
-
- l0 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
- l1 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1));
-
- n0 = fold_build1_loc (loc, BIT_NOT_EXPR, type, l0);
- n1 = fold_build1_loc (loc, BIT_NOT_EXPR, type, l1);
-
- if ((operand_equal_p (n0, a0, 0)
- && operand_equal_p (n1, a1, 0))
- || (operand_equal_p (n0, a1, 0)
- && operand_equal_p (n1, a0, 0)))
- return fold_build2_loc (loc, BIT_XOR_EXPR, type, l0, n1);
- }
-
/* See if this can be simplified into a rotate first. If that
is unsuccessful continue in the association code. */
goto bit_rotate;
diff --git a/gcc/match.pd b/gcc/match.pd
index 83dc7ad..0fb6115 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -346,6 +346,29 @@ along with GCC; see the file COPYING3. If not see
(bit_and:c (convert? @0) (convert? (bit_not @0)))
{ build_zero_cst (type); })
+/* Fold (A & ~B) - (A & B) into (A ^ B) - B. */
+(simplify
+ (minus (bit_and:cs @0 (bit_not @1)) (bit_and:s @0 @1))
+ (minus (bit_xor @0 @1) @1))
+(simplify
+ (minus (bit_and:s @0 INTEGER_CST@2) (bit_and:s @0 INTEGER_CST@1))
+ (if (wi::bit_not (@2) == @1)
+ (minus (bit_xor @0 @1) @1)))
+
+/* Fold (A & B) - (A & ~B) into B - (A ^ B). */
+(simplify
+ (minus (bit_and:s @0 @1) (bit_and:cs @0 (bit_not @1)))
+ (minus @1 (bit_xor @0 @1)))
+
+/* Simplify (X & ~Y) | (~X & Y) -> X ^ Y. */
+(simplify
+ (bit_ior:c (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1))
+ (bit_xor @0 @1))
+(simplify
+ (bit_ior:c (bit_and @0 INTEGER_CST@2) (bit_and (bit_not @0) INTEGER_CST@1))
+ (if (wi::bit_not (@2) == @1)
+ (bit_xor @0 @1)))
+
/* X % Y is smaller than Y. */
(for cmp (lt ge)
(simplify
next prev parent reply other threads:[~2015-10-23 4:29 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-07 9:54 Hurugalawadi, Naveen
2015-10-08 13:39 ` Richard Biener
2015-10-12 10:22 ` Hurugalawadi, Naveen
2015-10-12 12:49 ` Marc Glisse
2015-10-12 13:11 ` Richard Biener
2015-10-13 10:52 ` Hurugalawadi, Naveen
2015-10-13 11:38 ` Marc Glisse
2015-10-13 11:57 ` Richard Biener
2015-10-13 12:18 ` Marc Glisse
2015-10-13 12:50 ` Richard Biener
2015-10-14 5:13 ` Hurugalawadi, Naveen
2015-10-14 5:40 ` Marc Glisse
2015-10-14 10:09 ` Richard Biener
2015-10-14 10:45 ` Marc Glisse
2015-10-14 10:53 ` Richard Biener
2015-10-14 11:38 ` Marc Glisse
2015-10-15 6:11 ` Hurugalawadi, Naveen
2015-10-15 12:38 ` Richard Biener
2015-10-16 10:30 ` Hurugalawadi, Naveen
2015-10-16 11:05 ` Marc Glisse
2015-10-19 11:14 ` Hurugalawadi, Naveen
2015-10-19 13:04 ` Richard Biener
2015-10-19 11:22 ` Hurugalawadi, Naveen
2015-10-19 11:42 ` Marc Glisse
2015-10-20 6:48 ` Hurugalawadi, Naveen
2015-10-20 12:13 ` Richard Biener
2015-10-21 4:05 ` Hurugalawadi, Naveen
2015-10-21 7:26 ` Marc Glisse
2015-10-21 9:49 ` Richard Biener
2015-10-23 5:11 ` Hurugalawadi, Naveen [this message]
2015-10-23 9:07 ` Richard Biener
2015-10-24 21:37 ` Marc Glisse
2015-10-26 9:29 ` Richard Biener
2015-10-26 9:33 ` Richard Biener
2015-10-08 16:58 ` Bernd Schmidt
2015-10-08 18:03 ` Joseph Myers
2015-10-08 18:15 ` Bernd Schmidt
2015-10-09 9:32 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=SN2PR0701MB102493AB9A401CC25D600B478E260@SN2PR0701MB1024.namprd07.prod.outlook.com \
--to=naveen.hurugalawadi@caviumnetworks.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=marc.glisse@inria.fr \
--cc=richard.guenther@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).