From patchwork Mon Feb 28 21:49:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 51453 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 66A263858406 for ; Mon, 28 Feb 2022 21:49:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 66A263858406 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1646084986; bh=TbCyKwjqlNvfj+Wvdxle7HX2z7FrlxCUd9qTv6mXfqM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=knWUN/Lfo7ocJKpfAjR5rofnAu0FcRy8kEmCbShmVC+uJRCj4o6Ke2KWx2/ILFHio OpGMlFXjWrP8F3iOO+IQJeoK88J8JZmnGan2oDstlB8tu2tKUHdhpTwczkGDhzKIsp K2Ubp/jF8qw/fSTGRdE8mP+OyU9I95kV6Uo2e/Mc= 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 13E7F3858D20 for ; Mon, 28 Feb 2022 21:49:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 13E7F3858D20 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-114-XEXbDB5kNFKC96pD6erEUg-1; Mon, 28 Feb 2022 16:49:11 -0500 X-MC-Unique: XEXbDB5kNFKC96pD6erEUg-1 Received: by mail-qv1-f71.google.com with SMTP id fq2-20020a056214258200b0042c39c09e5dso13507261qvb.18 for ; Mon, 28 Feb 2022 13:49:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:from:subject; bh=ZQcGbfWTTy/lFp8ONkZaF6y2cA11pP3oWyXYPejlxP4=; b=pI9AgNf23X5ESs6r2obMeTzD1SQKqXido/Ykvh7WY5zd7dFdcn7Dey1/jFbHEXsWCP qKfDqkIcGwtjNCA+uTUuWIlT0JEP/fm2RQqJ7hhhs3Qf36QqqJc1490ZaV2RYnuOvuOl J1gmTjnKJpLo/uyW5ULvRv8mQ0LaDiUwsG/DoqUO/vT8DYhf6H3lcPAvoNs3ehnLD4uu 8FpwqcyZmuG8y3CIs0MhE2uEOhsE3j5Rnf4EKD9kSSxP2kVGH2Vt03E04oMhl5frPDGW sxfYB671cMjmNn4Aw0A/LyIw47i2zrpQPDiXjuGLXX4iqjkJCyrXrpM8G7zBamcv+L7q GbIw== X-Gm-Message-State: AOAM533GCkYBs1vuXvYc8IfGW8N+4arhBmWwdlaTGqJ68o3oXT6C0SYA a9YGRS1rT4CGBlb/JF46RRPTwptH70iCBAIGLeClB8davGGXwvGa/FgUKbccEbN2vErPGcuvOBJ MK93c53OOfZQsIqfAb54ZGhxcemPhhHlIADfiUQbCTotBb1LvoI22DFdsTVGX8GDBhF58zQ== X-Received: by 2002:ad4:4e69:0:b0:432:8a22:90f2 with SMTP id ec9-20020ad44e69000000b004328a2290f2mr15507216qvb.81.1646084950951; Mon, 28 Feb 2022 13:49:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJylGm53SQZ6s2fgna+fLUb9qVu0+CjW9/ipcqVll9Gg6aM/GxTJ4tTShwJ1Zs0SjR6kCgAYvQ== X-Received: by 2002:ad4:4e69:0:b0:432:8a22:90f2 with SMTP id ec9-20020ad44e69000000b004328a2290f2mr15507167qvb.81.1646084949621; Mon, 28 Feb 2022 13:49:09 -0800 (PST) Received: from [192.168.1.113] ([69.165.238.126]) by smtp.gmail.com with ESMTPSA id d13-20020a05622a05cd00b002dffcc45ba5sm5058009qtb.4.2022.02.28.13.49.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Feb 2022 13:49:09 -0800 (PST) Message-ID: <4a0082c6-822f-9051-8fbe-8bd5b3e7372f@redhat.com> Date: Mon, 28 Feb 2022 16:49:08 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 To: "gcc-patches@gcc.gnu.org" Subject: [committed] [PR104637] LRA: Split hard regs as many as possible on one subpass X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.2 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_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The following patch fixes https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104637 The patch was successfully bootstrapped and tested on x86-64, aarch64, and ppc64. commit ec1b9ba2d7913fe5e9deacc8e55e7539262f5124 Author: Vladimir N. Makarov Date: Mon Feb 28 16:43:50 2022 -0500 [PR104637] LRA: Split hard regs as many as possible on one subpass LRA hard reg split subpass is a small subpass used as the last resort for LRA when it can not assign a hard reg to a reload pseudo by other ways (e.g. by spilling non-reload pseudos). For simplicity the subpass works on one split base (as each split changes pseudo live range info). In this case it results in reaching maximal possible number of subpasses. The patch implements as many non-overlapping hard reg splits splits as possible on each subpass. gcc/ChangeLog: PR rtl-optimization/104637 * lra-assigns.cc (lra_split_hard_reg_for): Split hard regs as many as possible on one subpass. gcc/testsuite/ChangeLog: PR rtl-optimization/104637 * gcc.target/i386/pr104637.c: New. diff --git a/gcc/lra-assigns.cc b/gcc/lra-assigns.cc index c1d40ea2a14..ab3a6e6e9cc 100644 --- a/gcc/lra-assigns.cc +++ b/gcc/lra-assigns.cc @@ -1774,8 +1774,8 @@ lra_split_hard_reg_for (void) iterations. Either it's an asm and something is wrong with the constraints, or we have run out of spill registers; error out in either case. */ - bool asm_p = false; - bitmap_head failed_reload_insns, failed_reload_pseudos; + bool asm_p = false, spill_p = false; + bitmap_head failed_reload_insns, failed_reload_pseudos, over_split_insns; if (lra_dump_file != NULL) fprintf (lra_dump_file, @@ -1786,6 +1786,7 @@ lra_split_hard_reg_for (void) bitmap_ior (&non_reload_pseudos, &lra_inheritance_pseudos, &lra_split_regs); bitmap_ior_into (&non_reload_pseudos, &lra_subreg_reload_pseudos); bitmap_ior_into (&non_reload_pseudos, &lra_optional_reload_pseudos); + bitmap_initialize (&over_split_insns, ®_obstack); for (i = lra_constraint_new_regno_start; i < max_regno; i++) if (reg_renumber[i] < 0 && lra_reg_info[i].nrefs != 0 && (rclass = lra_get_allocno_class (i)) != NO_REGS @@ -1793,14 +1794,41 @@ lra_split_hard_reg_for (void) { if (! find_reload_regno_insns (i, first, last)) continue; - if (BLOCK_FOR_INSN (first) == BLOCK_FOR_INSN (last) - && spill_hard_reg_in_range (i, rclass, first, last)) + if (BLOCK_FOR_INSN (first) == BLOCK_FOR_INSN (last)) { - bitmap_clear (&failed_reload_pseudos); - return true; + /* Check that we are not trying to split over the same insn + requiring reloads to avoid splitting the same hard reg twice or + more. If we need several hard regs splitting over the same insn + it can be finished on the next iterations. + + The following loop iteration number is small as we split hard + reg in a very small range. */ + for (insn = first; + insn != NEXT_INSN (last); + insn = NEXT_INSN (insn)) + if (bitmap_bit_p (&over_split_insns, INSN_UID (insn))) + break; + if (insn != NEXT_INSN (last) + || !spill_hard_reg_in_range (i, rclass, first, last)) + { + bitmap_set_bit (&failed_reload_pseudos, i); + } + else + { + for (insn = first; + insn != NEXT_INSN (last); + insn = NEXT_INSN (insn)) + bitmap_set_bit (&over_split_insns, INSN_UID (insn)); + spill_p = true; + } } - bitmap_set_bit (&failed_reload_pseudos, i); } + bitmap_clear (&over_split_insns); + if (spill_p) + { + bitmap_clear (&failed_reload_pseudos); + return true; + } bitmap_clear (&non_reload_pseudos); bitmap_initialize (&failed_reload_insns, ®_obstack); EXECUTE_IF_SET_IN_BITMAP (&failed_reload_pseudos, 0, u, bi) diff --git a/gcc/testsuite/gcc.target/i386/pr104637.c b/gcc/testsuite/gcc.target/i386/pr104637.c new file mode 100644 index 00000000000..65e8635d55e --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr104637.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-Og -fno-forward-propagate -mavx" } */ + +typedef short __attribute__((__vector_size__ (64))) U; +typedef unsigned long long __attribute__((__vector_size__ (32))) V; +typedef long double __attribute__((__vector_size__ (64))) F; + +int i; +U u; +F f; + +void +foo (char a, char b, _Complex char c, V v) +{ + u = (U) { u[0] / 0, u[1] / 0, u[2] / 0, u[3] / 0, u[4] / 0, u[5] / 0, u[6] / 0, u[7] / 0, + u[8] / 0, u[0] / 0, u[9] / 0, u[10] / 0, u[11] / 0, u[12] / 0, u[13] / 0, u[14] / 0, u[15] / 0, + u[16] / 0, u[17] / 0, u[18] / 0, u[19] / 0, u[20] / 0, u[21] / 0, u[22] / 0, u[23] / 0, + u[24] / 0, u[25] / 0, u[26] / 0, u[27] / 0, u[28] / 0, u[29] / 0, u[30] / 0, u[31] / 0 }; + c += i; + f = (F) { v[0], v[1], v[2], v[3] }; + i = (char) (__imag__ c + i); +}