From patchwork Thu Jul 5 18:45:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 169236 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 D81002C01D3 for ; Fri, 6 Jul 2012 04:46:03 +1000 (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=1342118764; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC: Subject:References:In-Reply-To:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=FssjewdXST39kle5J32rD1r5mjM=; b=bDpwniTEPxDRgEwpgS1Q/S1mUDNtHgQ6Z/G7od2IcUEVVuGG1jF3OzHXHPyJo/ cDEHBUIT1lr8Qng5lqYbFHFiKlvlDwPMLl5UtoWRZO02ufZxTi5lwz8bI2LIa4jJ YzM8r1XAM0bimCbgiUfLNZl5Bc+mwkJU2fKhYcHuZEkWA= 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:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=jbl1Wh7mPUY5jqeF/4Q94w8NYLNM+U78u+esAHW6DCj3BWCgUSlBGqwj5Vl2yf qfux+71q5lA8B5aEM/dfONv6QFGsgcvyqB/aULR0Q2uZjZWaN9sUAoZ0npxa1/jk 14ima9eY1qnNTjspEHe6Anwy1U8mUye/sbAhOpbwsbgqM=; Received: (qmail 6176 invoked by alias); 5 Jul 2012 18:46:00 -0000 Received: (qmail 6167 invoked by uid 22791); 5 Jul 2012 18:45:59 -0000 X-SWARE-Spam-Status: No, hits=-4.2 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, TW_CF, TW_TM X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 05 Jul 2012 18:45:46 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1Smr3g-0001z0-UF from Tom_deVries@mentor.com ; Thu, 05 Jul 2012 11:45:44 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 5 Jul 2012 11:44:54 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.1.289.1; Thu, 5 Jul 2012 19:45:43 +0100 Message-ID: <4FF5E0D1.30402@mentor.com> Date: Thu, 5 Jul 2012 20:45:37 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: Michael Matz CC: Ulrich Weigand , , , Andrew Pinski , Steven Bosscher , Richard Guenther Subject: Re: Tree tail merging breaks __builtin_unreachable optimization References: <201207041702.q64H2GGj017517@d06av02.portsmouth.uk.ibm.com> <4FF58D3E.4060105@mentor.com> In-Reply-To: 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 05/07/12 15:30, Michael Matz wrote: > Hi, > > On Thu, 5 Jul 2012, Tom de Vries wrote: > >> The asserts allow the return result to be optimized, but not the cfg >> conditions. >> >> AFAIU, we can insert the asserts earlier. F.i., we can insert >> aD.1711_6 = ASSERT_EXPR 0> >> before the GIMPLE_COND in bb2. > > Nope. That would require some more checks, in particular that the BB > containing builtin_unreachable doesn't contain any other side-effects. > Given this: > > if (i < 0) > { do_something_interesting(); > __builtin_unreachable(); > } > > moving the assert before the if would remove the if condition, hence > the call to do_something_interesting. You need to retain side-effects if > there are any. > Michael, Thanks for pointing that out. I tried a first stab at your suggestion of implementing the optimization in pass_fold_builtins, it works for the test-case. Thanks, - Tom > > Ciao, > Michael. > Index: gcc/tree-ssa-ccp.c =================================================================== --- gcc/tree-ssa-ccp.c (revision 189007) +++ gcc/tree-ssa-ccp.c (working copy) @@ -2318,6 +2318,44 @@ optimize_stdarg_builtin (gimple call) } } +/* Return false if there are staments with side-effects before I. Otherwise, + return true and make the block of I unreachable. */ + +static bool +optimize_unreachable (gimple_stmt_iterator i) +{ + gimple stmt; + basic_block bb; + edge_iterator ei; + edge e; + + for (gsi_prev (&i); !gsi_end_p (i); gsi_prev (&i)) + { + stmt = gsi_stmt (i); + if (gimple_has_side_effects (stmt)) + return false; + } + + bb = gsi_bb (i); + + FOR_EACH_EDGE (e, ei, bb->preds) + { + basic_block src = e->src; + gimple stmt; + i = gsi_last_bb (src); + stmt = gsi_stmt (i); + gcc_assert (gimple_code (stmt) == GIMPLE_COND); + if (e->flags & EDGE_TRUE_VALUE) + gimple_cond_make_false (stmt); + else if (e->flags & EDGE_FALSE_VALUE) + gimple_cond_make_true (stmt); + else + gcc_unreachable (); + } + + return true; +} + /* A simple pass that attempts to fold all builtin functions. This pass is run after we've propagated as many constants as we can. */ @@ -2379,6 +2417,11 @@ execute_fold_all_builtins (void) gsi_next (&i); continue; + case BUILT_IN_UNREACHABLE: + if (optimize_unreachable (i)) + cfg_changed = true; + break; + case BUILT_IN_VA_START: case BUILT_IN_VA_END: case BUILT_IN_VA_COPY: @@ -2393,6 +2436,9 @@ execute_fold_all_builtins (void) continue; } + if (result == NULL_TREE) + break; + if (dump_file && (dump_flags & TDF_DETAILS)) { fprintf (dump_file, "Simplified\n ");