From: "Hurugalawadi, Naveen" <Naveen.Hurugalawadi@caviumnetworks.com>
To: "marc.glisse@inria.fr" <marc.glisse@inria.fr>
Cc: "ramana.radhakrishnan@foss.arm.com"
<ramana.radhakrishnan@foss.arm.com>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fix PR31096
Date: Tue, 12 Apr 2016 08:25:00 -0000 [thread overview]
Message-ID: <CO2PR07MB26941B6AA9C0417C2151C59B8E950@CO2PR07MB2694.namprd07.prod.outlook.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1604071311300.1957@laptop-mg.saclay.inria.fr>
[-- Attachment #1: Type: text/plain, Size: 486 bytes --]
Hi,
>> type is the return type of the comparison. The relevant type here is
TREE_TYPE (@0).
Done.
>>Maybe add a testcase with unsigned, to check that it
does not transform?
Added the testcase
>> you could probably use tree_expr_nonzero_p
Done.
I had !wi::eq_p (@1, 0) for INTEGER_CST, but when tried to
use it for general, then used the integer_zerop
Please find attached the modified patch with all the modifications
and let me know if its okay?
Thanks,
Naveen
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr31096-3.patch --]
[-- Type: text/x-diff; name="pr31096-3.patch", Size: 4027 bytes --]
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 0f4bf7e..5922dbd 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -9177,7 +9177,7 @@ tree_expr_nonzero_warnv_p (tree t, bool *strict_overflow_p)
/* Return true when T is an address and is known to be nonzero.
Handle warnings about undefined signed overflow. */
-static bool
+bool
tree_expr_nonzero_p (tree t)
{
bool ret, strict_overflow_p;
diff --git a/gcc/fold-const.h b/gcc/fold-const.h
index 02f4270..8579622 100644
--- a/gcc/fold-const.h
+++ b/gcc/fold-const.h
@@ -167,6 +167,7 @@ extern tree size_diffop_loc (location_t, tree, tree);
#define non_lvalue(T) non_lvalue_loc (UNKNOWN_LOCATION, T)
extern tree non_lvalue_loc (location_t, tree);
+extern bool tree_expr_nonzero_p (tree);
extern bool tree_expr_nonnegative_p (tree);
extern bool tree_expr_nonnegative_warnv_p (tree, bool *, int = 0);
extern tree make_range (tree, int *, tree *, tree *, bool *);
diff --git a/gcc/match.pd b/gcc/match.pd
index 75aa601..479a3a3 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see
zerop
CONSTANT_CLASS_P
tree_expr_nonnegative_p
+ tree_expr_nonzero_p
integer_valued_real_p
integer_pow2p
HONOR_NANS)
@@ -894,7 +895,26 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& tree_nop_conversion_p (type, TREE_TYPE (@1)))
(convert (bit_and (bit_not @1) @0))))
+/* Fold A * 10 == B * 10 into A == B. */
+(for cmp (eq ne)
+ (simplify
+ (cmp (mult:c @0 @1) (mult:c @2 @1))
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@1))
+ && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
+ && tree_expr_nonzero_p (@1))
+ (cmp @0 @2))))
+/* Fold A * 10 < B * 10 into A < B. */
+(for cmp (lt gt le ge)
+ (simplify
+ (cmp (mult:c @0 @1) (mult:c @2 @1))
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@1))
+ && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
+ && tree_expr_nonzero_p (@1))
+ (if (tree_expr_nonnegative_p (@1))
+ (cmp @0 @2)
+ (if (!tree_expr_nonnegative_p (@1))
+ (cmp @2 @0))))))
/* ((X inner_op C0) outer_op C1)
With X being a tree where value_range has reasoned certain bits to always be
diff --git a/gcc/testsuite/gcc.dg/pr31096-1.c b/gcc/testsuite/gcc.dg/pr31096-1.c
new file mode 100644
index 0000000..5f62ddc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr31096-1.c
@@ -0,0 +1,29 @@
+/* PR middle-end/31096 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+f (int a, int b)
+{
+ return a > b;
+}
+
+int
+f1 (int a, int b)
+{
+ return a * 10 >= b * 10;
+}
+
+int
+f2 (int a, int b)
+{
+ return a * -42 < b * -42;
+}
+
+int
+f3 (int a, int b)
+{
+ return a * 0 <= b * 0;
+}
+
+/* { dg-final { scan-tree-dump-not "\\(D\\) \\*" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/pr31096-2.c b/gcc/testsuite/gcc.dg/pr31096-2.c
new file mode 100644
index 0000000..ec51817
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr31096-2.c
@@ -0,0 +1,29 @@
+/* PR middle-end/31096 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+f (unsigned int a, unsigned int b)
+{
+ return a == b;
+}
+
+int
+f1 (unsigned int a, unsigned int b)
+{
+ return a * 10 == b * 10;
+}
+
+int
+f2 (unsigned int a, unsigned int b)
+{
+ return a * -42 < b * -42;
+}
+
+int
+f3 (unsigned int a, unsigned int b)
+{
+ return a * 0 <= b * 0;
+}
+
+/* { dg-final { scan-tree-dump-times "\\(D\\) \\*" 4 "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/pr31096.c b/gcc/testsuite/gcc.dg/pr31096.c
new file mode 100644
index 0000000..90cb71b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr31096.c
@@ -0,0 +1,29 @@
+/* PR middle-end/31096 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+f (int a, int b)
+{
+ return a == b;
+}
+
+int
+f1 (int a, int b)
+{
+ return a * 10 == b * 10;
+}
+
+int
+f2 (int a, int b)
+{
+ return a * -42 != b * -42;
+}
+
+int
+f3 (int a, int b)
+{
+ return a * 0 != b * 0;
+}
+
+/* { dg-final { scan-tree-dump-not "\\(D\\) \\*" "optimized" } } */
next prev parent reply other threads:[~2016-04-12 8:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-31 9:19 Hurugalawadi, Naveen
2016-03-31 9:32 ` Marc Glisse
2016-04-05 9:09 ` Hurugalawadi, Naveen
2016-04-05 9:17 ` Marc Glisse
2016-04-07 11:04 ` Hurugalawadi, Naveen
2016-04-07 11:28 ` Marc Glisse
2016-04-12 8:25 ` Hurugalawadi, Naveen [this message]
2016-04-12 9:33 ` Marc Glisse
2016-04-14 6:46 ` Hurugalawadi, Naveen
2016-04-15 16:25 ` Marc Glisse
2016-07-13 20:35 ` Jeff Law
2016-11-11 10:20 ` Hurugalawadi, Naveen
2016-11-23 9:56 ` Richard Biener
2016-03-31 9:35 ` Ramana Radhakrishnan
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=CO2PR07MB26941B6AA9C0417C2151C59B8E950@CO2PR07MB2694.namprd07.prod.outlook.com \
--to=naveen.hurugalawadi@caviumnetworks.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=marc.glisse@inria.fr \
--cc=ramana.radhakrishnan@foss.arm.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).