diff mbox

[PR57371] transform (double)i eq/ne 0 to i eq/ne 0

Message ID CAAgBjMmLtpzra0hpkfMHaBsYd3pLmd5y+1t3gQ6YgFgS1ruong@mail.gmail.com
State New
Headers show

Commit Message

Prathamesh Kulkarni Aug. 3, 2016, 7:53 a.m. UTC
Hi,
The attached patch tries to transform
(double)i eq/ne 0 to i eq/ne 0
AFAIU from Joseph's comment 1 in PR, the transform should be safe with
-fno-trapping-math ?
Bootstrap+tested on x86_64-unknown-linux-gnu in progress.

Thanks,
Prathamesh
2016-08-03  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

	PR tree-optimization/57371
	* match.pd ((double) i eq/ne 0 -> i eq/ne 0): New pattern.

testsuite/
	* gcc.dg/pr57371-1.c: New test-case.
	* gcc.dg/pr57371-2.c: Likewise.
diff mbox

Patch

diff --git a/gcc/match.pd b/gcc/match.pd
index 2380d90..63be2e9 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2611,6 +2611,13 @@  DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
    { constant_boolean_node (cmp == ORDERED_EXPR || cmp == LTGT_EXPR
 			    ? false : true, type); })))
 
+/* PR57371: Transform (double)i eq/ne 0 to i eq/ne 0.  */
+(for cmp (ne eq)
+ (simplify
+  (cmp (float @0) real_zerop@1)
+   (if (!flag_trapping_math && INTEGRAL_TYPE_P (TREE_TYPE (@0)))
+    (cmp @0 { build_zero_cst (TREE_TYPE (@0)); }))))
+
 /* bool_var != 0 becomes bool_var.  */
 (simplify
  (ne @0 integer_zerop)
diff --git a/gcc/testsuite/gcc.dg/pr57371-1.c b/gcc/testsuite/gcc.dg/pr57371-1.c
new file mode 100644
index 0000000..fd15509
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr57371-1.c
@@ -0,0 +1,14 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-trapping-math -fdump-tree-gimple" } */
+
+int f1(int i)
+{
+  return (double)i != 0;
+}
+
+int f2(int i)
+{
+  return (double)i == 0;
+}
+
+/* { dg-final { scan-tree-dump-times "double" 0 "gimple" } } */
diff --git a/gcc/testsuite/gcc.dg/pr57371-2.c b/gcc/testsuite/gcc.dg/pr57371-2.c
new file mode 100644
index 0000000..e19d054
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr57371-2.c
@@ -0,0 +1,17 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-trapping-math -fdump-tree-forwprop-details" } */
+
+int f1(int i)
+{
+  double x = (double) i;
+  return x != 0.0;
+}
+
+int f2(int i)
+{
+  double x = (double) i;
+  return x == 0.0;
+}
+
+/* { dg-final { scan-tree-dump "i_\[0-9\]*\\(D\\) != 0" "forwprop1" } } */
+/* { dg-final { scan-tree-dump "i_\[0-9\]*\\(D\\) == 0" "forwprop1" } } */