re PR tree-optimization/15346 ([tree-ssa] combine two successive divisions)
authorRichard Biener <rguenther@suse.de>
Mon, 1 Dec 2014 13:13:28 +0000 (13:13 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 1 Dec 2014 13:13:28 +0000 (13:13 +0000)
2014-12-01  Richard Biener  <rguenther@suse.de>

PR tree-optimization/15346
* Makefile.in (gimple-match.o-warn): Remove -Wno-unused-parameter,
add -Wno-unused-but-set-variable.
* match.pd: Combine two successive divisions.

* gcc.dg/tree-ssa/forwprop-32.c: New testcase.

From-SVN: r218211

gcc/ChangeLog
gcc/Makefile.in
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/forwprop-32.c [new file with mode: 0644]

index d6968653f4dae81e1912aeeca078fa77582f61df..ae3b3c37bbdfb1629944be725ec75cf025e40f47 100644 (file)
@@ -1,3 +1,10 @@
+2014-12-01  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/15346
+       * Makefile.in (gimple-match.o-warn): Remove -Wno-unused-parameter,
+       add -Wno-unused-but-set-variable.
+       * match.pd: Combine two successive divisions.
+
 2014-12-01  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/64126
index 49f94e751b3d31be6068f3cb933d7398a10455c2..d36b2f04fbc3a897358034d6f582fde8db8e88b1 100644 (file)
@@ -209,8 +209,8 @@ gengtype-lex.o-warn = -Wno-error
 libgcov-util.o-warn = -Wno-error
 libgcov-driver-tool.o-warn = -Wno-error
 libgcov-merge-tool.o-warn = -Wno-error
-gimple-match.o-warn = -Wno-unused-variable -Wno-unused-parameter
-generic-match.o-warn = -Wno-unused-variable -Wno-unused-parameter
+gimple-match.o-warn = -Wno-unused-variable -Wno-unused-but-set-variable
+generic-match.o-warn = -Wno-unused-variable -Wno-unused-but-set-variable
 
 # All warnings have to be shut off in stage1 if the compiler used then
 # isn't gcc; configure determines that.  WARN_CFLAGS will be either
index 42e7c62cc7964451cc9a26666116217cfd865761..ee9bbc65fafe853178db6d5ebd64c2d3674901f2 100644 (file)
@@ -129,6 +129,19 @@ along with GCC; see the file COPYING3.  If not see
       && TYPE_UNSIGNED (type))
   (trunc_div @0 @1)))
 
+/* Combine two successive divisions.  */
+(for div (trunc_div ceil_div floor_div round_div exact_div)
+ (simplify
+  (div (div @0 INTEGER_CST@1) INTEGER_CST@2)
+  (with {
+    bool overflow_p;
+    wide_int mul = wi::mul (@1, @2, TYPE_SIGN (type), &overflow_p);
+   }
+   (if (!overflow_p)
+    (div @0 { wide_int_to_tree (type, mul); }))
+   (if (overflow_p)
+    { build_zero_cst (type); }))))
+
 /* Optimize A / A to 1.0 if we don't care about
    NaNs or Infinities.  */
 (simplify
index cb8bef7d901bb193a9614397cfe000b0650e5b6d..e56f3d9bc4c6cad18a276559a1694264451d4e6f 100644 (file)
@@ -1,3 +1,8 @@
+2014-12-01  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/15346
+       * gcc.dg/tree-ssa/forwprop-32.c: New testcase.
+
 2014-12-01  Yuri Rumyantsev  <ysrumyan@gmail.com>
 
        PR tree-optimization/63941
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-32.c b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-32.c
new file mode 100644 (file)
index 0000000..93851a1
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-forwprop1 -fdump-tree-ccp1" } */
+
+int foo (int x)
+{
+  int tem = x / 3;
+  return tem / 5;
+}
+int bar (int x)
+{
+  int tem = x / 3;
+  return tem / (__INT_MAX__ / 2);
+}
+
+/* { dg-final { scan-tree-dump "x_.\\(D\\) / 15" "forwprop1" } } */
+/* { dg-final { scan-tree-dump "return 0;" "ccp1" } } */
+/* { dg-final { cleanup-tree-dump "forwprop1" } } */
+/* { dg-final { cleanup-tree-dump "ccp1" } } */