From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by sourceware.org (Postfix) with ESMTPS id E01A63858D32 for ; Sat, 18 Feb 2023 21:08:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E01A63858D32 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-il1-x12d.google.com with SMTP id u5so491387ilk.9 for ; Sat, 18 Feb 2023 13:08:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=Z+T6ZzUryIUsmNupTLuWurmayyv/4BzzhXoBCf4EbYY=; b=U01suKHeP/btIAefRvkNeIKHYV++87v79g7muq3DsqTQV+b7RSJcxX6ZlA62svKr/0 zbmI87zOJyZN8Bu5T1UlxNMaYFe1MrjZwoYGZse5gyWRBcmbd5eQE35i8Ro45XYSsm6R Jq/MHCgs03izK1YX6f8YX6Xi0kV7aWfQFfw7qYScmW9nFzb8JB05anhSuT64ibqE0I4V JdtX6vPOiL8QhGqK75435oXKLUroHsMta9UWCAyf5cKmJqV5w6Br1qf5lPtpjOapqvfB +7bQguE4EYnXLic9OnN80lDN52vC4q2QyrOZY5isU62PTfJhK2JxOj6ptqmnnwSXn5kz 18/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Z+T6ZzUryIUsmNupTLuWurmayyv/4BzzhXoBCf4EbYY=; b=NH9CIskz2iqRfU/Rj6ZCD/ImHr8ZAT9s53e6r6+1NYXhlSV+4w1RV/PVfC6+FOmlAz CcgVcjKkpLbBBIqEpiph8qKDa+sE8PhIWqhGpCIuIBjJTgGfgs7laHfVTK+zV21kCPlq /1+TcpWjjmDwfqcAIlZK4Qi7g+LOpX2P7x3U/4bJ+3gT8i7RgRlha5Al6PHERJKy2QEM DX3c+Vqyk/5BgDHk9KZuZ07KmDWpJSfU3i7eFNiQFUgxV3Y5gPtwpOHbuvRQibGZZHBn Bxbwwwzlk8bwN1qHNXrQOTtJbJoCmuWXTx9UKBsY5h3cCmdJmG/hLKnIehwsKXiuKOjd rOaA== X-Gm-Message-State: AO0yUKUmqB1cmkQNvYwlCbsn4LC0h2jo75Z8nUf2aH4sw4p5uVZF9MAH iJE7aLc7p8vd41Y2zAUDLF4= X-Google-Smtp-Source: AK7set9uahoZYqhxTLUsDAChnNnqeFSSl8roZGvhfXrUs5UrInaZUsmdShYLF3bilQhc48HLpIA70A== X-Received: by 2002:a05:6e02:1e09:b0:315:6840:f727 with SMTP id g9-20020a056e021e0900b003156840f727mr1097330ila.8.1676754481093; Sat, 18 Feb 2023 13:08:01 -0800 (PST) Received: from ?IPV6:2601:681:8600:13d0::f0a? ([2601:681:8600:13d0::f0a]) by smtp.gmail.com with ESMTPSA id g12-20020a92cdac000000b0031571deaae2sm66553ild.20.2023.02.18.13.08.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 18 Feb 2023 13:08:00 -0800 (PST) Message-ID: <26ca669c-70ce-e475-717e-3c36f1e1c703@gmail.com> Date: Sat, 18 Feb 2023 14:07:59 -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: RISC-V: Add divmod instruction support Content-Language: en-US To: "Maciej W. Rozycki" , Andrew Pinski Cc: Palmer Dabbelt , gcc-patches@gcc.gnu.org References: From: Jeff Law In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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 2/18/23 12:31, Maciej W. Rozycki wrote: > On Sat, 18 Feb 2023, Andrew Pinski via Gcc-patches wrote: > >>>> If we have division and remainder calculations with the same operands: >>>> >>>> a = b / c; >>>> d = b % c; >>>> >>>> We can replace the calculation of remainder with multiplication + >>>> subtraction, using the result from the previous division: >>>> >>>> a = b / c; >>>> d = a * c; >>>> d = b - d; >>>> >>>> Which will be faster. >>> >>> Do you have any benchmarks that show that performance increase? The ISA >>> manual specifically says the suggested sequence is div+mod, and while >>> those suggestions don't always pan out for real hardware it's likely >>> that at least some implementations will end up with the ISA-suggested >>> fusions. >> >> I suspect I will be needing this kind of patch for the core that I am >> going to be using. >> If anything this should be under a tuning option. > > Barring the fusion case, which indeed asks for a dedicated `divmod' > pattern (and then I suppose a post-reload splitter or a peephole so that > where one of the two results produced has eventually turned out unused, we > have means to discard the unneeded machine instruction), isn't the generic > transformation something for the middle end to do based on RTX costs? I originally though the same way you did Maciej. The problem is you don't see it as a divmod in expand_divmod unless you expose a divmod optab. See tree-ssa-mathopts.cc's divmod handling. jeff