From patchwork Tue Nov 26 20:25:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 294398 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2EF6A2C00A3 for ; Wed, 27 Nov 2013 07:27:24 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=D7vgx7Jug6mIFlEw10XPZKkEo/mE3 egd3R8Vzp2RI98NiCzA9xwqCqg8JLgRAlhapY2Mz69F68HNC9ZSgCQMJXSvRaSmf F7afE4dicofFnobuAOI1WApgRl5u5+LelBTn7wq8jWJ/pMbv10OjWKcvwX2N7RxW jj7q0YPguX8rAI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=QFA/jC1vx6Kj1oR7aCJ39NzEWqI=; b=SQf zva59XsmNS/goXd7PzKVayDR5EnvJ2ZACTgXerI95EEFKccHmeMXjj6uInZg3XPf 12cF4bI8e/iWZsHlEz7j88voJWOx/mbWRppA1d5QVtGnlsSwdHRlouu0oUZA6TI+ 5GJ6+b7t1x1BW0s0UgZMmmXdC19kqUb4uiEtJE6o= Received: (qmail 23158 invoked by alias); 26 Nov 2013 20:27:14 -0000 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 Received: (qmail 23148 invoked by uid 89); 26 Nov 2013 20:27:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_40, RDNS_NONE, SPF_HELO_PASS, SPF_PASS autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from Unknown (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 26 Nov 2013 20:25:50 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rAQKPhJZ012439 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Nov 2013 15:25:43 -0500 Received: from tucnak.zalov.cz (vpn1-4-96.ams2.redhat.com [10.36.4.96]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rAQKPf53031414 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 26 Nov 2013 15:25:43 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.7/8.14.7) with ESMTP id rAQKPfKl018537; Tue, 26 Nov 2013 21:25:41 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.7/8.14.7/Submit) id rAQKPeL2018536; Tue, 26 Nov 2013 21:25:40 +0100 Date: Tue, 26 Nov 2013 21:25:40 +0100 From: Jakub Jelinek To: Vladimir Makarov , Martin Jambor Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix split_live_ranges_for_shrink_wrap (PR rtl-optimization/59166) Message-ID: <20131126202540.GN892@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 Hi! The problem on this testcase is that we have (debug_insn 30 29 31 7 (var_location:HI D#1 (subreg:HI (reg/v:SI 93 [ p ]) 0)) pr59166.c:20 -1 (nil)) and split_live_ranges_for_shrink_wrap decides to replace SImode pseudo 93 with some other SImode pseudo. But it uses DF_REF_LOC, which is address of the HImode subreg around the pseudo, validate_change succeeds on it, because there is no validation inside of debug_insns and then we crash during var-tracking because of a mode mismatch. The following patch uses DF_REF_REAL_LOC instead, so that it looks through the subreg and adjusts what it should. Code inspection showed the same issue in find_moveable_pseudos, don't have a testcase for that though. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-11-26 Jakub Jelinek PR rtl-optimization/59166 * ira.c (find_moveable_pseudos): Use DF_REF_REAL_LOC instead of DF_REF_LOC in validate_change call. (split_live_ranges_for_shrink_wrap): Likewise. * gcc.dg/torture/pr59166.c: New test. Jakub --- gcc/ira.c.jj 2013-11-25 10:20:12.000000000 +0100 +++ gcc/ira.c 2013-11-26 12:45:27.443495633 +0100 @@ -4812,7 +4812,7 @@ find_moveable_pseudos (void) { rtx def_reg = DF_REF_REG (def); rtx newreg = ira_create_new_reg (def_reg); - if (validate_change (def_insn, DF_REF_LOC (def), newreg, 0)) + if (validate_change (def_insn, DF_REF_REAL_LOC (def), newreg, 0)) { unsigned nregno = REGNO (newreg); emit_insn_before (gen_move_insn (def_reg, newreg), use_insn); @@ -5034,7 +5034,7 @@ split_live_ranges_for_shrink_wrap (void) rtx newreg = NULL_RTX; df_ref use, next; - for (use = DF_REG_USE_CHAIN (REGNO(dest)); use; use = next) + for (use = DF_REG_USE_CHAIN (REGNO (dest)); use; use = next) { rtx uin = DF_REF_INSN (use); next = DF_REF_NEXT_REG (use); @@ -5045,7 +5045,7 @@ split_live_ranges_for_shrink_wrap (void) { if (!newreg) newreg = ira_create_new_reg (dest); - validate_change (uin, DF_REF_LOC (use), newreg, true); + validate_change (uin, DF_REF_REAL_LOC (use), newreg, true); } } --- gcc/testsuite/gcc.dg/torture/pr59166.c.jj 2013-11-26 12:49:33.551233602 +0100 +++ gcc/testsuite/gcc.dg/torture/pr59166.c 2013-11-26 12:50:15.589019973 +0100 @@ -0,0 +1,37 @@ +/* PR rtl-optimization/59166 */ +/* { dg-additional-options "-fcompare-debug" } */ + +int a, b, c, f, g; + +void +foo () +{ + for (; b; b++) + for (; f; f = g) + for (; a;) + ; +} + +static int +bar (int p) +{ + short d; + if (c) + { + for (; f; f = g); + foo (); + d = p; + char e = d; + if (p) + return 1; + } + return p; +} + +int +main () +{ + bar (0); + bar (g); + return 0; +}