From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id 0AE113858434 for ; Sun, 5 Mar 2023 19:07:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0AE113858434 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-x62d.google.com with SMTP id p20so7932938plw.13 for ; Sun, 05 Mar 2023 11:07:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678043269; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=AtqBIZII4g9E9A3dAgWYRTuFH1FshB5njRFP/OIb90E=; b=KrbgU8qLCwrgOFg5OAiAt22wSm2K72tN1FVZVl6+GmjL+V87P0mZOBlmBLhLlealaY 64NkPbhn7cf7eYa4qKIgpAO3WBQOabanwopkLYqBMwTFwy2bNksmwfjlrPp8N7I2PN7P 5YfmSiz2IdDy/Fo3+5mBsMgqge/Eqq72UxNREg1MY8lxT1DcGWLHxSMz7D9w1y5HHcpj K85cIkl7rvpc5x2ySz0MQ45CUxF0p2SXAnnHtwvc89tBOi51juS+6J24ypsoeYG6Yk3E 4KxJ5Hwo2GiYy/ttWbOA3ZTpEPL/BF0wWH7H5ScKpP8rItXhNr6Zx5AggHmPgxl3aIWb b7LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678043269; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AtqBIZII4g9E9A3dAgWYRTuFH1FshB5njRFP/OIb90E=; b=Cf83kRpbRMh1+rGM5IG21iyXSeQjHsEJUeuMlc02P43HhWVozx/VU4vJicfoCxS+sG 3j/17nmYN5oIqxjZU3EuB48k6I3SIQ0cePsqeDmg5dxVOmvbaCxwOzoYzv4hmxN3A16F mCZoyHhyB4+tW6weuOcCnwttnfzTj+mQCiZtNl+cHVPbYnRa1fbfB9XPm6TzBLWqxIpU AWYMYq+GADBezvf/IhuDaFG9i37jTzQp76d25Ytv6lTnqbDseePJXnbsOc26QnBEy/IW a4uI6+LmUtPTxICt8iaEVueSlE9eOcr1hSuaUQG/icL0/Jq+o3oDdJo46NOYpNOqc/Bq WmGQ== X-Gm-Message-State: AO0yUKVfhcsKAgyBcHRAv/MrbQJ4Rap9cL2nVj/KSBDQ4iXGXebA0ZKZ XvVpLXf46v4uKbIKoMFMK5Q= X-Google-Smtp-Source: AK7set+QyX3lp1biMnHBTNtK3DxVCCLb8+49I56gXJRvA60+TbMhoLl6iS1qHR/oHFwRY3Y+jSV+KA== X-Received: by 2002:a17:902:ce91:b0:19d:1dfe:eac8 with SMTP id f17-20020a170902ce9100b0019d1dfeeac8mr13564185plg.26.1678043268755; Sun, 05 Mar 2023 11:07:48 -0800 (PST) Received: from ?IPV6:2601:681:8600:13d0::f0a? ([2601:681:8600:13d0::f0a]) by smtp.gmail.com with ESMTPSA id m12-20020a63fd4c000000b004fb10399da2sm4822619pgj.56.2023.03.05.11.07.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 05 Mar 2023 11:07:48 -0800 (PST) Message-ID: Date: Sun, 5 Mar 2023 12:07:47 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH v2] RISC-V: Produce better code with complex constants [PR95632] [PR106602] Content-Language: en-US To: Andrew Pinski Cc: gcc-patches@gcc.gnu.org References: <20221209182510.43515-1-rzinsly@ventanamicro.com> <41ba8a45-b4a6-aaf4-1b7a-6e7a7d2dec4f@gmail.com> From: Jeff Law In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 3/5/23 12:03, Andrew Pinski wrote: > On Sun, Mar 5, 2023 at 10:14 AM Jeff Law via Gcc-patches > wrote: >> >> >> >> On 2/23/23 14:23, Andrew Pinski via Gcc-patches wrote: >>> On Fri, Dec 9, 2022 at 10:25 AM Raphael Moreira Zinsly >>> wrote: >>>> >>>> Changes since v1: >>>> - Fixed formatting issues. >>>> - Added a name to the define_insn_and_split pattern. >>>> - Set the target on the 'dg-do compile' in pr106602.c. >>>> - Removed the rv32 restriction in pr95632.c. >>>> >>>> -- >8 -- >>>> >>>> Due to RISC-V limitations on operations with big constants combine >>>> is failing to match such operations and is not being able to >>>> produce optimal code as it keeps splitting them. By pretending we >>>> can do those operations we can get more opportunities for >>>> simplification of surrounding instructions. >>>> >>>> 2022-12-06 Raphael Moreira Zinsly >>>> Jeff Law >>>> >>>> gcc/Changelog: >>>> PR target/95632 >>>> PR target/106602 >>>> * config/riscv/riscv.md: New pattern to simulate complex >>>> const_int loads. >>>> >>>> gcc/testsuite/ChangeLog: >>>> * gcc.target/riscv/pr95632.c: New test. >>>> * gcc.target/riscv/pr106602.c: New test. >>>> --- >>>> gcc/config/riscv/riscv.md | 15 +++++++++++++++ >>>> gcc/testsuite/gcc.target/riscv/pr106602.c | 14 ++++++++++++++ >>>> gcc/testsuite/gcc.target/riscv/pr95632.c | 15 +++++++++++++++ >>>> 3 files changed, 44 insertions(+) >>>> create mode 100644 gcc/testsuite/gcc.target/riscv/pr106602.c >>>> create mode 100644 gcc/testsuite/gcc.target/riscv/pr95632.c >>>> >>>> diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md >>>> index df57e2b0b4a..b0daa4b19eb 100644 >>>> --- a/gcc/config/riscv/riscv.md >>>> +++ b/gcc/config/riscv/riscv.md >>>> @@ -1667,6 +1667,21 @@ >>>> MAX_MACHINE_MODE, &operands[3], TRUE); >>>> }) >>>> >>>> +;; Pretend to have the ability to load complex const_int in order to get >>>> +;; better code generation around them. >>>> +(define_insn_and_split "*mvconst_internal" >>>> + [(set (match_operand:GPR 0 "register_operand" "=r") >>>> + (match_operand:GPR 1 "splittable_const_int_operand" "i"))] >>>> + "cse_not_expected" >>> >>> This is just way broken. This should be combined with the normal move >>> instructions and just be a define_split. >>> See PR 108892 for a testcase which shows this breaking how the >>> register allocator thinks it should work. >> I'm pretty sure that won't work. You need them exposed as a define_insn >> so that they can act as a bridge pattern for combine. You don't want to >> expose before combine as that'll regress things in a variety of other >> ways. You don't want the bridge form to survive after splitting. Hence >> define_insn_and_split. >> >> I haven't looked at that bug in detail, but Raphael and I certainly will. > > So the register allocator does not know how to handle if there are two > different patterns which are to be used but differ by > constraints/predicats. This is especially true for mov instructions > which this is. The define_insn_and_split for this case shouldn't be available for the allocator. If it is, then that's the source of the problem. We may have missed something in the predicates. > What I am saying is the "*movdi_64bit" and "*movsi_internal" patterns > should handle the same instruction as the above and still have a > define_split. Perhaps but I think that's independent of the problem you're bumping up against. Also note that by the time we're in the allocator we have to be more careful as we can't allocate new pseudos. > > Take a look at how aarch64 handles this here. It has one pattern for > the move but it is a define_insn_and_split still. This is explicitly > to handle the case you are doing really. > "*movsi_aarch64" and "*movdi_aarch64" . Will do. Jeff