This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR31096
- From: "Hurugalawadi, Naveen" <Naveen dot Hurugalawadi at caviumnetworks dot com>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 31 Mar 2016 08:55:56 +0000
- Subject: [PATCH] Fix PR31096
- Authentication-results: sourceware.org; auth=none
- Authentication-results: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=caviumnetworks.com;
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:23
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.
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" } } */