diff mbox

Don't optimize away calls to looping pure builtins (PR middle-end/44974)

Message ID 20100820181409.GG702@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Aug. 20, 2010, 6:14 p.m. UTC
Hi!

If some builtin has definition available to the compiler and
this noreturn definition just calls some other noreturn function,
Honza's recent changes mark if as DECL_PURE_P with
DECL_LOOPING_CONST_OR_PURE_P, which says to DCE that it shouldn't
optimize such calls away, but it can be CSEd etc.

expand_builtin wasn't expecting that any builtin might
be DECL_LOOPING_CONST_OR_PURE_P though and thus was
optimizing away any call to pure or const builtin, if the return
value is ignored.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2010-08-20  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/44974
	* builtins.c (expand_builtin): Don't optimize away
	calls to DECL_LOOPING_CONST_OR_PURE_P builtins.

	* gcc.dg/pr44974.c: New test.


	Jakub

Comments

Richard Henderson Aug. 20, 2010, 6:48 p.m. UTC | #1
On 08/20/2010 11:14 AM, Jakub Jelinek wrote:
> 	PR middle-end/44974
> 	* builtins.c (expand_builtin): Don't optimize away
> 	calls to DECL_LOOPING_CONST_OR_PURE_P builtins.
> 
> 	* gcc.dg/pr44974.c: New test.

Ok.


r~
diff mbox

Patch

--- gcc/builtins.c.jj	2010-08-13 10:15:19.000000000 +0200
+++ gcc/builtins.c	2010-08-20 16:51:09.000000000 +0200
@@ -5770,7 +5770,8 @@  expand_builtin (tree exp, rtx target, rt
      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_PURE_P (fndecl) || TREE_READONLY (fndecl)))
+      && (DECL_PURE_P (fndecl) || TREE_READONLY (fndecl))
+      && !DECL_LOOPING_CONST_OR_PURE_P (fndecl))
     {
       bool volatilep = false;
       tree arg;
--- gcc/testsuite/gcc.dg/pr44974.c.jj	2010-08-20 17:11:04.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr44974.c	2010-08-20 17:10:10.000000000 +0200
@@ -0,0 +1,23 @@ 
+/* PR middle-end/44974 */
+/* { dg-do compile } */
+/* { dg-options "-O -fno-optimize-sibling-calls" } */
+
+extern void foo (int status) __attribute__ ((__noreturn__));
+extern void bar (int status) __attribute__ ((__noreturn__));
+extern void _Exit (int status) __attribute__ ((__noreturn__));
+
+void
+foo (int status)
+{
+  _Exit (status);
+}
+
+void
+_Exit (int status)
+{
+  bar (status);
+}
+
+/* { dg-final { scan-assembler "call\[^\n\]*_Exit" { target i?86-*-* x86_64-*-* ia64-*-* sparc*-*-* } } } */
+/* { dg-final { scan-assembler "bl\[^\n\]*_Exit" { target powerpc*-*-* } } } */
+/* { dg-final { scan-assembler "brasl\[^\n\]*_Exit" { target { s390*-*-* && lp64 } } } } */