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] Some TLC


Noticed when working on vector/complex folding and simplification.

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

Richard.

2011-10-06  Richard Guenther  <rguenther@suse.de>

	* fold-const.c (fold_ternary_loc): Also fold non-constant
	vector CONSTRUCTORs.  Make more efficient.
	* tree-ssa-dom.c (cprop_operand): Don't handle virtual operands.
	(cprop_into_stmt): Don't propagate into virtual operands.
	(optimize_stmt): Really dump original statement.

Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c	(revision 179592)
--- gcc/fold-const.c	(working copy)
*************** fold_ternary_loc (location_t loc, enum t
*** 13647,13653 ****
  
      case BIT_FIELD_REF:
        if ((TREE_CODE (arg0) == VECTOR_CST
! 	   || (TREE_CODE (arg0) == CONSTRUCTOR && TREE_CONSTANT (arg0)))
  	  && type == TREE_TYPE (TREE_TYPE (arg0)))
  	{
  	  unsigned HOST_WIDE_INT width = tree_low_cst (arg1, 1);
--- 13647,13653 ----
  
      case BIT_FIELD_REF:
        if ((TREE_CODE (arg0) == VECTOR_CST
! 	   || TREE_CODE (arg0) == CONSTRUCTOR)
  	  && type == TREE_TYPE (TREE_TYPE (arg0)))
  	{
  	  unsigned HOST_WIDE_INT width = tree_low_cst (arg1, 1);
*************** fold_ternary_loc (location_t loc, enum t
*** 13659,13682 ****
  	      && (idx = idx / width)
  		 < TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)))
  	    {
- 	      tree elements = NULL_TREE;
- 
  	      if (TREE_CODE (arg0) == VECTOR_CST)
- 		elements = TREE_VECTOR_CST_ELTS (arg0);
- 	      else
  		{
! 		  unsigned HOST_WIDE_INT idx;
! 		  tree value;
! 
! 		  FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (arg0), idx, value)
! 		    elements = tree_cons (NULL_TREE, value, elements);
  		}
! 	      while (idx-- > 0 && elements)
! 		elements = TREE_CHAIN (elements);
! 	      if (elements)
! 		return TREE_VALUE (elements);
! 	      else
! 		return build_zero_cst (type);
  	    }
  	}
  
--- 13659,13675 ----
  	      && (idx = idx / width)
  		 < TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)))
  	    {
  	      if (TREE_CODE (arg0) == VECTOR_CST)
  		{
! 		  tree elements = TREE_VECTOR_CST_ELTS (arg0);
! 		  while (idx-- > 0 && elements)
! 		    elements = TREE_CHAIN (elements);
! 		  if (elements)
! 		    return TREE_VALUE (elements);
  		}
! 	      else if (idx < CONSTRUCTOR_NELTS (arg0))
! 		return CONSTRUCTOR_ELT (arg0, idx)->value;
! 	      return build_zero_cst (type);
  	    }
  	}
  
Index: gcc/tree-ssa-dom.c
===================================================================
*** gcc/tree-ssa-dom.c	(revision 179592)
--- gcc/tree-ssa-dom.c	(working copy)
*************** cprop_operand (gimple stmt, use_operand_
*** 1995,2011 ****
    val = SSA_NAME_VALUE (op);
    if (val && val != op)
      {
-       /* Do not change the base variable in the virtual operand
- 	 tables.  That would make it impossible to reconstruct
- 	 the renamed virtual operand if we later modify this
- 	 statement.  Also only allow the new value to be an SSA_NAME
- 	 for propagation into virtual operands.  */
-       if (!is_gimple_reg (op)
- 	  && (TREE_CODE (val) != SSA_NAME
- 	      || is_gimple_reg (val)
- 	      || get_virtual_var (val) != get_virtual_var (op)))
- 	return;
- 
        /* Do not replace hard register operands in asm statements.  */
        if (gimple_code (stmt) == GIMPLE_ASM
  	  && !may_propagate_copy_into_asm (op))
--- 1995,2000 ----
*************** cprop_into_stmt (gimple stmt)
*** 2076,2086 ****
    use_operand_p op_p;
    ssa_op_iter iter;
  
!   FOR_EACH_SSA_USE_OPERAND (op_p, stmt, iter, SSA_OP_ALL_USES)
!     {
!       if (TREE_CODE (USE_FROM_PTR (op_p)) == SSA_NAME)
! 	cprop_operand (stmt, op_p);
!     }
  }
  
  /* Optimize the statement pointed to by iterator SI.
--- 2065,2072 ----
    use_operand_p op_p;
    ssa_op_iter iter;
  
!   FOR_EACH_SSA_USE_OPERAND (op_p, stmt, iter, SSA_OP_USE)
!     cprop_operand (stmt, op_p);
  }
  
  /* Optimize the statement pointed to by iterator SI.
*************** optimize_stmt (basic_block bb, gimple_st
*** 2107,2124 ****
  
    old_stmt = stmt = gsi_stmt (si);
  
-   if (gimple_code (stmt) == GIMPLE_COND)
-     canonicalize_comparison (stmt);
- 
-   update_stmt_if_modified (stmt);
-   opt_stats.num_stmts++;
- 
    if (dump_file && (dump_flags & TDF_DETAILS))
      {
        fprintf (dump_file, "Optimizing statement ");
        print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
      }
  
    /* Const/copy propagate into USES, VUSES and the RHS of VDEFs.  */
    cprop_into_stmt (stmt);
  
--- 2093,2110 ----
  
    old_stmt = stmt = gsi_stmt (si);
  
    if (dump_file && (dump_flags & TDF_DETAILS))
      {
        fprintf (dump_file, "Optimizing statement ");
        print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
      }
  
+   if (gimple_code (stmt) == GIMPLE_COND)
+     canonicalize_comparison (stmt);
+ 
+   update_stmt_if_modified (stmt);
+   opt_stats.num_stmts++;
+ 
    /* Const/copy propagate into USES, VUSES and the RHS of VDEFs.  */
    cprop_into_stmt (stmt);
  


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