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][mem-ref2] Cleanup gimplification


This cleans up gimplification, fixing re-gimplifying during omp-lowering
on the way.

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

Richard.

2010-06-14  Richard Guenther  <rguenther@suse.de>

	* gimple.c (is_gimple_mem_ref_addr): New predicate.
	* gimple.h (is_gimple_mem_ref_addr): Declare.
	* gimplify.c (gimplify_expr): Use it when gimplifying MEM_REFs.

Index: gcc/gimplify.c
===================================================================
*** gcc/gimplify.c	(revision 160604)
--- gcc/gimplify.c	(working copy)
*************** gimplify_expr (tree *expr_p, gimple_seq
*** 6570,6576 ****
             || gimple_test_f == is_gimple_mem_rhs_or_call
             || gimple_test_f == is_gimple_reg_rhs
             || gimple_test_f == is_gimple_reg_rhs_or_call
!            || gimple_test_f == is_gimple_asm_val)
      gcc_assert (fallback & fb_rvalue);
    else if (gimple_test_f == is_gimple_min_lval
  	   || gimple_test_f == is_gimple_lvalue)
--- 6570,6577 ----
             || gimple_test_f == is_gimple_mem_rhs_or_call
             || gimple_test_f == is_gimple_reg_rhs
             || gimple_test_f == is_gimple_reg_rhs_or_call
!            || gimple_test_f == is_gimple_asm_val
! 	   || gimple_test_f == is_gimple_mem_ref_addr)
      gcc_assert (fallback & fb_rvalue);
    else if (gimple_test_f == is_gimple_min_lval
  	   || gimple_test_f == is_gimple_lvalue)
*************** gimplify_expr (tree *expr_p, gimple_seq
*** 6810,6828 ****
  	    break;
  	  }
  
  	case MEM_REF:
  	  tmp = fold_binary (MEM_REF, TREE_TYPE (*expr_p),
  			     TREE_OPERAND (*expr_p, 0),
  			     TREE_OPERAND (*expr_p, 1));
  	  if (tmp)
! 	    *expr_p = tmp;
! 	  ret = GS_ALL_DONE;
! 	  if (TREE_CODE (TREE_OPERAND (*expr_p, 0)) != ADDR_EXPR
! 	      || (!CONSTANT_CLASS_P (TREE_OPERAND (TREE_OPERAND (*expr_p, 0), 0))
! 		  && !decl_address_invariant_p (TREE_OPERAND (TREE_OPERAND (*expr_p, 0), 0))))
! 	    ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
! 				 is_gimple_reg, fb_rvalue);
  	  recalculate_side_effects (*expr_p);
  	  break;
  
  	  /* Constants need not be gimplified.  */
--- 6811,6833 ----
  	    break;
  	  }
  
+ 	/* We arrive here through the various re-gimplifcation paths.  */
  	case MEM_REF:
+ 	  /* First try re-folding the whole thing.  */
  	  tmp = fold_binary (MEM_REF, TREE_TYPE (*expr_p),
  			     TREE_OPERAND (*expr_p, 0),
  			     TREE_OPERAND (*expr_p, 1));
  	  if (tmp)
! 	    {
! 	      *expr_p = tmp;
! 	      recalculate_side_effects (*expr_p);
! 	      ret = GS_OK;
! 	      break;
! 	    }
! 	  ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
! 			       is_gimple_mem_ref_addr, fb_rvalue);
  	  recalculate_side_effects (*expr_p);
+ 	  ret = GS_ALL_DONE;
  	  break;
  
  	  /* Constants need not be gimplified.  */
Index: gcc/gimple.c
===================================================================
*** gcc/gimple.c	(revision 160604)
--- gcc/gimple.c	(working copy)
*************** is_gimple_call_addr (tree t)
*** 2934,2939 ****
--- 2934,2951 ----
    return (TREE_CODE (t) == OBJ_TYPE_REF || is_gimple_val (t));
  }
  
+ /* Return true if T is a valid address operand of a MEM_REF.  */
+ 
+ bool
+ is_gimple_mem_ref_addr (tree t)
+ {
+   return (is_gimple_reg (t)
+ 	  || TREE_CODE (t) == INTEGER_CST
+ 	  || (TREE_CODE (t) == ADDR_EXPR
+ 	      && (CONSTANT_CLASS_P (TREE_OPERAND (t, 0))
+ 		  || decl_address_invariant_p (TREE_OPERAND (t, 0)))));
+ }
+ 
  /* If T makes a function call, return the corresponding CALL_EXPR operand.
     Otherwise, return NULL_TREE.  */
  
Index: gcc/gimple.h
===================================================================
*** gcc/gimple.h	(revision 160604)
--- gcc/gimple.h	(working copy)
*************** extern bool is_gimple_ip_invariant (cons
*** 926,931 ****
--- 926,933 ----
  extern bool is_gimple_val (tree);
  /* Returns true iff T is a GIMPLE asm statement input.  */
  extern bool is_gimple_asm_val (tree);
+ /* Returns true iff T is a valid address operand of a MEM_REF.  */
+ bool is_gimple_mem_ref_addr (tree);
  /* Returns true iff T is a valid rhs for a MODIFY_EXPR where the LHS is a
     GIMPLE temporary, a renamed user variable, or something else,
     respectively.  */


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