From patchwork Thu Nov 15 20:09:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 199396 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 D0DA32C04C9 for ; Fri, 16 Nov 2012 07:09:29 +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=1353614970; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=7k3m2TF6zaifIs2Wt8DN nMJ/kno=; b=dVcVcSRBJF/anoCtR8x5jtMDQ3TTaaxyZ0L3yYraYp3k65SJd7h6 9mNBXutWfzKdut7jVKwoA/T6jUKjA4yle/czYUsn3QO75aeYq73y0NXmzFGOVZbM Bdi5reNZ68aZqbQVhx2/rQtn0JXZftGxx8ydgGtQv5SYSUVT+RJcRGE= 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:Received:Date:From:To:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=k9vtoVRJLtejcIKm4cAfwX9u0eXLwHvaw1UeW1v3eUo6muJsN81dD15ooIoNQa UDbmE8mkiovdk1ELtA5k+SHHWx1balD0ZoS1GxT0/hh+4OpP0cS/TxCMoHWTC1/T tT+tvacDNu/PtgtOWb50NKn5LccUVtQ67kRMCMnPFy4Ow=; Received: (qmail 31785 invoked by alias); 15 Nov 2012 20:09:20 -0000 Received: (qmail 31762 invoked by uid 22791); 15 Nov 2012 20:09:18 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_TM 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; Thu, 15 Nov 2012 20:09:13 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qAFK9Cvb007067 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 15 Nov 2012 15:09:12 -0500 Received: from zalov.redhat.com (vpn1-6-139.ams2.redhat.com [10.36.6.139]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qAFK99E1017493 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 15 Nov 2012 15:09:11 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id qAFK98Lu022247 for ; Thu, 15 Nov 2012 21:09:09 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id qAFK97UK022246 for gcc-patches@gcc.gnu.org; Thu, 15 Nov 2012 21:09:07 +0100 Date: Thu, 15 Nov 2012 21:09:07 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix substitute_and_fold ICE (PR tree-optimization/55331) Message-ID: <20121115200907.GC1886@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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! On the following testcase substitute_and_fold ICEs because memmove of length 1 on an empty class is optimized away, and this function wasn't prepared to handle that. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.7? 2012-11-15 Jakub Jelinek PR tree-optimization/55331 * tree-ssa-propagate.c (substitute_and_fold): Handle fold_stmt turning a stmt into nothing. * g++.dg/opt/pr55331.C: New test. Jakub --- gcc/tree-ssa-propagate.c.jj 2012-11-02 09:01:55.000000000 +0100 +++ gcc/tree-ssa-propagate.c 2012-11-15 12:27:37.218543417 +0100 @@ -1094,7 +1094,7 @@ substitute_and_fold (ssa_prop_get_value_ gimple stmt = gsi_stmt (i); gimple old_stmt; enum gimple_code code = gimple_code (stmt); - gimple_stmt_iterator oldi; + gimple_stmt_iterator oldi, nexti; oldi = i; if (do_dce) @@ -1147,6 +1147,8 @@ substitute_and_fold (ssa_prop_get_value_ } old_stmt = stmt; + nexti = oldi; + gsi_next (&nexti); /* Some statements may be simplified using propagator specific information. Do this before propagating @@ -1171,36 +1173,63 @@ substitute_and_fold (ssa_prop_get_value_ /* Now cleanup. */ if (did_replace) { - stmt = gsi_stmt (oldi); - - /* If we cleaned up EH information from the statement, - remove EH edges. */ - if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt)) - gimple_purge_dead_eh_edges (bb); - - if (is_gimple_assign (stmt) - && (get_gimple_rhs_class (gimple_assign_rhs_code (stmt)) - == GIMPLE_SINGLE_RHS)) - { - tree rhs = gimple_assign_rhs1 (stmt); - - if (TREE_CODE (rhs) == ADDR_EXPR) - recompute_tree_invariant_for_addr_expr (rhs); - } + /* old_stmt might have been also replaced by nothing, + in that case set stmt to NULL. */ + if (gsi_end_p (oldi)) + { + gcc_checking_assert (gsi_end_p (nexti)); + stmt = NULL; + } + else + { + stmt = gsi_stmt (oldi); + if (!gsi_end_p (nexti) && gsi_stmt (nexti) == stmt) + stmt = NULL; + } - /* Determine what needs to be done to update the SSA form. */ - update_stmt (stmt); - if (!is_gimple_debug (stmt)) - something_changed = true; + if (stmt == NULL) + { + if (maybe_clean_eh_stmt (old_stmt)) + gimple_purge_dead_eh_edges (bb); + something_changed = true; + } + else + { + /* If we cleaned up EH information from the statement, + remove EH edges. */ + if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt)) + gimple_purge_dead_eh_edges (bb); + + if (is_gimple_assign (stmt) + && (get_gimple_rhs_class (gimple_assign_rhs_code (stmt)) + == GIMPLE_SINGLE_RHS)) + { + tree rhs = gimple_assign_rhs1 (stmt); + + if (TREE_CODE (rhs) == ADDR_EXPR) + recompute_tree_invariant_for_addr_expr (rhs); + } + + /* Determine what needs to be done to update the SSA + form. */ + update_stmt (stmt); + if (!is_gimple_debug (stmt)) + something_changed = true; + } } if (dump_file && (dump_flags & TDF_DETAILS)) { if (did_replace) { - fprintf (dump_file, "Folded into: "); - print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM); - fprintf (dump_file, "\n"); + if (stmt == NULL) + fprintf (dump_file, "Folded into nothing\n"); + else + { + fprintf (dump_file, "Folded into: "); + print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM); + fprintf (dump_file, "\n"); + } } else fprintf (dump_file, "Not folded\n"); --- gcc/testsuite/g++.dg/opt/pr55331.C.jj 2012-11-15 12:53:26.893631190 +0100 +++ gcc/testsuite/g++.dg/opt/pr55331.C 2012-11-15 12:53:52.482504446 +0100 @@ -0,0 +1,14 @@ +// PR tree-optimization/55331 +// { dg-do compile } +// { dg-options "-O2 -fno-tree-fre" } + +struct A {}; + +void +foo (A *p, bool x) +{ + A a; + char *e = (char *) (&a + 1); + if (x) + __builtin_memmove (p, &a, e - (char *) &a); +}