public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
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-patches@gcc.gnu.org>
Subject: Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
Date: Thu, 23 Jul 2015 03:59:00 -0000	[thread overview]
Message-ID: <SN2PR0701MB1024E2FD81BA317E4CFFE98F8E820@SN2PR0701MB1024.namprd07.prod.outlook.com> (raw)
In-Reply-To: <CAFiYyc2=EyQvrDK+4PfUMQwHLY1EK0ZDg5WoY+ZXQ8k5oP_7NQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 576 bytes --]

>> so using wi::mask is prefered here.

Thanks for your review and comments.

Please find attached the modified patch as per your comments.

Please let me know if this version is okay?

Thanks,
Naveen

2015-07-22  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>

gcc/testsuite/ChangeLog:
         PR middle-end/25529
         * gcc.dg/pr25529.c: New test.

gcc/ChangeLog:
         PR middle-end/25529
         * match.pd (exact_div (mult @0 INTEGER_CST@1) @1) :     New simplifier.
         (trunc_div (mult @0 integer_pow2p@1) @1) : New simplifier.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr25529.patch --]
[-- Type: text/x-patch; name="pr25529.patch", Size: 1518 bytes --]

diff --git a/gcc/match.pd b/gcc/match.pd
index 9a66f52..9c8080f 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -29,7 +29,8 @@ along with GCC; see the file COPYING3.  If not see
    integer_each_onep integer_truep
    real_zerop real_onep real_minus_onep
    CONSTANT_CLASS_P
-   tree_expr_nonnegative_p)
+   tree_expr_nonnegative_p
+   integer_pow2p)
 
 /* Operator lists.  */
 (define_operator_list tcc_comparison
@@ -280,6 +281,20 @@ along with GCC; see the file COPYING3.  If not see
 	&& integer_pow2p (@2) && tree_int_cst_sgn (@2) > 0)
    (bit_and @0 (convert (minus @1 { build_int_cst (TREE_TYPE (@1), 1); }))))))
 
+/* Simplify (t * 2)/2 ->  t.  */
+(simplify
+ (exact_div (mult @0 INTEGER_CST@1) @1)
+ (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
+  @0))
+
+/* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF.  */
+(simplify
+ (trunc_div (mult @0 integer_pow2p@1) @1)
+ (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+  (bit_and @0 { wide_int_to_tree
+		(type, wi::mask (TYPE_PRECISION (type) - wi::exact_log2 (@1),
+				 false, TYPE_PRECISION (type))); })))
+
 /* X % Y is smaller than Y.  */
 (for cmp (lt ge)
  (simplify
diff --git a/gcc/testsuite/gcc.dg/pr25529.c b/gcc/testsuite/gcc.dg/pr25529.c
new file mode 100644
index 0000000..4d9fe9e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr25529.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+f (unsigned t)
+{
+  return (t * 2) / 2;
+}
+
+/* { dg-final { scan-tree-dump "\& 2147483647" "optimized" } } */

  reply	other threads:[~2015-07-23  3:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-07  4:52 Hurugalawadi, Naveen
2015-07-07  6:06 ` Marc Glisse
2015-07-07  9:12   ` Richard Biener
2015-07-07  9:24     ` Marc Glisse
2015-07-07  9:35       ` Richard Biener
2015-07-21  9:16         ` Hurugalawadi, Naveen
2015-07-22 12:10           ` Richard Biener
2015-07-23  3:59             ` Hurugalawadi, Naveen [this message]
2015-07-23 13:36               ` Richard Biener
2015-08-07  8:44                 ` Hurugalawadi, Naveen
2015-08-11 12:50                   ` Richard Biener
2015-08-11 12:51                     ` Richard Biener
2015-08-20 20:10                   ` H.J. Lu

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=SN2PR0701MB1024E2FD81BA317E4CFFE98F8E820@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).