From patchwork Wed May 18 11:30:18 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 96152 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 6E4B1B6F59 for ; Wed, 18 May 2011 21:30:40 +1000 (EST) Received: (qmail 27241 invoked by alias); 18 May 2011 11:30:36 -0000 Received: (qmail 27232 invoked by uid 22791); 18 May 2011 11:30:35 -0000 X-SWARE-Spam-Status: No, hits=-3.3 required=5.0 tests=AWL, BAYES_00, TW_TM, T_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; Wed, 18 May 2011 11:30:20 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) by mx2.suse.de (Postfix) with ESMTP id A29DB8765C for ; Wed, 18 May 2011 13:30:18 +0200 (CEST) Date: Wed, 18 May 2011 13:30:18 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR49018 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 PR49018, ifcombine looks for side-effects but instead asks only gimple_has_volatile_ops. And gimple_has_side_effects disregards that volatile asms have side-effects. The function also doesn't handle all stmts gracefully so I fixed it as well as turning the asserts to checking asserts. Fixed as follows. Bootstrap / regtest pending on x86_64-unknown-linux-gnu. Richard. 2011-05-18 Richard Guenther PR tree-optimization/49018 * gimple.c (gimple_has_side_effects): Volatile asms have side-effects. * tree-ssa-ifcombine.c (bb_no_side_effects_p): Use gimple_has_side_effects. Index: gcc/gimple.c =================================================================== --- gcc/gimple.c (revision 173854) +++ gcc/gimple.c (working copy) @@ -2354,6 +2354,10 @@ gimple_has_side_effects (const_gimple s) if (gimple_has_volatile_ops (s)) return true; + if (gimple_code (s) == GIMPLE_ASM + && gimple_asm_volatile_p (s)) + return true; + if (is_gimple_call (s)) { unsigned nargs = gimple_call_num_args (s); @@ -2368,7 +2372,7 @@ gimple_has_side_effects (const_gimple s) if (gimple_call_lhs (s) && TREE_SIDE_EFFECTS (gimple_call_lhs (s))) { - gcc_assert (gimple_has_volatile_ops (s)); + gcc_checking_assert (gimple_has_volatile_ops (s)); return true; } @@ -2379,7 +2383,7 @@ gimple_has_side_effects (const_gimple s) for (i = 0; i < nargs; i++) if (TREE_SIDE_EFFECTS (gimple_call_arg (s, i))) { - gcc_assert (gimple_has_volatile_ops (s)); + gcc_checking_assert (gimple_has_volatile_ops (s)); return true; } @@ -2388,11 +2392,14 @@ gimple_has_side_effects (const_gimple s) else { for (i = 0; i < gimple_num_ops (s); i++) - if (TREE_SIDE_EFFECTS (gimple_op (s, i))) - { - gcc_assert (gimple_has_volatile_ops (s)); - return true; - } + { + tree op = gimple_op (s, i); + if (op && TREE_SIDE_EFFECTS (op)) + { + gcc_checking_assert (gimple_has_volatile_ops (s)); + return true; + } + } } return false; Index: gcc/tree-ssa-ifcombine.c =================================================================== --- gcc/tree-ssa-ifcombine.c (revision 173854) +++ gcc/tree-ssa-ifcombine.c (working copy) @@ -107,7 +107,7 @@ bb_no_side_effects_p (basic_block bb) { gimple stmt = gsi_stmt (gsi); - if (gimple_has_volatile_ops (stmt) + if (gimple_has_side_effects (stmt) || gimple_vuse (stmt)) return false; }