tree-ssa-sccvn.c (expressions_equal_p): Check type equality.
authorDaniel Berlin <dberlin@dberlin.org>
Tue, 15 Jul 2008 23:50:52 +0000 (23:50 +0000)
committerDaniel Berlin <dberlin@gcc.gnu.org>
Tue, 15 Jul 2008 23:50:52 +0000 (23:50 +0000)
2008-07-15  Daniel Berlin  <dberlin@dberlin.org>

* tree-ssa-sccvn.c (expressions_equal_p): Check type equality.
* tree-ssa-pre.c (pre_expr_eq): Ditto
(get_constant_for_value_id): Take a type as an argument.
(fully_constant_expression): Pass in type.
(find_or_generate_expression): Short circuit constant case.
(create_expression_by_pieces): Remove special casing of
pointer_plus.
(do_regular_insertion): Short circuit constant case.
(do_partial_partial_insertion): Ditto.

From-SVN: r137859

gcc/ChangeLog
gcc/testsuite/gcc.c-torture/compile/20080704-1.c
gcc/tree-ssa-pre.c
gcc/tree-ssa-sccvn.c

index cbb23eae063e99f7a8a4346cf2dbc30de829b1f5..4c7a7766a1c46d0223b7800e0358a191ad3d5ab7 100644 (file)
@@ -1,3 +1,15 @@
+2008-07-15  Daniel Berlin  <dberlin@dberlin.org>
+
+       * tree-ssa-sccvn.c (expressions_equal_p): Check type equality.
+       * tree-ssa-pre.c (pre_expr_eq): Ditto
+       (get_constant_for_value_id): Take a type as an argument.
+       (fully_constant_expression): Pass in type.
+       (find_or_generate_expression): Short circuit constant case.
+       (create_expression_by_pieces): Remove special casing of
+       pointer_plus.
+       (do_regular_insertion): Short circuit constant case.
+       (do_partial_partial_insertion): Ditto.
+
 2008-07-15  Kaz Kojima  <kkojima@gcc.gnu.org>
 
        PR target/36782
index 9ca457cb952fc89e8ebb0932bed5ae10402c0c93..b5e38b4ba602f5fd8da01e5e468a2f7c1c0b0ee1 100644 (file)
@@ -1,5 +1,5 @@
 /* This code used to crash fold_convert due to PRE
-   wanting to fold_convert from a REA_TYPE to an INTEGER_TYPE.  */
+   wanting to fold_convert from a REAL_TYPE to an INTEGER_TYPE.  */
 typedef unsigned int uint32_t;
 union double_union
 {
index 07290bc48c4446423327b9e8293133d49d7b3898..efa934fb85329ceabb17cc84c2cdce3ef62fa7d0 100644 (file)
@@ -193,8 +193,13 @@ pre_expr_eq (const void *p1, const void *p2)
   switch (e1->kind)
     {
     case CONSTANT:
-      return expressions_equal_p (PRE_EXPR_CONSTANT (e1),
-                                 PRE_EXPR_CONSTANT (e2));
+      {
+       tree const0 = PRE_EXPR_CONSTANT (e1);
+       tree const1 = PRE_EXPR_CONSTANT (e2);
+       return TREE_TYPE (const1) == TREE_TYPE (const0)
+         && expressions_equal_p (const0, const1);
+      }
+      break;
     case NAME:
       return PRE_EXPR_NAME (e1) == PRE_EXPR_NAME (e2);
     case NARY:
@@ -316,8 +321,9 @@ get_or_alloc_expr_for_name (tree name)
   result_id = lookup_expression_id (result);
   if (result_id != 0)
     {
-      pool_free (pre_expr_pool, result);
-      result = expression_for_id (result_id);
+      pre_expr newresult = expression_for_id (result_id);
+      pool_free (pre_expr_pool, result); 
+      result = newresult;
       return result;
     }
   get_or_alloc_expression_id (result);
@@ -994,8 +1000,9 @@ get_or_alloc_expr_for_constant (tree constant)
   result_id = lookup_expression_id (newexpr);
   if (result_id != 0)
     {
-      pool_free (pre_expr_pool, newexpr);
-      newexpr = expression_for_id (result_id);
+      pre_expr newresult = expression_for_id (result_id);
+      pool_free (pre_expr_pool, newexpr); 
+      newexpr = newresult;
       return newexpr;
     }
   value_id = get_or_alloc_constant_value_id (constant);
@@ -1009,7 +1016,7 @@ get_or_alloc_expr_for_constant (tree constant)
    a constant.  */
 
 static tree
-get_constant_for_value_id (unsigned int v)
+get_constant_for_value_id (unsigned int v, tree type)
 {
   if (value_id_constant_p (v))
     {
@@ -1020,7 +1027,8 @@ get_constant_for_value_id (unsigned int v)
       FOR_EACH_EXPR_ID_IN_SET (exprset, i, bi)
        {
          pre_expr expr = expression_for_id (i);
-         if (expr->kind == CONSTANT)
+         if (expr->kind == CONSTANT
+             && TREE_TYPE (PRE_EXPR_CONSTANT (expr)) == type)
            return PRE_EXPR_CONSTANT (expr);
        }
     }
@@ -1064,8 +1072,10 @@ fully_constant_expression (pre_expr e)
              pre_expr rep1 = get_or_alloc_expr_for (naryop1);
              unsigned int vrep0 = get_expr_value_id (rep0);
              unsigned int vrep1 = get_expr_value_id (rep1);
-             tree const0 = get_constant_for_value_id (vrep0);
-             tree const1 = get_constant_for_value_id (vrep1);
+             tree const0 = get_constant_for_value_id (vrep0,
+                                                      TREE_TYPE (nary->op[0]));
+             tree const1 = get_constant_for_value_id (vrep1,
+                                                      TREE_TYPE (nary->op[1]));
              tree result = NULL;
              if (const0 && const1)
                {
@@ -1087,7 +1097,8 @@ fully_constant_expression (pre_expr e)
              tree naryop0 = nary->op[0];
              pre_expr rep0 = get_or_alloc_expr_for (naryop0);
              unsigned int vrep0 = get_expr_value_id (rep0);
-             tree const0 = get_constant_for_value_id (vrep0);
+             tree const0 = get_constant_for_value_id (vrep0,
+                                                      TREE_TYPE (nary->op[0]));
              tree result = NULL;
              if (const0)
                {
@@ -2599,9 +2610,14 @@ static tree
 find_or_generate_expression (basic_block block, pre_expr expr, tree stmts,
                             tree domstmt)
 {
-  pre_expr leader = bitmap_find_leader (AVAIL_OUT (block),
-                                       get_expr_value_id (expr), domstmt);
+  pre_expr leader;
   tree genop = NULL;
+
+  if (expr->kind == CONSTANT)
+    return PRE_EXPR_CONSTANT (expr);
+  
+  leader = bitmap_find_leader (AVAIL_OUT (block),
+                              get_expr_value_id (expr), domstmt);
   if (leader)
     {
       if (leader->kind == NAME)
@@ -2705,14 +2721,10 @@ create_expression_by_pieces (basic_block block, pre_expr expr, tree stmts,
                                                         stmts, domstmt);
              if (!genop1 || !genop2)
                return NULL_TREE;
+
              genop1 = fold_convert (TREE_TYPE (nary->op[0]),
                                     genop1);
-             /* Ensure op2 is a sizetype for POINTER_PLUS_EXPR.  It
-                may be a constant with the wrong type.  */
-             if (nary->opcode == POINTER_PLUS_EXPR)
-               genop2 = fold_convert (sizetype, genop2);
-             else
-               genop2 = fold_convert (TREE_TYPE (nary->op[1]), genop2);
+             genop2 = fold_convert (TREE_TYPE (nary->op[1]), genop2);
              
              folded = fold_build2 (nary->opcode, nary->type,
                                    genop1, genop2);
@@ -3141,9 +3153,16 @@ do_regular_insertion (basic_block block, basic_block dom)
                }
 
              eprime = fully_constant_expression (eprime);
-             vprime = get_expr_value_id (eprime);
-             edoubleprime = bitmap_find_leader (AVAIL_OUT (bprime),
-                                                vprime, NULL_TREE);
+             if (eprime->kind == CONSTANT)
+               {
+                 edoubleprime = eprime;
+               }
+             else
+               {
+                 vprime = get_expr_value_id (eprime);
+                 edoubleprime = bitmap_find_leader (AVAIL_OUT (bprime),
+                                                    vprime, NULL_TREE);
+               }
              if (edoubleprime == NULL)
                {
                  avail[bprime->index] = eprime;
@@ -3275,9 +3294,17 @@ do_partial_partial_insertion (basic_block block, basic_block dom)
                }
 
              eprime = fully_constant_expression (eprime);
-             vprime = get_expr_value_id (eprime);
-             edoubleprime = bitmap_find_leader (AVAIL_OUT (bprime),
-                                                vprime, NULL_TREE);
+             if (eprime->kind == CONSTANT)
+               {
+                 edoubleprime = eprime;
+               }
+             else
+               {
+                 vprime = get_expr_value_id (eprime);
+                 edoubleprime = bitmap_find_leader (AVAIL_OUT (bprime),
+                                                    vprime, NULL_TREE);
+               }
+             
              if (edoubleprime == NULL)
                {
                  by_all = false;
index f1318656b9b839bdff78b77df6c8bf3d323f830c..69945a5c3c74666fe468db7ea3e1454fca19b9a8 100644 (file)
@@ -2582,6 +2582,8 @@ expressions_equal_p (tree e1, tree e2)
 
   te1 = TREE_TYPE (e1);
   te2 = TREE_TYPE (e2);
+  if (te1 != te2)
+    return false;
 
   if (TREE_CODE (e1) == TREE_LIST && TREE_CODE (e2) == TREE_LIST)
     {