[tree-ssa] folding builtins [patch]
Diego Novillo
dnovillo@redhat.com
Thu Feb 27 20:17:00 GMT 2003
Changes the way we fold builtins. Instead of creating a deep
copy of the builtin, it replaces its arguments with their known
values, calls fold_builtin and restores the original arguments.
Bootstrapped and tested on x86.
Diego.
* tree-ssa-ccp.c (ccp_fold): Fold builtins by replacing and
restoring their arguments.
Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-ccp.c,v
retrieving revision 1.1.2.59
diff -d -u -p -r1.1.2.59 tree-ssa-ccp.c
--- tree-ssa-ccp.c 26 Feb 2003 23:09:32 -0000 1.1.2.59
+++ tree-ssa-ccp.c 27 Feb 2003 19:59:55 -0000
@@ -643,7 +643,7 @@ ccp_fold (stmt)
tree rhs = get_rhs (stmt);
enum tree_code code = TREE_CODE (rhs);
int kind = TREE_CODE_CLASS (code);
- tree retval;
+ tree retval = NULL_TREE;
/* If the RHS is just a variable, then that variable must now have
a constant value that we can return directly. */
@@ -740,9 +740,26 @@ ccp_fold (stmt)
== FUNCTION_DECL)
&& DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (rhs, 0), 0)))
{
- tree copy = copy_stmt (stmt);
- replace_uses_in (copy);
- retval = fold_builtin (get_rhs (copy));
+ varray_type uses = use_ops (stmt);
+ if (uses)
+ {
+ tree *orig;
+ size_t i;
+
+ /* Preserve the original values of every operand. */
+ orig = xmalloc (sizeof (tree) * VARRAY_ACTIVE_SIZE (uses));
+ for (i = 0; i < VARRAY_ACTIVE_SIZE (uses); i++)
+ orig[i] = *((tree *) VARRAY_GENERIC_PTR (uses, i));
+
+ /* Substitute operands with their values and try to fold. */
+ replace_uses_in (stmt);
+ retval = fold_builtin (rhs);
+
+ /* Restore operands to their original form. */
+ for (i = 0; i < VARRAY_ACTIVE_SIZE (uses); i++)
+ *((tree *) VARRAY_GENERIC_PTR (uses, i)) = orig[i];
+ free (orig);
+ }
}
else
return rhs;
More information about the Gcc-patches
mailing list