OSDN Git Service

* calls.c (expand_call): Avoid calling pure or const functions
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 4 Jun 2003 12:07:52 +0000 (12:07 +0000)
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 4 Jun 2003 12:07:52 +0000 (12:07 +0000)
when the result is ignored (or void) and none of the arguments
are volatile.  Move warning diagnostic earlier in function.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@67436 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/calls.c

index 8be4202..4199b50 100644 (file)
@@ -1,3 +1,9 @@
+2003-06-04  Roger Sayle  <roger@eyesopen.com>
+
+       * calls.c (expand_call): Avoid calling pure or const functions
+       when the result is ignored (or void) and none of the arguments
+       are volatile.  Move warning diagnostic earlier in function.
+
 2003-06-04  Andreas Jaeger  <aj@suse.de>
 
        * system.h: Do not poison TDESC_SECTION_ASM_OP,
@@ -15,7 +21,8 @@
        * cse.c: Include params.h.
        (PATHLENGTH): Removed.
        (struct cse_basic_block_data): Make path array dynamic.
-       (cse_end_of_basic_block): Use PARAM_MAX_CSE_PATH_LENGTH instead of PATHLENGTH.
+       (cse_end_of_basic_block): Use PARAM_MAX_CSE_PATH_LENGTH instead
+       of PATHLENGTH.
        (cse_main, cse_basic_block): Allocate path array.
        * params.def (PARAM_MAX_CSE_PATH_LENGTH): New.
 
index 4e95735..db6b884 100644 (file)
@@ -2211,6 +2211,37 @@ expand_call (exp, target, ignore)
   else
     flags |= flags_from_decl_or_type (TREE_TYPE (TREE_TYPE (p)));
 
+  /* Warn if this value is an aggregate type,
+     regardless of which calling convention we are using for it.  */
+  if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
+    warning ("function call has aggregate value");
+
+  /* If the result of a pure or const function call is ignored (or void),
+     and none of its arguments are volatile, we can avoid expanding the
+     call and just evaluate the arguments for side-effects.  */
+  if ((flags & (ECF_CONST | ECF_PURE))
+      && (ignore || target == const0_rtx
+         || TYPE_MODE (TREE_TYPE (exp)) == VOIDmode))
+    {
+      bool volatilep = false;
+      tree arg;
+
+      for (arg = actparms; arg; arg = TREE_CHAIN (arg))
+       if (TREE_THIS_VOLATILE (TREE_VALUE (arg)))
+         {
+           volatilep = true;
+           break;
+         }
+
+      if (! volatilep)
+       {
+         for (arg = actparms; arg; arg = TREE_CHAIN (arg))
+           expand_expr (TREE_VALUE (arg), const0_rtx,
+                        VOIDmode, EXPAND_NORMAL);
+         return const0_rtx;
+       }
+    }
+
 #ifdef REG_PARM_STACK_SPACE
 #ifdef MAYBE_REG_PARM_STACK_SPACE
   reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
@@ -2224,11 +2255,6 @@ expand_call (exp, target, ignore)
     must_preallocate = 1;
 #endif
 
-  /* Warn if this value is an aggregate type,
-     regardless of which calling convention we are using for it.  */
-  if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
-    warning ("function call has aggregate value");
-
   /* Set up a place to return a structure.  */
 
   /* Cater to broken compilers.  */