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]

[tree-ssa] CCP fixes


This corrects our handling of statements with UNDEFINED operands
(which produces an UNDEFINED result).  It also re-enables one of the
two checks Diego disabled (VARYING->CONSTANT state transitions).

It's based on work from Diego and myself.

Bootstrapped and regression tested.

        * tree-ssa-ccp.c (likely_value): Renamed from may_fold_p.  Now
        returns a latticevalue indicating the likely value for the
	the RHS of the statement.
	(evaluate_stmt): Update to use likely_value instead of may_fold_p.
	Statements with UNDEFINED operands produce an UNDEFINED result.
	(set_lattice_value): Reenable VARYING->CONSTANT sanity check.
	
Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-ccp.c,v
retrieving revision 1.1.2.55
diff -c -3 -p -r1.1.2.55 tree-ssa-ccp.c
*** tree-ssa-ccp.c	25 Feb 2003 13:28:25 -0000	1.1.2.55
--- tree-ssa-ccp.c	25 Feb 2003 18:46:16 -0000
*************** static value evaluate_stmt		PARAMS ((tre
*** 117,123 ****
  static void dump_lattice_value		PARAMS ((FILE *, const char *, value));
  static tree widen_bitfield		PARAMS ((tree, tree, tree));
  static bool replace_uses_in		PARAMS ((tree));
! static bool may_fold_p			PARAMS ((tree));
  static void fold_stmt			PARAMS ((tree));
  static tree get_rhs			PARAMS ((tree));
  static void set_rhs			PARAMS ((tree, tree));
--- 117,123 ----
  static void dump_lattice_value		PARAMS ((FILE *, const char *, value));
  static tree widen_bitfield		PARAMS ((tree, tree, tree));
  static bool replace_uses_in		PARAMS ((tree));
! static latticevalue likely_value	PARAMS ((tree));
  static void fold_stmt			PARAMS ((tree));
  static tree get_rhs			PARAMS ((tree));
  static void set_rhs			PARAMS ((tree, tree));
*************** evaluate_stmt (stmt)
*** 748,769 ****
  {
    value val;
    tree simplified;
  
!   val.lattice_val = VARYING;
!   val.const_val = NULL_TREE;
! 
!   /* If one or more operands has been determined to be a constant,
!      then fold the expression.  */
!   if (may_fold_p (stmt))
      simplified = ccp_fold (stmt);
!   else
      simplified = get_rhs (stmt);
  
    if (simplified && really_constant_p (simplified))
      {
        val.lattice_val = CONSTANT;
        val.const_val = simplified;
      }
  
    /* Debugging dumps.  */
    if (dump_file && (dump_flags & TDF_DETAILS))
--- 748,782 ----
  {
    value val;
    tree simplified;
+   latticevalue likelyvalue = likely_value (stmt);
  
!   /* If the statement is likely to have a CONSTANT result, then try
!      to fold the statement to determine the constant value.  */
!   if (likelyvalue == CONSTANT)
      simplified = ccp_fold (stmt);
!   /* If the statement is likely to have a VARYING result, then do not
!      bother folding the statement.  */
!   else if (likelyvalue == VARYING)
      simplified = get_rhs (stmt);
+   /* Otherwise the statement is likely to have an UNDEFINED value and
+      there will be nothing to do.  */
+   else
+     simplified = NULL_TREE;
  
    if (simplified && really_constant_p (simplified))
      {
+       /* The statement produced a constant value.  */
        val.lattice_val = CONSTANT;
        val.const_val = simplified;
      }
+   else
+     {
+       /* The statement produced a nonconstant value.  If the statement
+          had undefined operands, then the result of the statement should
+ 	 be undefined.  Else the result of the statement is VARYING.  */
+       val.lattice_val = (likelyvalue == UNDEFINED ? UNDEFINED : VARYING);
+       val.const_val = NULL_TREE;
+     }
  
    /* Debugging dumps.  */
    if (dump_file && (dump_flags & TDF_DETAILS))
*************** set_lattice_value (var, val)
*** 1031,1039 ****
  
            add_var_to_ssa_edges_worklist (var);
  
-   /* FIXME: Hideous hack to overcome bugs in ccp_fold() that returns
-      VARYING for expressions that will later become UNDEFINED or CONSTANT.  
*/
- #if 0
  #ifdef ENABLE_CHECKING
  	  /* VARYING -> CONSTANT is an invalid state transition, except
  	     for objects which start off in a VARYING state.  */
--- 1044,1049 ----
*************** set_lattice_value (var, val)
*** 1041,1047 ****
  	      && get_default_value (var).lattice_val != VARYING)
  	    abort ();
  #endif
- #endif
  
  	  /* If the constant for VAR has changed, then this VAR is
  	     really varying.  */
--- 1051,1056 ----
*************** replace_uses_in (stmt)
*** 1090,1108 ****
    return replaced;
  }
  
  
! /* Return nonzero if STMT has a reasonable chance of folding into
!    something simpler.
  
!    We consider STMT likely to fold if at least one of its operands
!    is a constant.  */
  
! static bool
! may_fold_p (stmt)
       tree stmt;
  {
    varray_type uses;
    size_t i;
  
    get_stmt_operands (stmt);
  
--- 1099,1119 ----
    return replaced;
  }
  
+ /* Return the likely latticevalue for STMT.
  
!    If any operands of STMT are undefined, then return UNDEFINED.
  
!    Else if any operands of STMT are constants, then return CONSTANT.
  
!    Else return VARYING.  */
! 
! static latticevalue
! likely_value (stmt)
       tree stmt;
  {
    varray_type uses;
    size_t i;
+   int found_constant = 0;
  
    get_stmt_operands (stmt);
  
*************** may_fold_p (stmt)
*** 1112,1122 ****
        tree *use = VARRAY_GENERIC_PTR (uses, i);
        value *val = get_value (*use);
  
        if (val->lattice_val == CONSTANT)
! 	return true;
      }
  
!   return false;
  }
  
  
--- 1123,1136 ----
        tree *use = VARRAY_GENERIC_PTR (uses, i);
        value *val = get_value (*use);
  
+       if (val->lattice_val == UNDEFINED)
+ 	return UNDEFINED;
+ 
        if (val->lattice_val == CONSTANT)
! 	found_constant = 1;
      }
  
!   return (found_constant ? CONSTANT : VARYING);
  }
  
  




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