[ tree-ssa ] Another small CCP improvement

law@redhat.com law@redhat.com
Fri Feb 14 17:52:00 GMT 2003



Our state transitions are a little inefficient.    Let's consider what
happens when we have a state transition:


  1. We call set_value.  1 function call.

  2. set_value does a memory store calls htab_find_slot.  1 function call 1 mem

  3. htab_find_slot indirectly calls the hash function.  1 function call

  4. htab_find_slot then calls htab_find_slot_with_hash.  1 function call.

  5. htab_find_slot_with_hash does some checks on its arguments, some
     arithmetic, an indirect call to the comparison function.  If
     there is a collision, then we have even more work to do possibly
     looping.  Ugh.  At the least this is another function call and
     a 4 branches, one divmod, and 4 memory accesses.

  6. set_value then checks for null return value, access the slot.
     1 branch, 1 mem access

  7. Then we actually set the new lattice_val and const_val.


So we're looking at a minimum of 4 function calls, 6 memory accesses,
5 branches, and a divmod operator before we can actually store the new
value (step #7).

Why do I consider this so inefficient?  Because we already did steps #1-#6
and have the result handy.  So rather than redo steps #1-#6, we just do
step #7.  Sheesh.

This saves a couple more seconds of my tests.

Of course, we're doing more state transitions than we should, but that's
a separate issue.  There's no good reason for having to redo so much
work just to set two fields in a structure we've already got hanging
around in a local variable.

	* tree-ssa-ccp.c (def_to_undefined): Directly store the new
	lattice values rather than call set_value.
	(def_to_varying): Likewise.
        (set_lattice_value): Likewise.

Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-ccp.c,v
retrieving revision 1.1.2.49
diff -c -3 -p -r1.1.2.49 tree-ssa-ccp.c
*** tree-ssa-ccp.c	14 Feb 2003 17:03:27 -0000	1.1.2.49
--- tree-ssa-ccp.c	14 Feb 2003 17:37:22 -0000
*************** def_to_undefined (var)
*** 823,829 ****
  	fprintf (dump_file, "Lattice value changed.  Adding definition to SSA 
edges.\n");
  
        VARRAY_PUSH_TREE (ssa_edges, SSA_NAME_DEF_STMT (var));
!       set_value (var, UNDEFINED, NULL_TREE);
      }
  
  }
--- 823,830 ----
  	fprintf (dump_file, "Lattice value changed.  Adding definition to SSA 
edges.\n");
  
        VARRAY_PUSH_TREE (ssa_edges, SSA_NAME_DEF_STMT (var));
!       value->lattice_val = UNDEFINED;
!       value->const_val = NULL_TREE;
      }
  
  }
*************** def_to_varying (var)
*** 843,849 ****
  	fprintf (dump_file, "Lattice value changed.  Adding definition to SSA 
edges.\n");
  
        VARRAY_PUSH_TREE (ssa_edges, SSA_NAME_DEF_STMT (var));
!       set_value (var, VARYING, NULL_TREE);
      }
  
  }
--- 844,851 ----
  	fprintf (dump_file, "Lattice value changed.  Adding definition to SSA 
edges.\n");
  
        VARRAY_PUSH_TREE (ssa_edges, SSA_NAME_DEF_STMT (var));
!       value->lattice_val = VARYING;
!       value->const_val = NULL_TREE;
      }
  
  }
*************** set_lattice_value (var, val)
*** 885,893 ****
  	  /* If the constant for VAR has changed, then this VAR is
  	     really varying.  */
  	  if (old_val->lattice_val == CONSTANT)
! 	    set_value (var, VARYING, NULL_TREE);
  	  else
! 	    set_value (var, CONSTANT, val.const_val);
  
  	  VARRAY_PUSH_TREE (ssa_edges, SSA_NAME_DEF_STMT (var));
  	}
--- 887,901 ----
  	  /* If the constant for VAR has changed, then this VAR is
  	     really varying.  */
  	  if (old_val->lattice_val == CONSTANT)
! 	    {
! 	      old_val->lattice_val = VARYING;
! 	      old_val->const_val = NULL_TREE;
! 	    }
  	  else
! 	    {
! 	      old_val->lattice_val = CONSTANT;
! 	      old_val->const_val = val.const_val;
! 	    }
  
  	  VARRAY_PUSH_TREE (ssa_edges, SSA_NAME_DEF_STMT (var));
  	}






More information about the Gcc-patches mailing list