From patchwork Wed Dec 12 11:52:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Stubbs X-Patchwork-Id: 1011873 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-492218-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="LPRap1uv"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43FFYm0kRvz9s3Z for ; Wed, 12 Dec 2018 22:52:59 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:in-reply-to:references:mime-version :content-type; q=dns; s=default; b=YKPEipdC1A3zoQ2yyZgaTgSuLTNVr TMjEA5zQpd4/OT2grJcVVHx7ZRirZzCgEFUzK5nOaAWePb5h2bVhpBUw+/Ogaz8t smZ5Qne0mBqrVC7Zx4Bh1gmwRvLvl5inyoQJH/GcZ7MU/Vlt7iS1VxEeNDf2eT48 XVRJ3cBLhBkW3I= 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:from :to:subject:date:message-id:in-reply-to:references:mime-version :content-type; s=default; bh=KvCP9F6TtIQvCFWrJFrfgdPKPA8=; b=LPR ap1uvCcj0/9ogWXBsyK0ZxOh2rlDLQSM9p8T9DqFcg08OcezrxlV65GbzNXu158Q yic/HK8ykY9/CGewW+lgcNhDrlODQvYhg1DtSnPHZLdV3abqfYBQDvBEj/BIvcuE EH3bEZcdSmwtTJ1kyPY7PYLYDJ6IuJC3uwALx0y0= Received: (qmail 85493 invoked by alias); 12 Dec 2018 11:52:42 -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 85369 invoked by uid 89); 12 Dec 2018 11:52:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=libgfortran, Stubbs, ams@codesourcery.com, stubbs X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 12 Dec 2018 11:52:39 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=svr-ies-mbx-01.mgc.mentorg.com) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1gX34A-0002fq-7j from Andrew_Stubbs@mentor.com for gcc-patches@gcc.gnu.org; Wed, 12 Dec 2018 03:52:38 -0800 Received: from build6-trusty-cs.sje.mentorg.com (137.202.0.90) by svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Wed, 12 Dec 2018 11:52:34 +0000 From: Andrew Stubbs To: Subject: [PATCH 01/10] Fix LRA bug Date: Wed, 12 Dec 2018 11:52:20 +0000 Message-ID: <37b228579c172c39ce89c75a673326b9185f92bc.1544611347.git.ams@codesourcery.com> In-Reply-To: References: MIME-Version: 1.0 [This is new patch not included in the previously posted patch sets.] This patch fixes an ICE building libgfortran/random.c. The problem was an adddi3 instruction that had an eliminable frame pointer. GCN adddi3 includes a match_scratch, which LRA substitutes with a REG, and checks if it can be converted back to a scratch afterwards. In the meantime, the add was converted to a move, meaning that the instruction pattern completely changed, thus causing a segfault when the instruction is revisited in restore_scratches. 2018-12-12 Andrew Stubbs gcc/ * gcc/lra-int.h (lra_register_new_scratch_op): Add third parameter. * gcc/lra-remat.c (update_scratch_ops): Pass icode to lra_register_new_scratch_op. * gcc/lra.c (struct sloc): Add icode field. (lra_register_new_scratch_op): Add icode parameter. Use icode to skip insns that have changed beyond recognition. --- gcc/lra-int.h | 2 +- gcc/lra-remat.c | 2 +- gcc/lra.c | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/gcc/lra-int.h b/gcc/lra-int.h index 5267b53..d5ff652 100644 --- a/gcc/lra-int.h +++ b/gcc/lra-int.h @@ -335,7 +335,7 @@ extern void lra_create_copy (int, int, int); extern lra_copy_t lra_get_copy (int); extern bool lra_former_scratch_p (int); extern bool lra_former_scratch_operand_p (rtx_insn *, int); -extern void lra_register_new_scratch_op (rtx_insn *, int); +extern void lra_register_new_scratch_op (rtx_insn *, int, int); extern int lra_new_regno_start; extern int lra_constraint_new_regno_start; diff --git a/gcc/lra-remat.c b/gcc/lra-remat.c index faf74ca..627a248 100644 --- a/gcc/lra-remat.c +++ b/gcc/lra-remat.c @@ -1042,7 +1042,7 @@ update_scratch_ops (rtx_insn *remat_insn) fprintf (lra_dump_file, " Assigning the same %d to r%d\n", REGNO (*loc), hard_regno); } - lra_register_new_scratch_op (remat_insn, i); + lra_register_new_scratch_op (remat_insn, i, id->icode); } } diff --git a/gcc/lra.c b/gcc/lra.c index 5d58d90..14974ed 100644 --- a/gcc/lra.c +++ b/gcc/lra.c @@ -2026,6 +2026,7 @@ struct sloc { rtx_insn *insn; /* Insn where the scratch was. */ int nop; /* Number of the operand which was a scratch. */ + int icode; /* Original icode from which scratch was removed. */ }; typedef struct sloc *sloc_t; @@ -2057,7 +2058,7 @@ lra_former_scratch_operand_p (rtx_insn *insn, int nop) /* Register operand NOP in INSN as a former scratch. It will be changed to scratch back, if it is necessary, at the LRA end. */ void -lra_register_new_scratch_op (rtx_insn *insn, int nop) +lra_register_new_scratch_op (rtx_insn *insn, int nop, int icode) { lra_insn_recog_data_t id = lra_get_insn_recog_data (insn); rtx op = *id->operand_loc[nop]; @@ -2065,6 +2066,7 @@ lra_register_new_scratch_op (rtx_insn *insn, int nop) lra_assert (REG_P (op)); loc->insn = insn; loc->nop = nop; + loc->icode = icode; scratches.safe_push (loc); bitmap_set_bit (&scratch_bitmap, REGNO (op)); bitmap_set_bit (&scratch_operand_bitmap, @@ -2102,7 +2104,7 @@ remove_scratches (void) *id->operand_loc[i] = reg = lra_create_new_reg (static_id->operand[i].mode, *id->operand_loc[i], ALL_REGS, NULL); - lra_register_new_scratch_op (insn, i); + lra_register_new_scratch_op (insn, i, id->icode); if (lra_dump_file != NULL) fprintf (lra_dump_file, "Removing SCRATCH in insn #%u (nop %d)\n", @@ -2136,6 +2138,12 @@ restore_scratches (void) last = loc->insn; id = lra_get_insn_recog_data (last); } + if (loc->icode != id->icode) + { + /* The icode doesn't match, which means the insn has been modified + (e.g. register elimination). The scratch cannot be restored. */ + continue; + } if (REG_P (*id->operand_loc[loc->nop]) && ((regno = REGNO (*id->operand_loc[loc->nop])) >= FIRST_PSEUDO_REGISTER)