From patchwork Thu Sep 8 12:55:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 113900 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 45C12B6F91 for ; Thu, 8 Sep 2011 22:56:33 +1000 (EST) Received: (qmail 20666 invoked by alias); 8 Sep 2011 12:56:31 -0000 Received: (qmail 20658 invoked by uid 22791); 8 Sep 2011 12:56:30 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD 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; Thu, 08 Sep 2011 12:56:00 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [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 0FFCC8B2F9 for ; Thu, 8 Sep 2011 14:55:59 +0200 (CEST) Date: Thu, 8 Sep 2011 14:55:58 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Fix PR19831, remove malloc/free pairs In-Reply-To: Message-ID: References: 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 On Thu, 8 Sep 2011, Richard Guenther wrote: > > This implements removal of malloc/free pairs when allowed for a > subset of all possible cases. The idea is to identify possible > candidates (we free the return value of an allocation call) and > for them do not make the allocation function necessary because > of the free. If nothing else made the allocation necessary, > go ahead and make the free call not necessary as well after > propagation. > > Integrating this with control-dependence is much harder but > would then handle also if (p) free (p). The testcases contain > some tricky cases that break when you do it too simple-minded. > > Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. And we hit gcc.dg/errno-1.c, adjusted as follows which keeps the malloc live. The testcase wants to verify that we don't CSE errno across malloc. Committed. Richard. Index: gcc/testsuite/gcc.dg/errno-1.c =================================================================== --- gcc/testsuite/gcc.dg/errno-1.c (revision 178684) +++ gcc/testsuite/gcc.dg/errno-1.c (working copy) @@ -6,7 +6,7 @@ int main() { - void *p; + void * volatile p; errno = 0; p = malloc (-1); if (errno != 0)