]> gcc.gnu.org Git - gcc.git/commitdiff
re PR tree-optimization/64454 (optimize (x%5)%5)
authorMarc Glisse <marc.glisse@inria.fr>
Fri, 15 May 2015 17:34:15 +0000 (19:34 +0200)
committerMarc Glisse <glisse@gcc.gnu.org>
Fri, 15 May 2015 17:34:15 +0000 (17:34 +0000)
2015-05-15  Marc Glisse  <marc.glisse@inria.fr>

PR tree-optimization/64454
gcc/
* match.pd ((X % Y) % Y, (X % Y) < Y): New patterns.
(-1 - A -> ~A): Remove unnecessary condition.
gcc/testsuite/
* gcc.dg/modmod.c: New testcase.

From-SVN: r223221

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/modmod.c [new file with mode: 0644]

index caf24c22b121678334430792b25f975d0979bb4e..3dec6b10cdab1468af6bf0323136e5b6f55c0d32 100644 (file)
@@ -1,3 +1,9 @@
+2015-05-15  Marc Glisse  <marc.glisse@inria.fr>
+
+       PR tree-optimization/64454
+       * match.pd ((X % Y) % Y, (X % Y) < Y): New patterns.
+       (-1 - A -> ~A): Remove unnecessary condition.
+
 2015-05-15  Gregor Richards  <gregor.richards@uwaterloo.ca>
 
        * config/i386/linux.h (MUSL_DYNAMIC_LINKER): Define.
index fffe6946325dc421d6246a363dd0b6864b0e8c5a..f277fe33cd59765cba796b33ef0fbb48dfd91be2 100644 (file)
@@ -211,7 +211,11 @@ along with GCC; see the file COPYING3.  If not see
  (simplify
   (mod @0 integer_minus_onep@1)
   (if (!TYPE_UNSIGNED (type))
-   { build_zero_cst (type); })))
+   { build_zero_cst (type); }))
+ /* (X % Y) % Y is just X % Y.  */
+ (simplify
+  (mod (mod@2 @0 @1) @1)
+  @2))
 
 /* X % -C is the same as X % C.  */
 (simplify
@@ -224,6 +228,18 @@ along with GCC; see the file COPYING3.  If not see
        && !sign_bit_p (@1, @1))
    (trunc_mod @0 (negate @1))))
 
+/* X % Y is smaller than Y.  */
+(for cmp (lt ge)
+ (simplify
+  (cmp (trunc_mod @0 @1) @1)
+  (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+   { constant_boolean_node (cmp == LT_EXPR, type); })))
+(for cmp (gt le)
+ (simplify
+  (cmp @1 (trunc_mod @0 @1))
+  (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+   { constant_boolean_node (cmp == GT_EXPR, type); })))
+
 /* x | ~0 -> ~0  */
 (simplify
   (bit_ior @0 integer_all_onesp@1)
@@ -533,8 +549,7 @@ along with GCC; see the file COPYING3.  If not see
   /* -1 - A -> ~A */
   (simplify
    (minus integer_all_onesp @0)
-   (if (TREE_CODE (type) != COMPLEX_TYPE)
-    (bit_not @0)))
+   (bit_not @0))
 
   /* (T)(P + A) - (T)P -> (T) A */
   (for add (plus pointer_plus)
index a9361067c5ad3e9442645fe135e891c8678f75a3..5875476821b8b51fc99e5e825dcd11f4e49cd20e 100644 (file)
@@ -1,3 +1,8 @@
+2015-05-15  Marc Glisse  <marc.glisse@inria.fr>
+
+       PR tree-optimization/64454
+       * gcc.dg/modmod.c: New testcase.
+
 2015-05-15  Ilya Enkovich  <ilya.enkovich@intel.com>
 
        * gcc.dg/lto/chkp-wrap-asm-name_0.c: New.
diff --git a/gcc/testsuite/gcc.dg/modmod.c b/gcc/testsuite/gcc.dg/modmod.c
new file mode 100644 (file)
index 0000000..577d0aa
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-options "-O -fdump-tree-optimized-raw" } */
+
+int f(int a, int b){
+  a %= b;
+  return a % b;
+}
+int g(unsigned a, unsigned b){
+  a %= b;
+  return a < b;
+}
+
+/* { dg-final { scan-tree-dump-times "trunc_mod_expr" 1 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
This page took 0.09099 seconds and 5 git commands to generate.