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: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PR25530] Convert (unsigned t / 2) * 2 into (unsigned t & ~1)
Date: Tue, 21 Jul 2015 09:21:00 -0000	[thread overview]
Message-ID: <DM2PR0701MB1018B6682277C9F319FC55208E840@DM2PR0701MB1018.namprd07.prod.outlook.com> (raw)
In-Reply-To: <CAFiYyc3CbUKgnW6DC_t=CP=ZJMRveD+X9_6A0aWCgKgjQ87RzA@mail.gmail.com>

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

Hi,

>> handle exact_div differently, like fold-const.c does.
>> Then expressing ~1 with the result expression is really excessive - you
>> should simply build this with @1 - 1 if @1 is a power of two.

Thanks for the review and comments.

Please find attached the modified patch as per your comments.

Please review the same and let me know if any further modifications are required.

Regression Tested on X86_64.

Thanks,
Naveen

gcc/testsuite/ChangeLog:

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

	PR middle-end/25530
	* gcc.dg/pr25530.c: New test.

gcc/ChangeLog:

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

	PR middle-end/25530
	* match.pd (mult (exact_div @0 INTEGET_CST@1) @1) : 	New simplifier.
	(mult (trunc_div @0 integer_pow2p@1) @1) : New simplifier.

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

--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -280,6 +280,15 @@ 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 (unsigned t / 2) * 2 -> unsigned t & ~1.  */
+(simplify
+ (mult (exact_div @0 INTEGET_CST@1) @1)
+  @0)
+
+(simplify
+ (mult (trunc_div @0 integer_pow2p@1) @1)
+  (bit_and @0 (negate @1)))
+
 /* X % Y is smaller than Y.  */
 (for cmp (lt ge)
  (simplify
new file mode 100644
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr25530.c
@@ -0,0 +1,14 @@
+new file mode 100644
+--- /dev/null
++++ b/gcc/testsuite/gcc.dg/pr25530.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 "\& -2" "optimized" } } */

  parent reply	other threads:[~2015-07-21  9:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-07  4:55 Hurugalawadi, Naveen
2015-07-07  9:08 ` Richard Biener
2015-07-09  6:35   ` Paolo Bonzini
2015-07-09  8:57     ` Richard Biener
2015-07-21  9:21   ` Hurugalawadi, Naveen [this message]
2015-07-22 12:16     ` Richard Biener
2015-07-23  7:26       ` Hurugalawadi, Naveen
2015-07-23 13:36         ` 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=DM2PR0701MB1018B6682277C9F319FC55208E840@DM2PR0701MB1018.namprd07.prod.outlook.com \
    --to=naveen.hurugalawadi@caviumnetworks.com \
    --cc=gcc-patches@gcc.gnu.org \
    --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).