This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] CALL_EXPR support for operand_equal_p
- From: law at redhat dot com
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 11 Jun 2003 22:44:13 -0600
- Subject: [tree-ssa] CALL_EXPR support for operand_equal_p
- Reply-to: law at redhat dot com
One of the pieces of infrastructure we need to be able to eliminate
useless or redundant calls to "const" functions. In simplest terms
this allows us to use operand_equal_p to determine if two given CALL_EXPRs
call the same function with the same arguments.
The usual testing has been done with this patch in a tree which has the
rest of the infrastructure required to remove useless or redundant calls
to "const" functions.
* fold-const.c (operand_equal_p): Handle CALL_EXPRs.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.213.2.30
diff -c -3 -p -r1.213.2.30 fold-const.c
*** fold-const.c 9 Jun 2003 22:40:33 -0000 1.213.2.30
--- fold-const.c 12 Jun 2003 04:42:17 -0000
*************** operand_equal_p (arg0, arg1, only_const)
*** 2016,2021 ****
--- 2016,2046 ----
case RTL_EXPR:
return rtx_equal_p (RTL_EXPR_RTL (arg0), RTL_EXPR_RTL (arg1));
+ case CALL_EXPR:
+ /* If the CALL_EXPRs call different functions, then they
+ clearly can not be equal. */
+ if (! operand_equal_p (TREE_OPERAND (arg0, 0),
+ TREE_OPERAND (arg1, 0), 0))
+ return 0;
+
+ /* Now see if all the arguments are the same. operand_equal_p
+ does not handle TREE_LIST, so we walk the operands here
+ feeding them to operand_equal_p. */
+ arg0 = TREE_OPERAND (arg0, 1);
+ arg1 = TREE_OPERAND (arg1, 1);
+ while (arg0 && arg1)
+ {
+ if (! operand_equal_p (TREE_VALUE (arg0), TREE_VALUE (arg1), 0))
+ return 0;
+
+ arg0 = TREE_CHAIN (arg0);
+ arg1 = TREE_CHAIN (arg1);
+ }
+
+ /* If we get here and both argument lists are exhausted
+ then the CALL_EXPRs are equal. */
+ return ! (arg0 || arg1);
+
default:
return 0;
}