public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR31096
@ 2016-03-31  9:19 Hurugalawadi, Naveen
  2016-03-31  9:32 ` Marc Glisse
  2016-03-31  9:35 ` Ramana Radhakrishnan
  0 siblings, 2 replies; 14+ messages in thread
From: Hurugalawadi, Naveen @ 2016-03-31  9:19 UTC (permalink / raw)
  To: gcc-patches

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

Hi,

Please find attached the patch that fixes the PR31096.
Should the optimization be extended to addition and other
operations as well?

Please review the patch and let me know if its okay?

Regression tested on X86_64.

Thanks,
Naveen

2016-03-31  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>

        * match.pd (cmp (mult:cs @0 @1) (mult:cs @2 @1)) : New Pattern.

        * gcc.dg/pr31096.c: New testcase.

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

diff --git a/gcc/match.pd b/gcc/match.pd
index c0ed305..e1e1b04 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -894,7 +894,11 @@ 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 (tcc_comparison)
+ (simplify
+  (cmp (mult:cs @0 @1) (mult:cs @2 @1))
+   (cmp @0 @2)))
 
 /* ((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.c b/gcc/testsuite/gcc.dg/pr31096.c
new file mode 100644
index 0000000..5476db1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr31096.c
@@ -0,0 +1,17 @@
+/* PR middle-end/31096 */
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+
+int
+f (int a, int b)
+{
+  return a * 10 == b * 10;
+}
+
+int
+f1 (int a, int b)
+{
+  return a == b;
+}
+
+/* { dg-final { scan-assembler-not "addl" } } */

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2016-11-23  9:56 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-31  9:19 [PATCH] Fix PR31096 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
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

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).