From patchwork Thu Jul 13 14:52:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 119948 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1881020vqm; Thu, 13 Jul 2023 07:57:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlFube2JKKwEkCpLH/83TFxMflsuKAzbRnsO2SYgS72HBZ2he9fNVzyOXy+dDzBxGRzGb9x7 X-Received: by 2002:a2e:9792:0:b0:2b6:eb5c:e23c with SMTP id y18-20020a2e9792000000b002b6eb5ce23cmr2013171lji.34.1689260273437; Thu, 13 Jul 2023 07:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689260273; cv=none; d=google.com; s=arc-20160816; b=KyGQUKea2vkrHIAMjLOU+oI5KjCX8iyoca35fsItA0n6HvLgV2vkS4N+wtRUy5g9L1 fMi0pA8wwsIE5cfp1GHpafcUVhTEmhIPjwSFG1Mcl9Ny7IpOSSDdysBOgfCDXCrQVeZD ObYmYWeVHlWbwfaajWcVdti05B1GG6gSSa4vrj1llB8Ho6ZtfipWffod9RiQIlsr7k5I LekzR5mIQ84XGUa4VBmoSWpg8MZyittMqLUtV1vxZUJLuevdO+RaYRiDRFq5/hJ7Govq qoIumGdU6QPDS+u3KVf8Hr4q+8xGYIlZbFX7IFcMdpUW5Fx4K08whEd3T2lpgebyGrqb qMAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:content-language :subject:to:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=DpJSFETtZhuhJd6NHqaR5w096YHtcAeVKrOxhagGfHY=; fh=0aQsLc0V92kpB4FRNib+nLWTzzLLCxCyMbdt3EjzZBE=; b=w7nBNyHyhQF5LFlO6uLCmkFyQ9I9zMCYhTQ90olNYVR/LMa7dzRaoJne9e4wKZJ9qU rgi/d6DHPwLPeP2ZnmHpPm9bAM5af0CgLvMfPLjdFOyEOviVMC0k6/Vx+n8Rt59F8MFf njEBHddvstT9UBMiCc3YcOKyAINKn/X8q8AUpqqOBWWvvQpdumLFkqJsvNYa3eRsDdXW dW9sZ6e4f+jCte6ckLuQgV1HyPGer6KdRqu3w6Ke2l1/oKqmO5oJBYYerEte0lHoI+Mp MsDK0+rsjWlZ36q1Y8vjALD4ZCRNI/JV8rRtq+qWWpMQji2YnExz+br0WtYIzfvLIZZp U1NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pletigj2; 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=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b9-20020a170906490900b0098718777182si7244055ejq.685.2023.07.13.07.57.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 07:57:53 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=pletigj2; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D50E53858413 for ; Thu, 13 Jul 2023 14:57:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D50E53858413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689260271; bh=DpJSFETtZhuhJd6NHqaR5w096YHtcAeVKrOxhagGfHY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pletigj2ORkT6x9mLh9JO5WELxu7D4i6luOQchtzaMpue7sQSIfsiY3ymZMskl105 lJef2SOuujmtY4mwApjHUoVsYS1efuYbgcpurgfWes7GDMVJjfOJD5RjJDaBx3ct2b SnSM8tRWq7zJEGd0tvxdBnYoMogTtHBC0034Quhs= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 794A93858D1E for ; Thu, 13 Jul 2023 14:57:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 794A93858D1E Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-321-jILVsFU-M2OtwIfDs8PB_Q-1; Thu, 13 Jul 2023 10:52:47 -0400 X-MC-Unique: jILVsFU-M2OtwIfDs8PB_Q-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7624ca834b5so109305985a.0 for ; Thu, 13 Jul 2023 07:52:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689259966; x=1691851966; 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=oXEEGM5lWJnglPIwgJZwXlM//fYuGp1v7+N1ktmGSKY=; b=M7iIBy3prw3GuAQIov/mn9rbUFMsLNPRkFS6iGrhKMljFhCajnTq4GTh4okk44efAJ Sb9PdvURFPsTJ/+jJ4r2XQ7Zs2wrvEQVRqenO5t/2y8E0cVbbQKQB5tG1730gLt7cEaA eQTMXNBoI3Oqc8RsYEXc13o94UclAp+PBdv0sdMj+cjmdcwg2Zxo6H4PTtAifoQ9tvgy 5MCX2GfKwQksQpx2r361BQdGo2F5o77DqPmloRMqHPnGZ23ByasbJLjGtmZTmJKqoSUR k8RUCfMfmH4a1XvY8ziMdbXqmngx6JyDJ924ErTtZ5JM0evaR3R/CI1I1Krw1VCLTx6P 55Og== X-Gm-Message-State: ABy/qLbcK8nEUdUU0mtzflWzdF2JgzHw49x05K8bNRRI/qK1YVoL2bSg RoIqhyHXTV8EkxuUB64cgyHB2roA3XRBmiLX35t1EIOPj7wEqxOXwp+MmYQJIgmDeL60sRSrcgx 4BSQ0giBw6i00jcvSqRCOe3lA53oAGw7WzvwO11WjopEcBeEdRkwRIyHZdq19jG/K9WpvK/lFSk e//w== X-Received: by 2002:a05:620a:40d4:b0:767:dcda:b44b with SMTP id g20-20020a05620a40d400b00767dcdab44bmr2839250qko.56.1689259966310; Thu, 13 Jul 2023 07:52:46 -0700 (PDT) X-Received: by 2002:a05:620a:40d4:b0:767:dcda:b44b with SMTP id g20-20020a05620a40d400b00767dcdab44bmr2839217qko.56.1689259965836; Thu, 13 Jul 2023 07:52:45 -0700 (PDT) Received: from [192.168.1.88] (192-0-143-139.cpe.teksavvy.com. [192.0.143.139]) by smtp.gmail.com with ESMTPSA id t2-20020a05620a034200b007623c96430csm2942081qkm.111.2023.07.13.07.52.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jul 2023 07:52:45 -0700 (PDT) Message-ID: Date: Thu, 13 Jul 2023 10:52:44 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 To: "gcc-patches@gcc.gnu.org" Subject: [pushed][RA][PR109520]: Catch error when there are no enough registers for asm insn X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.0 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_H4, RCVD_IN_MSPIKE_WL, SCC_5_SHORT_WORD_LINES, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Vladimir Makarov via Gcc-patches From: Vladimir Makarov Reply-To: Vladimir Makarov Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771317780700281742 X-GMAIL-MSGID: 1771317780700281742 The following patch solves https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109520 The patch was successfully bootstrapped and tested on x86-64, aarch64, and ppc64le. commit b175b4887f928118af997f6d4d75097a64dcec5d Author: Vladimir N. Makarov Date: Thu Jul 13 10:42:17 2023 -0400 [RA][PR109520]: Catch error when there are no enough registers for asm insn Asm insn unlike other insns can have so many operands whose constraints can not be satisfied. It results in LRA cycling for such test case. The following patch catches such situation and reports the problem. PR middle-end/109520 gcc/ChangeLog: * lra-int.h (lra_insn_recog_data): Add member asm_reloads_num. (lra_asm_insn_error): New prototype. * lra.cc: Include rtl_error.h. (lra_set_insn_recog_data): Initialize asm_reloads_num. (lra_asm_insn_error): New func whose code is taken from ... * lra-assigns.cc (lra_split_hard_reg_for): ... here. Use lra_asm_insn_error. * lra-constraints.cc (curr_insn_transform): Check reloads nummber for asm. gcc/testsuite/ChangeLog: * gcc.target/i386/pr109520.c: New test. diff --git a/gcc/lra-assigns.cc b/gcc/lra-assigns.cc index 2f95121df06..3555926af66 100644 --- a/gcc/lra-assigns.cc +++ b/gcc/lra-assigns.cc @@ -1851,20 +1851,8 @@ lra_split_hard_reg_for (void) insn = lra_insn_recog_data[u]->insn; if (asm_noperands (PATTERN (insn)) >= 0) { - lra_asm_error_p = asm_p = true; - error_for_asm (insn, - "% operand has impossible constraints"); - /* Avoid further trouble with this insn. */ - if (JUMP_P (insn)) - { - ira_nullify_asm_goto (insn); - lra_update_insn_regno_info (insn); - } - else - { - PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx); - lra_set_insn_deleted (insn); - } + asm_p = true; + lra_asm_insn_error (insn); } else if (!asm_p) { diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc index 9bfc88149ff..0c6912d6e7d 100644 --- a/gcc/lra-constraints.cc +++ b/gcc/lra-constraints.cc @@ -4813,6 +4813,10 @@ curr_insn_transform (bool check_only_p) lra_update_operator_dups (curr_id); /* Something changes -- process the insn. */ lra_update_insn_regno_info (curr_insn); + if (asm_noperands (PATTERN (curr_insn)) >= 0 + && ++curr_id->asm_reloads_num >= FIRST_PSEUDO_REGISTER) + /* Most probably there are no enough registers to satisfy asm insn: */ + lra_asm_insn_error (curr_insn); } lra_process_new_insns (curr_insn, before, after, "Inserting insn reload"); return change_p; diff --git a/gcc/lra-int.h b/gcc/lra-int.h index 4dbe6672f3a..a32359e5772 100644 --- a/gcc/lra-int.h +++ b/gcc/lra-int.h @@ -209,6 +209,9 @@ public: debug insn. LRA_NON_CLOBBERED_ALT means ignoring any earlier clobbers for the insn. */ int used_insn_alternative; + /* Defined for asm insn and it is how many times we already generated reloads + for the asm insn. */ + int asm_reloads_num; /* SP offset before the insn relative to one at the func start. */ poly_int64 sp_offset; /* The insn itself. */ @@ -307,6 +310,7 @@ extern void lra_delete_dead_insn (rtx_insn *); extern void lra_emit_add (rtx, rtx, rtx); extern void lra_emit_move (rtx, rtx); extern void lra_update_dups (lra_insn_recog_data_t, signed char *); +extern void lra_asm_insn_error (rtx_insn *insn); extern void lra_process_new_insns (rtx_insn *, rtx_insn *, rtx_insn *, const char *); diff --git a/gcc/lra.cc b/gcc/lra.cc index c8b3f139acd..563aff10b96 100644 --- a/gcc/lra.cc +++ b/gcc/lra.cc @@ -106,6 +106,7 @@ along with GCC; see the file COPYING3. If not see #include "backend.h" #include "target.h" #include "rtl.h" +#include "rtl-error.h" #include "tree.h" #include "predict.h" #include "df.h" @@ -536,6 +537,27 @@ lra_update_dups (lra_insn_recog_data_t id, signed char *nops) *id->dup_loc[i] = *id->operand_loc[nop]; } +/* Report asm insn error and modify the asm insn. */ +void +lra_asm_insn_error (rtx_insn *insn) +{ + lra_asm_error_p = true; + error_for_asm (insn, + "% operand has impossible constraints" + " or there are not enough registers"); + /* Avoid further trouble with this insn. */ + if (JUMP_P (insn)) + { + ira_nullify_asm_goto (insn); + lra_update_insn_regno_info (insn); + } + else + { + PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx); + lra_set_insn_deleted (insn); + } +} + /* This page contains code dealing with info about registers in the @@ -973,6 +995,7 @@ lra_set_insn_recog_data (rtx_insn *insn) lra_insn_recog_data[uid] = data; data->insn = insn; data->used_insn_alternative = LRA_UNKNOWN_ALT; + data->asm_reloads_num = 0; data->icode = icode; data->regs = NULL; if (DEBUG_INSN_P (insn)) diff --git a/gcc/testsuite/gcc.target/i386/pr109520.c b/gcc/testsuite/gcc.target/i386/pr109520.c new file mode 100644 index 00000000000..d81b2555202 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr109520.c @@ -0,0 +1,48 @@ +/* { dg-do compile { target { ! ia32 } } } */ +/* { dg-options "-O0" } */ + +int +foo (int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, + int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16) +{ + register int v0 asm ("rax") = a3; + register int v1 asm ("rbx") = a4; + register int v2 asm ("rcx") = a5; + register int v3 asm ("rdx") = a6; + register int v4 asm ("rsi") = a7; + register int v5 asm ("rdi") = a8; + register int v6 asm ("r8") = a9; + register int v7 asm ("r9") = a10; + register int v8 asm ("r10") = a11; + register int v9 asm ("r11") = a12; + register int v10 asm ("r12") = a13; + register int v11 asm ("r13") = a14; + register int v12 asm ("r14") = a15; + register int v13 asm ("r15") = a16; + int x; + + v0 += a0; + v1 += a1; + v2 += a2; + v0 |= a0; + v1 |= a1; + v2 |= a2; + v0 ^= a0; + v1 ^= a1; + v2 ^= a2; + v0 &= a0; + v1 &= a1; + v2 &= a2; + asm goto ("": "=r" (x) : : : lab); /* { dg-error "operand has impossible constraints" } */ + a1 ^= a0; + a2 = a1; + a0 |= a2; + a0 |= x; + lab: + v0 += x + a0 + a1 + a2; + v1 -= a0 - a1 - a2; + v2 |= a0 | a1 | a2; + v3 |= a0 & a1 & a2; + v4 ^= a0 ^ a1 ^ a2; + return v0 + v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + a0 + a1 + a2; +}