re PR tree-optimization/45633 (internal compiler error: verify_stmts failed)
authorJakub Jelinek <jakub@redhat.com>
Wed, 15 Sep 2010 15:42:41 +0000 (17:42 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 15 Sep 2010 15:42:41 +0000 (17:42 +0200)
PR tree-optimization/45633
* tree-cfg.c (verify_gimple_assign_binary): Allow
MINUS_EXPR with lhs and rhs1 pointer vector and
rhs2 sizetype vector.
* expr.c (expand_expr_real_2) <case PLUS_EXPR>: For pointer
or vector pointer use TER to optimize pointer subtraction.

* gcc.dg/vect/pr45633.c: New test.

From-SVN: r164312

gcc/ChangeLog
gcc/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/pr45633.c [new file with mode: 0644]
gcc/tree-cfg.c

index 79388cc..09da047 100644 (file)
@@ -1,3 +1,12 @@
+2010-09-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/45633
+       * tree-cfg.c (verify_gimple_assign_binary): Allow
+       MINUS_EXPR with lhs and rhs1 pointer vector and
+       rhs2 sizetype vector.
+       * expr.c (expand_expr_real_2) <case PLUS_EXPR>: For pointer
+       or vector pointer use TER to optimize pointer subtraction.
+
 2010-09-15  Jie Zhang  <jie@codesourcery.com>
 
        * config/arm/vfp.md (cmpsf_trap_vfp): Change type from
index b1e87d1..16daddc 100644 (file)
@@ -7572,6 +7572,24 @@ expand_expr_real_2 (sepops ops, rtx target, enum machine_mode tmode,
            }
        }
 
+      /* Use TER to expand pointer addition of a negated value
+        as pointer subtraction.  */
+      if ((POINTER_TYPE_P (TREE_TYPE (treeop0))
+          || (TREE_CODE (TREE_TYPE (treeop0)) == VECTOR_TYPE
+              && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0)))))
+         && TREE_CODE (treeop1) == SSA_NAME
+         && TYPE_MODE (TREE_TYPE (treeop0))
+            == TYPE_MODE (TREE_TYPE (treeop1)))
+       {
+         gimple def = get_def_for_expr (treeop1, NEGATE_EXPR);
+         if (def)
+           {
+             treeop1 = gimple_assign_rhs1 (def);
+             code = MINUS_EXPR;
+             goto do_minus;
+           }
+       }
+
       /* No sense saving up arithmetic to be done
         if it's all in the wrong mode to form part of an address.
         And force_operand won't know whether to sign-extend or
@@ -7593,6 +7611,7 @@ expand_expr_real_2 (sepops ops, rtx target, enum machine_mode tmode,
       return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
 
     case MINUS_EXPR:
+    do_minus:
       /* For initializers, we are allowed to return a MINUS of two
         symbolic constants.  Here we handle all cases when both operands
         are constant.  */
index c67d3e3..cde5eea 100644 (file)
@@ -1,3 +1,8 @@
+2010-09-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/45633
+       * gcc.dg/vect/pr45633.c: New test.
+
 2010-09-15  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/45577
diff --git a/gcc/testsuite/gcc.dg/vect/pr45633.c b/gcc/testsuite/gcc.dg/vect/pr45633.c
new file mode 100644 (file)
index 0000000..456d51f
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR tree-optimization/45633 */
+/* { dg-do compile } */
+
+int s[32];
+unsigned char *t[32];
+
+void
+foo (void)
+{
+  int i;
+  for (i = 0; i < 32; i++)
+    t[i] -= s[i];
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */
index b8afb57..be8a84f 100644 (file)
@@ -3448,8 +3448,9 @@ verify_gimple_assign_binary (gimple stmt)
       }
 
     case PLUS_EXPR:
+    case MINUS_EXPR:
       {
-       /* We use regular PLUS_EXPR for vectors.
+       /* We use regular PLUS_EXPR and MINUS_EXPR for vectors.
           ???  This just makes the checker happy and may not be what is
           intended.  */
        if (TREE_CODE (lhs_type) == VECTOR_TYPE
@@ -3474,10 +3475,6 @@ verify_gimple_assign_binary (gimple stmt)
              }
            goto do_pointer_plus_expr_check;
          }
-      }
-    /* Fallthru.  */
-    case MINUS_EXPR:
-      {
        if (POINTER_TYPE_P (lhs_type)
            || POINTER_TYPE_P (rhs1_type)
            || POINTER_TYPE_P (rhs2_type))