aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRoger Sayle <roger@eyesopen.com>2003-04-20 03:11:14 +0000
committerRoger Sayle <sayle@gcc.gnu.org>2003-04-20 03:11:14 +0000
commit0a45ec5c78e634e129fe3e9bbcddf6b721a10ca8 (patch)
treed3c6dc4d970337ee030f7fda0105a2d638d5ef0e /gcc
parent4049c77a01ab09b2b8bf59bd71a873ba672bcf86 (diff)
downloadgcc-0a45ec5c78e634e129fe3e9bbcddf6b721a10ca8.zip
gcc-0a45ec5c78e634e129fe3e9bbcddf6b721a10ca8.tar.gz
gcc-0a45ec5c78e634e129fe3e9bbcddf6b721a10ca8.tar.bz2
builtins.c (expand_builtin): Don't expand a pure or const built-in function if...
* builtins.c (expand_builtin): Don't expand a pure or const built-in function if the result will be ignored and none of its arguments are volatile. From-SVN: r65843
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/builtins.c30
2 files changed, 36 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c73e181..8d73923 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2003-04-19 Roger Sayle <roger@eyesopen.com>
+
+ * builtins.c (expand_builtin): Don't expand a pure or const
+ built-in function if the result will be ignored and none of
+ its arguments are volatile.
+
2003-04-19 Kean Johnston <jkj@sco.com>
* unwind-dw2.c (_Unwind_GetCFA): cast return to avoid warning
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 89f9531..87437d0 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -4139,6 +4139,36 @@ expand_builtin (exp, target, subtarget, mode, ignore)
break;
}
+ /* The built-in function expanders test for target == const0_rtx
+ to determine whether the function's result will be ignored. */
+ if (ignore)
+ target = const0_rtx;
+
+ /* If the result of a pure or const built-in function is ignored, and
+ none of its arguments are volatile, we can avoid expanding the
+ built-in call and just evaluate the arguments for side-effects. */
+ if (target == const0_rtx
+ && (DECL_IS_PURE (fndecl) || TREE_READONLY (fndecl)))
+ {
+ bool volatilep = false;
+ tree arg;
+
+ for (arg = arglist; arg; arg = TREE_CHAIN (arg))
+ if (TREE_THIS_VOLATILE (TREE_VALUE (arg)))
+ {
+ volatilep = true;
+ break;
+ }
+
+ if (! volatilep)
+ {
+ for (arg = arglist; arg; arg = TREE_CHAIN (arg))
+ expand_expr (TREE_VALUE (arg), const0_rtx,
+ VOIDmode, EXPAND_NORMAL);
+ return const0_rtx;
+ }
+ }
+
switch (fcode)
{
case BUILT_IN_ABS: