From patchwork Fri Aug 20 18:14:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 62299 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 75461B70DD for ; Sat, 21 Aug 2010 04:13:50 +1000 (EST) Received: (qmail 875 invoked by alias); 20 Aug 2010 18:13:49 -0000 Received: (qmail 867 invoked by uid 22791); 20 Aug 2010 18:13:48 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 20 Aug 2010 18:13:43 +0000 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o7KIDgol016964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 20 Aug 2010 14:13:42 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o7KIDfjq026062 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 20 Aug 2010 14:13:41 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id o7KIE9bC022957 for ; Fri, 20 Aug 2010 20:14:09 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o7KIE9dU022955 for gcc-patches@gcc.gnu.org; Fri, 20 Aug 2010 20:14:09 +0200 Date: Fri, 20 Aug 2010 20:14:09 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Don't optimize away calls to looping pure builtins (PR middle-end/44974) Message-ID: <20100820181409.GG702@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 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 --- 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 } } } } */