diff mbox

Fix PR31096

Message ID SN2PR0701MB102429781DD227528814D7888E9E0@SN2PR0701MB1024.namprd07.prod.outlook.com
State New
Headers show

Commit Message

Hurugalawadi, Naveen April 5, 2016, 9:09 a.m. UTC
Hi,

>> Looks like you are turning x*-1 < y*-1 into x<y? That doesn't work...

Please find attached the modified patch that works on integer
constant values.

Please review the patch and let me know if this is okay?

Thanks,
Naveen

Comments

Marc Glisse April 5, 2016, 9:16 a.m. UTC | #1
On Tue, 5 Apr 2016, Hurugalawadi, Naveen wrote:

> Hi,
>
>>> Looks like you are turning x*-1 < y*-1 into x<y? That doesn't work...
>
> Please find attached the modified patch that works on integer
> constant values.
>
> Please review the patch and let me know if this is okay?

-1 is an integer constant, so that's still invalid. It is also invalid for 
unsigned. The :s are useless since the output is a single insn.
diff mbox

Patch

diff --git a/gcc/match.pd b/gcc/match.pd
index c0ed305..e073e9f 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.  naveen*/
+(for cmp (tcc_comparison)
+ (simplify
+  (cmp (mult:cs @0 INTEGER_CST@1) (mult:cs @2 INTEGER_CST@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..1c464db
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr31096.c
@@ -0,0 +1,17 @@ 
+/* PR middle-end/31096 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" }  */
+
+int
+f (int a, int b)
+{
+  return a * 10 == b * 10;
+}
+
+int
+f1 (int a, int b)
+{
+  return a == b;
+}
+
+/* { dg-final { scan-tree-dump-not " * 10" "optimized" } } */