From patchwork Tue Jan 3 10:47:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 133994 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 A55C2B6FA5 for ; Tue, 3 Jan 2012 21:48:11 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1326192491; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=pMxJNvzLGUeJBHD1OWx9 Tnbk/m0=; b=Khm1MWHwgDBC2kPg3OosZaGkP1DSCnbMmRFJ1o4S6xS4ltPwKqVS seOjwjlX0YnaFr8z0olX7ZPz2dcn0M/YfNnSk0S+fydS4aTyG7tULgOf+bECL56R 1qjLSLAE8e+xOKQr5KjrP8ZNkZHFgS5WaRUlbETNWZHbucVAsoMMXiY= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Date:From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=mWekK3k8uqymFRatPffQilBLD3yL+xkVWEeWiyljyscBtdpmho7hq0oMEy3MnG OJ5BPUVGemYEbNLoQbzX2HgMgTIQPYN7noIWueZ/9+r0fXw60Ym8vEzM+XgFklZ7 IDj3MWspIuxgXgT6j7a1QadvtqyZX3hPZSXbjJr/rzLoU=; Received: (qmail 11027 invoked by alias); 3 Jan 2012 10:48:08 -0000 Received: (qmail 11019 invoked by uid 22791); 3 Jan 2012 10:48:07 -0000 X-SWARE-Spam-Status: No, hits=-4.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, TW_TM X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 03 Jan 2012 10:47:55 +0000 Received: from relay1.suse.de (nat.nue.novell.com [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 157CB8F29D for ; Tue, 3 Jan 2012 11:47:54 +0100 (CET) Date: Tue, 3 Jan 2012 11:47:54 +0100 (CET) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR51692 Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 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 This fixes PR51692, we shouldn't remove the lhs of allocation calls before the special malloc/free pair removal code kicks in. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2012-01-03 Richard Guenther PR tree-optimization/51692 * tree-ssa-dce.c (eliminate_unnecessary_stmts): Do not remove the LHS of allocation stmts. * gcc.dg/torture/pr51692.c: New testcase. Index: gcc/tree-ssa-dce.c =================================================================== --- gcc/tree-ssa-dce.c (revision 182829) +++ gcc/tree-ssa-dce.c (working copy) @@ -1329,31 +1329,38 @@ eliminate_unnecessary_stmts (void) } else if (is_gimple_call (stmt)) { - call = gimple_call_fndecl (stmt); - if (call) - { - tree name; + tree name = gimple_call_lhs (stmt); - /* When LHS of var = call (); is dead, simplify it into - call (); saving one operand. */ - name = gimple_call_lhs (stmt); - if (name && TREE_CODE (name) == SSA_NAME - && !TEST_BIT (processed, SSA_NAME_VERSION (name))) - { - something_changed = true; - if (dump_file && (dump_flags & TDF_DETAILS)) - { - fprintf (dump_file, "Deleting LHS of call: "); - print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM); - fprintf (dump_file, "\n"); - } + notice_special_calls (stmt); - gimple_call_set_lhs (stmt, NULL_TREE); - maybe_clean_or_replace_eh_stmt (stmt, stmt); - update_stmt (stmt); - release_ssa_name (name); + /* When LHS of var = call (); is dead, simplify it into + call (); saving one operand. */ + if (name + && TREE_CODE (name) == SSA_NAME + && !TEST_BIT (processed, SSA_NAME_VERSION (name)) + /* Avoid doing so for allocation calls which we + did not mark as necessary, it will confuse the + special logic we apply to malloc/free pair removal. */ + && (!(call = gimple_call_fndecl (stmt)) + || DECL_BUILT_IN_CLASS (call) != BUILT_IN_NORMAL + || (DECL_FUNCTION_CODE (call) != BUILT_IN_MALLOC + && DECL_FUNCTION_CODE (call) != BUILT_IN_CALLOC + && DECL_FUNCTION_CODE (call) != BUILT_IN_ALLOCA + && (DECL_FUNCTION_CODE (call) + != BUILT_IN_ALLOCA_WITH_ALIGN)))) + { + something_changed = true; + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Deleting LHS of call: "); + print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM); + fprintf (dump_file, "\n"); } - notice_special_calls (stmt); + + gimple_call_set_lhs (stmt, NULL_TREE); + maybe_clean_or_replace_eh_stmt (stmt, stmt); + update_stmt (stmt); + release_ssa_name (name); } } } Index: gcc/testsuite/gcc.dg/torture/pr51692.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr51692.c (revision 0) +++ gcc/testsuite/gcc.dg/torture/pr51692.c (revision 0) @@ -0,0 +1,13 @@ +/* { dg-do compile } */ + +int +main () +{ + volatile double d = 0.0; + double *p = __builtin_calloc (1, sizeof (double)); + d += 1.0; + *p += 2.0; + __builtin_free (p); + return 0; +} +