From patchwork Thu Jan 11 14:35:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 187402 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1489748dyi; Thu, 11 Jan 2024 06:36:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXTB9eCup/SDRfUdnGV/3p2t37q9XHZRaqQE1kBF8fRd+baAwkaF+pmu0sP4apvOoPn7Hk X-Received: by 2002:a81:9ac4:0:b0:5d8:67b8:6d13 with SMTP id r187-20020a819ac4000000b005d867b86d13mr591996ywg.76.1704983777956; Thu, 11 Jan 2024 06:36:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704983777; cv=pass; d=google.com; s=arc-20160816; b=CtP51ypSua2vD5erCE9VBdRqNMmgLgDQrSE0z8DlcpYLl078yrdWVgKJeecHedCjZv Vk1PRQhLcAmPP4vcOTKqDM3N4F8ZO4Kg81cze0GZIAJhMEm+CUlL57qTLSIGVKYplLfN E7YZz4veJd73ITPrYkUFdiX1eaaY5ODYI1OZnJ8spKD3fnYJfMD0lVSN0w1Huw3rh/6l zk9gDQzzkkRk4egUnwCBb1miDtA5x/eLnDr2UbxsaaX1Lr74I6wFxMB/FrVO/+6jlqg5 M2w77nngbxJdc8aTYAYWuzdwAIkEzKNDkR6AbrGLWulX4XPJuVMSnaxQZQVOiZpHkxSC 41tw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language:subject:from :to:user-agent:mime-version:date:message-id:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=wsNRmY0iYg8jlIVZCRCKUAId4umsW9pOhCOeu2s4IZo=; fh=XNn3asQvIblazGK92GBt13dVv+YmGV3pBS0JC29ZQco=; b=Oo/ICZmgRoDPNukfzmU2AOfAO1BOOpnP10UxxTx87JLlxsKRBtYjDg2bSpFVIsbte8 Kl1qb/0ZEbm17X5Sb7e7MTbUZ4ImuIG9rX/ehEqF1lie9CPXw16+RNbBbhOojR5cirjk R09hzE2gg7HibNdNg9nJtG+1so0zMyGez8Xth+2hPc70QplcyZQhvRRgWivztwc1s+Ph D0ATX27H0lJzhQjkL69IqTDA+iof76d9QNfg3TFcsLJzainbrJAXDc6JcEZ90WzZBB2h 4StzaJhA/hQscINrxKwn6DjIIHJFoGF983wkJCRqX6jtOpTuPOC+av46nLQG5zWKR+rL iUaw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QpTVfmsh; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w4-20020a9f2c84000000b007ce06518067si127235uaj.193.2024.01.11.06.36.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:36:17 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QpTVfmsh; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 03E58384F00A for ; Thu, 11 Jan 2024 14:36:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 694A33858004 for ; Thu, 11 Jan 2024 14:35:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 694A33858004 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 694A33858004 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704983718; cv=none; b=iAZhp8ZfZ98ySUHSws656RsaNNLvqiB93gKSv187m1puUXtHnFrFHlDCGzFE3UYACJect7OZ4ufXb9fnSCQVgTCj+HDTDh7WbDeUmlw/ScvLS7fKafuSwQqvknoty+9lna2mas8V/CLt0LwxWchKQ3d9iR9SIeRfzAyurwXaWVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704983718; c=relaxed/simple; bh=YYCXKE7FVrm879WQpBTmhSKbxt45szisoKcBmQvYUJU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=bBB5OmSfSyfvLPbOBaG9pDOm3aoyxTOOa99cHjLYP2axZYMzW684afWUDMPJhYmTmLMLg8wd4iZKOvRallHRWvq2fBNRIt4hdn37xfXLEUv/YFgLbCYoDEp+A5G4DnZmavKPc7TcuPM7eHxcZsJYOjiXDv6pLfW9dgRORHzRKfg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704983716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=wsNRmY0iYg8jlIVZCRCKUAId4umsW9pOhCOeu2s4IZo=; b=QpTVfmshDCIcLTgs9pVU5p6Zq+IM4aDlAN4xIXwd67ZllWmTznCJ9snuUU+QkwqW5Dh/8x UYvlhpHQzeJdzmkM4BuviQiZ0StidkDiTSscvdU/wBkxNDam0gWv13mG7kfF2ZKdoMoqTa BVu11jlSsSu0b22p/JbdYGAoxl4csOI= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-224-F4qZBEiWM6u12KsQJ1duqg-1; Thu, 11 Jan 2024 09:35:14 -0500 X-MC-Unique: F4qZBEiWM6u12KsQJ1duqg-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-4298c15d3a9so62884941cf.0 for ; Thu, 11 Jan 2024 06:35:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983713; x=1705588513; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kCSL4/VLkaT8vu9ElW1CeWhdn3C+lvdxVdr5K8r2l8s=; b=iBqIAfrbVmneUCN1rGXObrovR1pfLTZzsp99JcSfldMwA/KwYdzVcoS6T2rcmP5BRJ BcdJ5fhTDaujz+UcE5pPytgipEJMI/1vYcie4+Qnngv3aL+DB2Xy3gcQFUAJcCDpCwxN uGmmBXfNKrw71HFPHiDBy1l4o1qeFiYeHFbjdNbspnpv/ywWNa+4CQS2kV5sChaC3WXh T+uLw74hlJwqE+MNjybgKD4BIMiOThlv44C+2T7mMUdentaQsJneTRbGxKcrO+05iWQn Li/Mt6KDPO/0YPP6IjhwHgO1qrMnJcQ1InoyXGSxOvajbJKPewyMWaCFiGnayZvKpUfN x3Hg== X-Gm-Message-State: AOJu0YxRs0hdPxswVsjNiy4pRAabJZYviqy4+wh41ReKNtRVrpc6g+eo lE2+XXMESvBUBuqTzLaYwpIoP794hmrgnneGGkn1ptGV1/SEqns91spH6Pcjvhxi+IhWtrOlaLo pfpo0J9Pa+gI1g6LWCYm6nyB91nU9G7i9UZp1rm7qRhbgNTRMsS+ZyIl9ftDNDkE0pNnbZL5S74 a1Bb8rbGD4NA== X-Received: by 2002:a05:622a:104b:b0:429:96e2:876a with SMTP id f11-20020a05622a104b00b0042996e2876amr609900qte.17.1704983713652; Thu, 11 Jan 2024 06:35:13 -0800 (PST) X-Received: by 2002:a05:622a:104b:b0:429:96e2:876a with SMTP id f11-20020a05622a104b00b0042996e2876amr609887qte.17.1704983713162; Thu, 11 Jan 2024 06:35:13 -0800 (PST) Received: from [192.168.1.88] (23-233-12-249.cpe.pppoe.ca. [23.233.12.249]) by smtp.gmail.com with ESMTPSA id bp43-20020a05622a1bab00b00427e0e9c22dsm465420qtb.54.2024.01.11.06.35.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Jan 2024 06:35:12 -0800 (PST) Message-ID: <937f4ee1-3ed3-6d66-7e19-2bd69a30d6cf@redhat.com> Date: Thu, 11 Jan 2024 09:35:10 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 To: "gcc-patches@gcc.gnu.org" From: Vladimir Makarov Subject: [pushed][PR112918][LRA]: Fixing IRA ICE on m68k X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787805070001148260 X-GMAIL-MSGID: 1787805070001148260 The following patch fixes https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112918 The patch was successfully bootstrapped and tested on x86_64, aarch64, ppc64le commit 902a5931a1fbb04c65b48ca8b0f3827f6ff3b43e Author: Vladimir N. Makarov Date: Thu Jan 11 08:46:26 2024 -0500 [PR112918][LRA]: Fixing IRA ICE on m68k Some GCC tests on m68K port of LRA is failed on `maximum number of generated reload insns per insn achieved`. The problem is in that for subreg reload LRA can not narrow reg class more from ALL_REGS to GENERAL_REGS and then to data regs or address regs. The patch permits narrowing reg class from reload insns if this results in successful matching of reg operand. This is the second version of the patch to fix the PR. This version adds matching with and without narrowing reg class and preferring match without narrowing classes. gcc/ChangeLog: PR rtl-optimization/112918 * lra-constraints.cc (SMALL_REGISTER_CLASS_P): Move before in_class_p. (in_class_p): Restrict condition for narrowing class in case of allow_all_reload_class_changes_p. (process_alt_operands): Try to match operand without and with narrowing reg class. Discourage narrowing the class. Finish insn matching only if there is no class narrowing. (curr_insn_transform): Pass true to in_class_p for reg operand win. diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc index da7e1748d75..6132cd9844a 100644 --- a/gcc/lra-constraints.cc +++ b/gcc/lra-constraints.cc @@ -261,6 +261,13 @@ enough_allocatable_hard_regs_p (enum reg_class reg_class, return false; } +/* True if C is a non-empty register class that has too few registers + to be safely used as a reload target class. */ +#define SMALL_REGISTER_CLASS_P(C) \ + (ira_class_hard_regs_num [(C)] == 1 \ + || (ira_class_hard_regs_num [(C)] >= 1 \ + && targetm.class_likely_spilled_p (C))) + /* Return true if REG satisfies (or will satisfy) reg class constraint CL. Use elimination first if REG is a hard register. If REG is a reload pseudo created by this constraints pass, assume that it will @@ -318,7 +325,11 @@ in_class_p (rtx reg, enum reg_class cl, enum reg_class *new_class, common_class = ira_reg_class_subset[rclass][cl]; if (new_class != NULL) *new_class = common_class; - return enough_allocatable_hard_regs_p (common_class, reg_mode); + return (enough_allocatable_hard_regs_p (common_class, reg_mode) + /* Do not permit reload insn operand matching (new_class == NULL + case) if the new class is too small. */ + && (new_class != NULL || common_class == rclass + || !SMALL_REGISTER_CLASS_P (common_class))); } } @@ -923,13 +934,6 @@ operands_match_p (rtx x, rtx y, int y_hard_regno) && GET_MODE_SIZE (MODE).is_constant () \ && !targetm.cannot_force_const_mem (MODE, X)) -/* True if C is a non-empty register class that has too few registers - to be safely used as a reload target class. */ -#define SMALL_REGISTER_CLASS_P(C) \ - (ira_class_hard_regs_num [(C)] == 1 \ - || (ira_class_hard_regs_num [(C)] >= 1 \ - && targetm.class_likely_spilled_p (C))) - /* If REG is a reload pseudo, try to make its class satisfying CL. */ static void narrow_reload_pseudo_class (rtx reg, enum reg_class cl) @@ -2137,6 +2141,7 @@ process_alt_operands (int only_alternative) /* True if output stack pointer reload should be generated for the current alternative. */ bool curr_alt_out_sp_reload_p; + bool curr_alt_class_change_p; rtx op; /* The register when the operand is a subreg of register, otherwise the operand itself. */ @@ -2223,6 +2228,7 @@ process_alt_operands (int only_alternative) early_clobbered_regs_num = 0; curr_alt_out_sp_reload_p = false; curr_reuse_alt_p = true; + curr_alt_class_change_p = false; for (nop = 0; nop < n_operands; nop++) { @@ -2247,6 +2253,7 @@ process_alt_operands (int only_alternative) bool scratch_p; machine_mode mode; enum constraint_num cn; + bool class_change_p = false; opalt_num = nalt * n_operands + nop; if (curr_static_id->operand_alternative[opalt_num].anything_ok) @@ -2630,9 +2637,16 @@ process_alt_operands (int only_alternative) (this_alternative_exclude_start_hard_regs, hard_regno[nop])))) win = true; - else if (hard_regno[nop] < 0 - && in_class_p (op, this_alternative, NULL)) - win = true; + else if (hard_regno[nop] < 0) + { + if (in_class_p (op, this_alternative, NULL)) + win = true; + else if (in_class_p (op, this_alternative, NULL, true)) + { + class_change_p = true; + win = true; + } + } } break; } @@ -2647,6 +2661,15 @@ process_alt_operands (int only_alternative) if (win) { this_alternative_win = true; + if (class_change_p) + { + curr_alt_class_change_p = true; + if (lra_dump_file != NULL) + fprintf (lra_dump_file, + " %d Narrowing class: reject+=3\n", + nop); + reject += 3; + } if (operand_reg[nop] != NULL_RTX) { if (hard_regno[nop] >= 0) @@ -2675,7 +2698,7 @@ process_alt_operands (int only_alternative) reject++; } if (in_class_p (operand_reg[nop], - this_costly_alternative, NULL)) + this_costly_alternative, NULL, true)) { if (lra_dump_file != NULL) fprintf @@ -3351,7 +3374,7 @@ process_alt_operands (int only_alternative) best_reload_sum = reload_sum; goal_alt_number = nalt; } - if (losers == 0) + if (losers == 0 && !curr_alt_class_change_p) /* Everything is satisfied. Do not process alternatives anymore. */ break; @@ -4388,7 +4411,7 @@ curr_insn_transform (bool check_only_p) if (REG_P (reg) && (regno = REGNO (reg)) >= FIRST_PSEUDO_REGISTER) { - bool ok_p = in_class_p (reg, goal_alt[i], &new_class); + bool ok_p = in_class_p (reg, goal_alt[i], &new_class, true); if (new_class != NO_REGS && get_reg_class (regno) != new_class) {