From: "Hurugalawadi, Naveen" <Naveen.Hurugalawadi@caviumnetworks.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: [PR25530] Convert (unsigned t / 2) * 2 into (unsigned t & ~1)
Date: Tue, 07 Jul 2015 04:55:00 -0000 [thread overview]
Message-ID: <SN2PR0701MB1024719A5C46B8E7276E718C8E920@SN2PR0701MB1024.namprd07.prod.outlook.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 574 bytes --]
Hi,
Please find attached the patch PR25530.patch that converts the pattern:-
(unsigned / 2) * 2 is into (unsigned & ~1).
Please review and let me know if its okay.
Regression tested on AARH64 and x86_64.
Thanks,
Naveen
gcc/testsuite/ChangeLog:
2015-07-07 Naveen H.S <Naveen.Hurugalawadi@caviumnetworks.com>
PR middle-end/25530
* gcc.dg/pr25530.c: New test.
gcc/ChangeLog:
2015-07-07 Naveen H.S <Naveen.Hurugalawadi@caviumnetworks.com>
PR middle-end/25530
* match.pd (mult (div @0 INTEGER_CST@1) INTEGER_CST@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: 1196 bytes --]
diff --git a/gcc/match.pd b/gcc/match.pd
index 53e911a..2c9e408 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -529,6 +529,17 @@ along with GCC; see the file COPYING3. If not see
(bitop (bit_and:c @0 @1) (bit_and @2 @1))
(bit_and (bitop @0 @2) @1)))
+/* Simplify (unsigned t / 2) * 2 -> unsigned t & ~1. */
+/* PR25530. */
+(for div (trunc_div ceil_div floor_div round_div exact_div)
+ (simplify
+ (mult (div @0 INTEGER_CST@1) INTEGER_CST@1)
+ (with { tree n2 = build_int_cst (TREE_TYPE (@0),
+ wi::exact_log2 (@1)); }
+ (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+ (bit_and @0 (lshift (rshift { build_minus_one_cst (TREE_TYPE (@0)); }
+ { n2; }) { n2; }))))))
+
/* (x | CST1) & CST2 -> (x & CST2) | (CST1 & CST2) */
(simplify
(bit_and (bit_ior @0 CONSTANT_CLASS_P@1) CONSTANT_CLASS_P@2)
diff --git a/gcc/testsuite/gcc.dg/pr25530.c b/gcc/testsuite/gcc.dg/pr25530.c
new file mode 100644
index 0000000..61e19cc
--- /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" } } */
next reply other threads:[~2015-07-07 4:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-07 4:55 Hurugalawadi, Naveen [this message]
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
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=SN2PR0701MB1024719A5C46B8E7276E718C8E920@SN2PR0701MB1024.namprd07.prod.outlook.com \
--to=naveen.hurugalawadi@caviumnetworks.com \
--cc=gcc-patches@gcc.gnu.org \
/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).