From: "Hurugalawadi, Naveen" <Naveen.Hurugalawadi@caviumnetworks.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: "marc.glisse@inria.fr" <marc.glisse@inria.fr>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: Move some bit and binary optimizations in simplify and match
Date: Fri, 16 Oct 2015 10:30:00 -0000 [thread overview]
Message-ID: <SN2PR0701MB10241785BE597A8D3D648B8C8E3D0@SN2PR0701MB1024.namprd07.prod.outlook.com> (raw)
In-Reply-To: <CAFiYyc17b4BO5GDVxodzNfoztV0Gvdy6pdpJfW2dR+8xh0aK1Q@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 673 bytes --]
Hi,
Thanks very much for your detailed explanation regarding the queries.
>> you are missing the convert? on the lshift now, without it the
>> tree_nop_conversion_p check always evaluates to true.
Done.
>> fold-const.c which handles TRUTH_NOT_EXPR but logical_inverted_value
>> does not handle it. I suggest to add
Done.
Please find attached the modified patch as per your suggestions.
>> You should move them to match.pd. It requires duplication to
>> handle the const vs. non-const cases the fold-const.c code handled.
Have modified patterns to handle const and non-const cases.
Will test it and post it once finished with it.
Thanks,
Naveen
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bit-bin4.patch --]
[-- Type: text/x-patch; name="bit-bin4.patch", Size: 5214 bytes --]
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index de45a2c..1e7fbb4 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -9803,20 +9803,6 @@ fold_binary_loc (location_t loc,
goto associate;
case MULT_EXPR:
- /* (-A) * (-B) -> A * B */
- if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1))
- return fold_build2_loc (loc, MULT_EXPR, type,
- fold_convert_loc (loc, type,
- TREE_OPERAND (arg0, 0)),
- fold_convert_loc (loc, type,
- negate_expr (arg1)));
- if (TREE_CODE (arg1) == NEGATE_EXPR && negate_expr_p (arg0))
- return fold_build2_loc (loc, MULT_EXPR, type,
- fold_convert_loc (loc, type,
- negate_expr (arg0)),
- fold_convert_loc (loc, type,
- TREE_OPERAND (arg1, 0)));
-
if (! FLOAT_TYPE_P (type))
{
/* Transform x * -C into -x * C if x is easily negatable. */
@@ -9830,16 +9816,6 @@ fold_binary_loc (location_t loc,
negate_expr (arg0)),
tem);
- /* (a * (1 << b)) is (a << b) */
- if (TREE_CODE (arg1) == LSHIFT_EXPR
- && integer_onep (TREE_OPERAND (arg1, 0)))
- return fold_build2_loc (loc, LSHIFT_EXPR, type, op0,
- TREE_OPERAND (arg1, 1));
- if (TREE_CODE (arg0) == LSHIFT_EXPR
- && integer_onep (TREE_OPERAND (arg0, 0)))
- return fold_build2_loc (loc, LSHIFT_EXPR, type, op1,
- TREE_OPERAND (arg0, 1));
-
/* (A + A) * C -> A * 2 * C */
if (TREE_CODE (arg0) == PLUS_EXPR
&& TREE_CODE (arg1) == INTEGER_CST
@@ -9882,21 +9858,6 @@ fold_binary_loc (location_t loc,
}
else
{
- /* Convert (C1/X)*C2 into (C1*C2)/X. This transformation may change
- the result for floating point types due to rounding so it is applied
- only if -fassociative-math was specify. */
- if (flag_associative_math
- && TREE_CODE (arg0) == RDIV_EXPR
- && TREE_CODE (arg1) == REAL_CST
- && TREE_CODE (TREE_OPERAND (arg0, 0)) == REAL_CST)
- {
- tree tem = const_binop (MULT_EXPR, TREE_OPERAND (arg0, 0),
- arg1);
- if (tem)
- return fold_build2_loc (loc, RDIV_EXPR, type, tem,
- TREE_OPERAND (arg0, 1));
- }
-
/* Strip sign operations from X in X*X, i.e. -Y*-Y -> Y*Y. */
if (operand_equal_p (arg0, arg1, 0))
{
@@ -10053,22 +10014,6 @@ fold_binary_loc (location_t loc,
goto bit_rotate;
case BIT_AND_EXPR:
- /* ~X & X, (X == 0) & X, and !X & X are always zero. */
- if ((TREE_CODE (arg0) == BIT_NOT_EXPR
- || TREE_CODE (arg0) == TRUTH_NOT_EXPR
- || (TREE_CODE (arg0) == EQ_EXPR
- && integer_zerop (TREE_OPERAND (arg0, 1))))
- && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
- return omit_one_operand_loc (loc, type, integer_zero_node, arg1);
-
- /* X & ~X , X & (X == 0), and X & !X are always zero. */
- if ((TREE_CODE (arg1) == BIT_NOT_EXPR
- || TREE_CODE (arg1) == TRUTH_NOT_EXPR
- || (TREE_CODE (arg1) == EQ_EXPR
- && integer_zerop (TREE_OPERAND (arg1, 1))))
- && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
- return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
-
/* Fold (X ^ 1) & 1 as (X & 1) == 0. */
if (TREE_CODE (arg0) == BIT_XOR_EXPR
&& INTEGRAL_TYPE_P (type)
diff --git a/gcc/match.pd b/gcc/match.pd
index f3813d8..1120c59 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -324,6 +324,22 @@ along with GCC; see the file COPYING3. If not see
(if (real_isinteger (&TREE_REAL_CST (@1), &n) && (n & 1) == 0)
(pows @0 @1))))))
+/* Fold (a * (1 << b)) into (a << b) */
+(simplify
+ (mult:c @0 (convert? (lshift integer_onep@1 @2)))
+ (if (! FLOAT_TYPE_P (type)
+ && tree_nop_conversion_p (type, TREE_TYPE (@1)))
+ (lshift @0 @2)))
+
+/* Fold (C1/X)*C2 into (C1*C2)/X. */
+(simplify
+ (mult (rdiv:s REAL_CST@0 @1) REAL_CST@2)
+ (if (flag_associative_math)
+ (with
+ { tree tem = const_binop (MULT_EXPR, type, @0, @2); }
+ (if (tem)
+ (rdiv { tem; } @1)))))
+
/* X % Y is smaller than Y. */
(for cmp (lt ge)
(simplify
@@ -543,6 +559,13 @@ along with GCC; see the file COPYING3. If not see
(match negate_expr_p
VECTOR_CST
(if (FLOAT_TYPE_P (TREE_TYPE (type)) || TYPE_OVERFLOW_WRAPS (type))))
+
+/* (-A) * (-B) -> A * B */
+(simplify
+ (mult:c (convert1? (negate @0)) (convert2? negate_expr_p@1))
+ (if (tree_nop_conversion_p (type, TREE_TYPE (@0))
+ && tree_nop_conversion_p (type, TREE_TYPE (@1)))
+ (mult (convert @0) (convert (negate @1)))))
/* -(A + B) -> (-B) - A. */
(simplify
@@ -629,6 +652,8 @@ along with GCC; see the file COPYING3. If not see
(truth_not @0))
(match (logical_inverted_value @0)
+ (truth_not @0))
+(match (logical_inverted_value @0)
(bit_not truth_valued_p@0))
(match (logical_inverted_value @0)
(eq @0 integer_zerop))
@@ -646,6 +671,10 @@ along with GCC; see the file COPYING3. If not see
(simplify
(op:c truth_valued_p@0 (logical_inverted_value @0))
{ constant_boolean_node (true, type); }))
+/* Simplify ~X & X as zero. */
+(simplify
+ (bit_and:c (convert? truth_valued_p@0) (convert? (logical_inverted_value @0)))
+ { build_zero_cst (type); })
/* X ==/!= !X is false/true. */
(for op (eq ne)
(simplify
next prev parent reply other threads:[~2015-10-16 10:30 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 [this message]
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
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=SN2PR0701MB10241785BE597A8D3D648B8C8E3D0@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).