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][WIP] Enable type verification throughout optimization


This enables type verification throughout optimizations.  It doesn't
yet pass bootstrap (Ada RTS and libstdc++ fail), but it's a start.

The patch fixes some issues in the verifier (basically do not try to
verify anything about funny vector stmts (yet) and adjust shift
verification for vector arguments).  It also fixes two bugs in
the vectorizer.

More vectorizer issues remain and I seem to hit a tree reassoc bug
during Ada RTS build.  Also C++ for now needs the hack appended below.

Richard.

2008-09-11  Richard Guenther  <rguenther@suse.de>

	* tree-cfg.c (remove_useless_stmts): Verify stmts afterwards.
	(verify_stmts): Dispatch to gimple/type verification code.
	* tree-vect-loop-manip.c (vect_update_ivs_after_vectorizer):
	Fix types.
	(vect_update_init_of_dr): Likewise.

Index: gcc/tree-cfg.c
===================================================================
*** gcc/tree-cfg.c	2009-04-09 10:05:51.000000000 +0200
--- gcc/tree-cfg.c	2009-04-09 16:17:32.000000000 +0200
*************** remove_useless_stmts (void)
*** 2061,2066 ****
--- 2061,2071 ----
        remove_useless_stmts_1 (&gsi, &data);
      }
    while (data.repeat);
+ 
+ #ifdef ENABLE_TYPES_CHECKING
+   verify_types_in_gimple_seq (gimple_body (current_function_decl));
+ #endif
+ 
    return 0;
  }
  
*************** verify_gimple_assign_unary (gimple stmt)
*** 3411,3433 ****
          return false;
        }
  
!     case TRUTH_NOT_EXPR:
!       {
!       }
  
      case NEGATE_EXPR:
      case ABS_EXPR:
      case BIT_NOT_EXPR:
      case PAREN_EXPR:
      case NON_LVALUE_EXPR:
      case CONJ_EXPR:
-     case REDUC_MAX_EXPR:
-     case REDUC_MIN_EXPR:
-     case REDUC_PLUS_EXPR:
-     case VEC_UNPACK_HI_EXPR:
-     case VEC_UNPACK_LO_EXPR:
-     case VEC_UNPACK_FLOAT_HI_EXPR:
-     case VEC_UNPACK_FLOAT_LO_EXPR:
        break;
  
      default:
--- 3416,3438 ----
          return false;
        }
  
!     case VEC_UNPACK_HI_EXPR:
!     case VEC_UNPACK_LO_EXPR:
!     case REDUC_MAX_EXPR:
!     case REDUC_MIN_EXPR:
!     case REDUC_PLUS_EXPR:
!     case VEC_UNPACK_FLOAT_HI_EXPR:
!     case VEC_UNPACK_FLOAT_LO_EXPR:
!       /* FIXME.  */
!       return false;
  
+     case TRUTH_NOT_EXPR:
      case NEGATE_EXPR:
      case ABS_EXPR:
      case BIT_NOT_EXPR:
      case PAREN_EXPR:
      case NON_LVALUE_EXPR:
      case CONJ_EXPR:
        break;
  
      default:
*************** verify_gimple_assign_binary (gimple stmt
*** 3498,3514 ****
  
      case LSHIFT_EXPR:
      case RSHIFT_EXPR:
-       if (FIXED_POINT_TYPE_P (rhs1_type)
- 	  && INTEGRAL_TYPE_P (rhs2_type)
- 	  && useless_type_conversion_p (lhs_type, rhs1_type))
- 	return false;
-       /* Fall through.  */
- 
      case LROTATE_EXPR:
      case RROTATE_EXPR:
        {
! 	if (!INTEGRAL_TYPE_P (rhs1_type)
! 	    || !INTEGRAL_TYPE_P (rhs2_type)
  	    || !useless_type_conversion_p (lhs_type, rhs1_type))
  	  {
  	    error ("type mismatch in shift expression");
--- 3503,3523 ----
  
      case LSHIFT_EXPR:
      case RSHIFT_EXPR:
      case LROTATE_EXPR:
      case RROTATE_EXPR:
        {
! 	/* Shifts and rotates are ok on integral types, fixed point
! 	   types and integer vector types.  */
! 	if ((!INTEGRAL_TYPE_P (rhs1_type)
! 	     && !FIXED_POINT_TYPE_P (rhs1_type)
! 	     && !(TREE_CODE (rhs1_type) == VECTOR_TYPE
! 		  && TREE_CODE (TREE_TYPE (rhs1_type)) == INTEGER_TYPE))
! 	    || (!INTEGRAL_TYPE_P (rhs2_type)
! 		/* Vector shifts of vectors are also ok.  */
! 		&& !(TREE_CODE (rhs1_type) == VECTOR_TYPE
! 		     && TREE_CODE (TREE_TYPE (rhs1_type)) == INTEGER_TYPE
! 		     && TREE_CODE (rhs2_type) == VECTOR_TYPE
! 		     && TREE_CODE (TREE_TYPE (rhs2_type)) == INTEGER_TYPE))
  	    || !useless_type_conversion_p (lhs_type, rhs1_type))
  	  {
  	    error ("type mismatch in shift expression");
*************** verify_gimple_assign_binary (gimple stmt
*** 3614,3619 ****
--- 3623,3642 ----
  	break;
        }
  
+     case WIDEN_SUM_EXPR:
+     case WIDEN_MULT_EXPR:
+     case VEC_WIDEN_MULT_HI_EXPR:
+     case VEC_WIDEN_MULT_LO_EXPR:
+     case VEC_PACK_TRUNC_EXPR:
+     case VEC_PACK_SAT_EXPR:
+     case VEC_PACK_FIX_TRUNC_EXPR:
+     case VEC_EXTRACT_EVEN_EXPR:
+     case VEC_EXTRACT_ODD_EXPR:
+     case VEC_INTERLEAVE_HIGH_EXPR:
+     case VEC_INTERLEAVE_LOW_EXPR:
+       /* FIXME.  */
+       return false;
+ 
      case MULT_EXPR:
      case TRUNC_DIV_EXPR:
      case CEIL_DIV_EXPR:
*************** verify_gimple_assign_binary (gimple stmt
*** 3630,3646 ****
      case BIT_IOR_EXPR:
      case BIT_XOR_EXPR:
      case BIT_AND_EXPR:
-     case WIDEN_SUM_EXPR:
-     case WIDEN_MULT_EXPR:
-     case VEC_WIDEN_MULT_HI_EXPR:
-     case VEC_WIDEN_MULT_LO_EXPR:
-     case VEC_PACK_TRUNC_EXPR:
-     case VEC_PACK_SAT_EXPR:
-     case VEC_PACK_FIX_TRUNC_EXPR:
-     case VEC_EXTRACT_EVEN_EXPR:
-     case VEC_EXTRACT_ODD_EXPR:
-     case VEC_INTERLEAVE_HIGH_EXPR:
-     case VEC_INTERLEAVE_LOW_EXPR:
        /* Continue with generic binary expression handling.  */
        break;
  
--- 3653,3658 ----
*************** verify_gimple_phi (gimple stmt)
*** 3905,3911 ****
  	}
        if (!useless_type_conversion_p (type, TREE_TYPE (arg)))
  	{
! 	  error ("Incompatible types in PHI argument");
  	  debug_generic_stmt (type);
  	  debug_generic_stmt (TREE_TYPE (arg));
  	  return true;
--- 3917,3923 ----
  	}
        if (!useless_type_conversion_p (type, TREE_TYPE (arg)))
  	{
! 	  error ("Incompatible types in PHI argument %u", i);
  	  debug_generic_stmt (type);
  	  debug_generic_stmt (TREE_TYPE (arg));
  	  return true;
*************** verify_stmts (void)
*** 4251,4256 ****
--- 4263,4276 ----
  		  err |= true;
  		}
  	    }
+ 
+ #ifdef ENABLE_TYPES_CHECKING
+ 	  if (verify_gimple_phi (phi))
+ 	    {
+ 	      debug_gimple_stmt (phi);
+ 	      err |= true;
+ 	    }
+ #endif
  	}
  
        for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); )
*************** verify_stmts (void)
*** 4287,4292 ****
--- 4307,4320 ----
  	    }
  
  	  err |= verify_stmt (&gsi);
+ 
+ #ifdef ENABLE_TYPES_CHECKING
+ 	  if (verify_types_in_gimple_stmt (gsi_stmt (gsi)))
+ 	    {
+ 	      debug_gimple_stmt (stmt);
+ 	      err |= true;
+ 	    }
+ #endif
  	  addr = walk_gimple_op (gsi_stmt (gsi), verify_node_sharing, &wi);
  	  if (addr)
  	    {
Index: gcc/tree-vect-loop-manip.c
===================================================================
*** gcc/tree-vect-loop-manip.c	(revision 145838)
--- gcc/tree-vect-loop-manip.c	(working copy)
*************** vect_update_ivs_after_vectorizer (loop_v
*** 1639,1647 ****
        if (POINTER_TYPE_P (TREE_TYPE (init_expr)))
  	ni = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (init_expr), 
  			  init_expr, 
! 			  fold_convert (sizetype, 
! 					fold_build2 (MULT_EXPR, TREE_TYPE (niters),
! 						     niters, step_expr)));
        else
  	ni = fold_build2 (PLUS_EXPR, TREE_TYPE (init_expr),
  			  fold_build2 (MULT_EXPR, TREE_TYPE (init_expr),
--- 1639,1647 ----
        if (POINTER_TYPE_P (TREE_TYPE (init_expr)))
  	ni = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (init_expr), 
  			  init_expr, 
! 			  fold_build2 (MULT_EXPR, sizetype,
! 				       fold_convert (sizetype, niters),
! 				       step_expr));
        else
  	ni = fold_build2 (PLUS_EXPR, TREE_TYPE (init_expr),
  			  fold_build2 (MULT_EXPR, TREE_TYPE (init_expr),
*************** vect_update_init_of_dr (struct data_refe
*** 1926,1932 ****
    niters = fold_build2 (MULT_EXPR, sizetype,
  			fold_convert (sizetype, niters),
  			fold_convert (sizetype, DR_STEP (dr)));
!   offset = fold_build2 (PLUS_EXPR, sizetype, offset, niters);
    DR_OFFSET (dr) = offset;
  }
  
--- 1926,1933 ----
    niters = fold_build2 (MULT_EXPR, sizetype,
  			fold_convert (sizetype, niters),
  			fold_convert (sizetype, DR_STEP (dr)));
!   offset = fold_build2 (PLUS_EXPR, sizetype,
! 			fold_convert (sizetype, offset), niters);
    DR_OFFSET (dr) = offset;
  }
  


2008-09-11  Richard Guenther  <rguenther@suse.de>

	* tree-inline.c (remap_gimple_op_r): Work around C++ FE
	issue with call argument types.

Index: trunk/gcc/tree-inline.c
===================================================================
*** trunk.orig/gcc/tree-inline.c	2008-09-13 18:28:29.000000000 +0200
--- trunk/gcc/tree-inline.c	2008-09-13 18:33:44.000000000 +0200
***************
*** 635,640 ****
--- 635,647 ----
        gcc_assert (new_decl);
        /* Replace this variable with the copy.  */
        STRIP_TYPE_NOPS (new_decl);
+       /* ???  The C++ frontend uses void * pointer zero to initialize
+          any other type.  This confuses the middle-end type verification.
+ 	 As cloned bodies do not go through gimplification again the fixup
+ 	 there doesn't trigger.  */
+       if (TREE_CODE (new_decl) == INTEGER_CST
+ 	  && !useless_type_conversion_p (TREE_TYPE (*tp), TREE_TYPE (new_decl)))
+ 	new_decl = fold_convert (TREE_TYPE (*tp), new_decl);
        *tp = new_decl;
        *walk_subtrees = 0;
      }


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