This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] TLC PRE/SCCVN


This fixes some low-hanging fruit I came along while looking
at the profiles of PR18687.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2010-01-04  Richard Guenther  <rguenther@suse.de>

	* tree-ssa-sccvn.c (vn_reference_op_compute_hash): Use
	iterative_hash_* as intended.
	(vn_reference_compute_hash): Likewise.  Simplify hashing
	SSA names.
	(vn_reference_lookup_2): Likewise.
	(vn_nary_op_compute_hash): Likewise.
	(vn_phi_compute_hash): Likewise.
	(expressions_equal_p): Remove strange code.
	* tree-ssa-pre.c (pre_expr_eq): Use gcc_unreachable ().
	(pre_expr_hash): Likewise.  Simplify hashing SSA names.
	(bitmap_insert_into_set_1): Take value-id as parameter.
	(add_to_value): Pass it.
	(bitmap_insert_into_set): Likewise.
	(bitmap_value_insert_into_set): Likewise.  Remove redundant check.

Index: gcc/tree-ssa-sccvn.c
===================================================================
*** gcc/tree-ssa-sccvn.c	(revision 155597)
--- gcc/tree-ssa-sccvn.c	(working copy)
*************** vn_reference_op_eq (const void *p1, cons
*** 401,415 ****
  /* Compute the hash for a reference operand VRO1.  */
  
  static hashval_t
! vn_reference_op_compute_hash (const vn_reference_op_t vro1)
  {
!   hashval_t result = 0;
    if (vro1->op0)
!     result += iterative_hash_expr (vro1->op0, vro1->opcode);
    if (vro1->op1)
!     result += iterative_hash_expr (vro1->op1, vro1->opcode);
    if (vro1->op2)
!     result += iterative_hash_expr (vro1->op2, vro1->opcode);
    return result;
  }
  
--- 401,415 ----
  /* Compute the hash for a reference operand VRO1.  */
  
  static hashval_t
! vn_reference_op_compute_hash (const vn_reference_op_t vro1, hashval_t result)
  {
!   result = iterative_hash_hashval_t (vro1->opcode, result);
    if (vro1->op0)
!     result = iterative_hash_expr (vro1->op0, result);
    if (vro1->op1)
!     result = iterative_hash_expr (vro1->op1, result);
    if (vro1->op2)
!     result = iterative_hash_expr (vro1->op2, result);
    return result;
  }
  
*************** vn_reference_hash (const void *p1)
*** 427,439 ****
  hashval_t
  vn_reference_compute_hash (const vn_reference_t vr1)
  {
!   hashval_t result;
    int i;
    vn_reference_op_t vro;
  
-   result = iterative_hash_expr (vr1->vuse, 0);
    for (i = 0; VEC_iterate (vn_reference_op_s, vr1->operands, i, vro); i++)
!     result += vn_reference_op_compute_hash (vro);
  
    return result;
  }
--- 427,440 ----
  hashval_t
  vn_reference_compute_hash (const vn_reference_t vr1)
  {
!   hashval_t result = 0;
    int i;
    vn_reference_op_t vro;
  
    for (i = 0; VEC_iterate (vn_reference_op_s, vr1->operands, i, vro); i++)
!     result = vn_reference_op_compute_hash (vro, result);
!   if (vr1->vuse)
!     result += SSA_NAME_VERSION (vr1->vuse);
  
    return result;
  }
*************** vn_reference_lookup_2 (ao_ref *op ATTRIB
*** 1000,1008 ****
      *last_vuse_ptr = vuse;
  
    /* Fixup vuse and hash.  */
!   vr->hashcode = vr->hashcode - iterative_hash_expr (vr->vuse, 0);
    vr->vuse = SSA_VAL (vuse);
!   vr->hashcode = vr->hashcode + iterative_hash_expr (vr->vuse, 0);
  
    hash = vr->hashcode;
    slot = htab_find_slot_with_hash (current_info->references, vr,
--- 1001,1011 ----
      *last_vuse_ptr = vuse;
  
    /* Fixup vuse and hash.  */
!   if (vr->vuse)
!     vr->hashcode = vr->hashcode - SSA_NAME_VERSION (vr->vuse);
    vr->vuse = SSA_VAL (vuse);
!   if (vr->vuse)
!     vr->hashcode = vr->hashcode + SSA_NAME_VERSION (vr->vuse);
  
    hash = vr->hashcode;
    slot = htab_find_slot_with_hash (current_info->references, vr,
*************** vn_reference_insert_pieces (tree vuse, a
*** 1360,1366 ****
  hashval_t
  vn_nary_op_compute_hash (const vn_nary_op_t vno1)
  {
!   hashval_t hash = 0;
    unsigned i;
  
    for (i = 0; i < vno1->length; ++i)
--- 1363,1369 ----
  hashval_t
  vn_nary_op_compute_hash (const vn_nary_op_t vno1)
  {
!   hashval_t hash;
    unsigned i;
  
    for (i = 0; i < vno1->length; ++i)
*************** vn_nary_op_compute_hash (const vn_nary_o
*** 1376,1383 ****
        vno1->op[1] = temp;
      }
  
    for (i = 0; i < vno1->length; ++i)
!     hash += iterative_hash_expr (vno1->op[i], vno1->opcode);
  
    return hash;
  }
--- 1379,1387 ----
        vno1->op[1] = temp;
      }
  
+   hash = iterative_hash_hashval_t (vno1->opcode, 0);
    for (i = 0; i < vno1->length; ++i)
!     hash = iterative_hash_expr (vno1->op[i], hash);
  
    return hash;
  }
*************** vn_nary_op_insert_stmt (gimple stmt, tre
*** 1629,1635 ****
  static inline hashval_t
  vn_phi_compute_hash (vn_phi_t vp1)
  {
!   hashval_t result = 0;
    int i;
    tree phi1op;
    tree type;
--- 1633,1639 ----
  static inline hashval_t
  vn_phi_compute_hash (vn_phi_t vp1)
  {
!   hashval_t result;
    int i;
    tree phi1op;
    tree type;
*************** vn_phi_compute_hash (vn_phi_t vp1)
*** 1647,1653 ****
      {
        if (phi1op == VN_TOP)
  	continue;
!       result += iterative_hash_expr (phi1op, result);
      }
  
    return result;
--- 1651,1657 ----
      {
        if (phi1op == VN_TOP)
  	continue;
!       result = iterative_hash_expr (phi1op, result);
      }
  
    return result;
*************** expressions_equal_p (tree e1, tree e2)
*** 3310,3332 ****
    if (!e1 || !e2)
      return false;
  
-   /* Recurse on elements of lists.  */
-   if (TREE_CODE (e1) == TREE_LIST && TREE_CODE (e2) == TREE_LIST)
-     {
-       tree lop1 = e1;
-       tree lop2 = e2;
-       for (lop1 = e1, lop2 = e2;
- 	   lop1 || lop2;
- 	   lop1 = TREE_CHAIN (lop1), lop2 = TREE_CHAIN (lop2))
- 	{
- 	  if (!lop1 || !lop2)
- 	    return false;
- 	  if (!expressions_equal_p (TREE_VALUE (lop1), TREE_VALUE (lop2)))
- 	    return false;
- 	}
-       return true;
-     }
- 
    /* Now perform the actual comparison.  */
    if (TREE_CODE (e1) == TREE_CODE (e2)
        && operand_equal_p (e1, e2, OEP_PURE_SAME))
--- 3314,3319 ----
Index: gcc/tree-ssa-pre.c
===================================================================
*** gcc/tree-ssa-pre.c	(revision 155597)
--- gcc/tree-ssa-pre.c	(working copy)
*************** pre_expr_eq (const void *p1, const void 
*** 204,210 ****
        return vn_reference_eq (PRE_EXPR_REFERENCE (e1),
  			      PRE_EXPR_REFERENCE (e2));
      default:
!       abort();
      }
  }
  
--- 204,210 ----
        return vn_reference_eq (PRE_EXPR_REFERENCE (e1),
  			      PRE_EXPR_REFERENCE (e2));
      default:
!       gcc_unreachable ();
      }
  }
  
*************** pre_expr_hash (const void *p1)
*** 217,229 ****
      case CONSTANT:
        return vn_hash_constant_with_type (PRE_EXPR_CONSTANT (e));
      case NAME:
!       return iterative_hash_hashval_t (SSA_NAME_VERSION (PRE_EXPR_NAME (e)), 0);
      case NARY:
        return PRE_EXPR_NARY (e)->hashcode;
      case REFERENCE:
        return PRE_EXPR_REFERENCE (e)->hashcode;
      default:
!       abort ();
      }
  }
  
--- 217,229 ----
      case CONSTANT:
        return vn_hash_constant_with_type (PRE_EXPR_CONSTANT (e));
      case NAME:
!       return SSA_NAME_VERSION (PRE_EXPR_NAME (e));
      case NARY:
        return PRE_EXPR_NARY (e)->hashcode;
      case REFERENCE:
        return PRE_EXPR_REFERENCE (e)->hashcode;
      default:
!       gcc_unreachable ();
      }
  }
  
*************** static void bitmap_value_replace_in_set 
*** 436,442 ****
  static void bitmap_set_copy (bitmap_set_t, bitmap_set_t);
  static bool bitmap_set_contains_value (bitmap_set_t, unsigned int);
  static void bitmap_insert_into_set (bitmap_set_t, pre_expr);
! static void bitmap_insert_into_set_1 (bitmap_set_t, pre_expr, bool);
  static bitmap_set_t bitmap_set_new (void);
  static tree create_expression_by_pieces (basic_block, pre_expr, gimple_seq *,
  					 gimple, tree);
--- 436,443 ----
  static void bitmap_set_copy (bitmap_set_t, bitmap_set_t);
  static bool bitmap_set_contains_value (bitmap_set_t, unsigned int);
  static void bitmap_insert_into_set (bitmap_set_t, pre_expr);
! static void bitmap_insert_into_set_1 (bitmap_set_t, pre_expr,
! 				      unsigned int, bool);
  static bitmap_set_t bitmap_set_new (void);
  static tree create_expression_by_pieces (basic_block, pre_expr, gimple_seq *,
  					 gimple, tree);
*************** add_to_value (unsigned int v, pre_expr e
*** 580,586 ****
        VEC_replace (bitmap_set_t, value_expressions, v, set);
      }
  
!   bitmap_insert_into_set_1 (set, e, true);
  }
  
  /* Create a new bitmap set and return it.  */
--- 581,587 ----
        VEC_replace (bitmap_set_t, value_expressions, v, set);
      }
  
!   bitmap_insert_into_set_1 (set, e, v, true);
  }
  
  /* Create a new bitmap set and return it.  */
*************** bitmap_remove_from_set (bitmap_set_t set
*** 638,646 ****
  
  static void
  bitmap_insert_into_set_1 (bitmap_set_t set, pre_expr expr,
! 			  bool allow_constants)
  {
-   unsigned int val  = get_expr_value_id (expr);
    if (allow_constants || !value_id_constant_p (val))
      {
        /* We specifically expect this and only this function to be able to
--- 639,646 ----
  
  static void
  bitmap_insert_into_set_1 (bitmap_set_t set, pre_expr expr,
! 			  unsigned int val, bool allow_constants)
  {
    if (allow_constants || !value_id_constant_p (val))
      {
        /* We specifically expect this and only this function to be able to
*************** bitmap_insert_into_set_1 (bitmap_set_t s
*** 655,661 ****
  static void
  bitmap_insert_into_set (bitmap_set_t set, pre_expr expr)
  {
!   bitmap_insert_into_set_1 (set, expr, false);
  }
  
  /* Copy a bitmapped set ORIG, into bitmapped set DEST.  */
--- 655,661 ----
  static void
  bitmap_insert_into_set (bitmap_set_t set, pre_expr expr)
  {
!   bitmap_insert_into_set_1 (set, expr, get_expr_value_id (expr), false);
  }
  
  /* Copy a bitmapped set ORIG, into bitmapped set DEST.  */
*************** bitmap_value_insert_into_set (bitmap_set
*** 863,873 ****
  {
    unsigned int val = get_expr_value_id (expr);
  
-   if (value_id_constant_p (val))
-     return;
- 
    if (!bitmap_set_contains_value (set, val))
!     bitmap_insert_into_set (set, expr);
  }
  
  /* Print out EXPR to outfile.  */
--- 863,870 ----
  {
    unsigned int val = get_expr_value_id (expr);
  
    if (!bitmap_set_contains_value (set, val))
!     bitmap_insert_into_set_1 (set, expr, val, false);
  }
  
  /* Print out EXPR to outfile.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]