From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id 174283858280 for ; Sun, 13 Nov 2022 15:41:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 174283858280 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-lf1-x133.google.com with SMTP id be13so15543775lfb.4 for ; Sun, 13 Nov 2022 07:41:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=GNbsuL/DnMeZOW+7YFAosShBLJX+iHi8kqSDAEP40hY=; b=GrBW6JGR92wkiWnyyXUrbQuHtpCxgAgsIaDu2CdUaTtjRvD8hT3lZbllCtM2JOqKW3 GhIwcdG0N7U2gLhYlSTtnjx0z4b1W1FPGrejpEtl8ypoN7n+6LuL5yz10f/rEEVHn1Dl URtVSBJTDGQAgX0hgpfU1nlObqEUGQ9ozWpJbNH2bBOJ50EUU3qakirUfEgffYeRmm4O 1/RFKRksKUZ621LVvV9LYhnEOK+Y0HSgT3H4um1fW1v5Hcn3iTYxGOqXHuuB/174AWP7 8O1n3jLmYDCDAr08dI9F5lUPQFZ82SiePC0f74PYePOS7Pf25TjL24tpGTsqUKFTaCyf xj9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GNbsuL/DnMeZOW+7YFAosShBLJX+iHi8kqSDAEP40hY=; b=flZ7dJFk/qNOsHDchZZJI7Y5z379XJ3j2yk5xuix3H7cP9Ks9W+4UT3CepTK0Pfg82 Dwz4MTYtI4jkqxiuPpFTISRu8blf12AH63ByS9p8zfvy2jH4J8o9/ew27coGMRHyvX1q HtsLjXLZNfATFXDjbzmubN8E+Uijuf6FkpokpgF38QjCUTruJwornUuMVy2CohIDnTa4 XkV6PoJ0r/jd+QPiquVStkKfkPenNHfInw287y1FjIDRmQYyy3LRt4qAr4Wj1HtTHclv ezTISmEh4HOojwPn3ZVLHuxfCimT/MYOPASNaqPj1i0m/FPV7Snog2xBlf+CYjvb8pbh B1Dw== X-Gm-Message-State: ANoB5plwKmTXQOzZJBNclZsc9yTHdgIzvY96TnZMMx058RcSpDc7W2CT YXAo3Epdf9hu0x3duQEMDV2cmC9chzGocO2p5BwNTw== X-Google-Smtp-Source: AA0mqf6F9XPSCN3otqnw1mcmeshDyOKVQL9BQHSaU5Fv7MbdmZxsLlpJuGymYGp2vQ3PE1jwVY6But/Zxvg+nGYqJSE= X-Received: by 2002:ac2:47ea:0:b0:4b4:1324:6ed3 with SMTP id b10-20020ac247ea000000b004b413246ed3mr3022325lfp.19.1668354058452; Sun, 13 Nov 2022 07:40:58 -0800 (PST) MIME-Version: 1.0 References: <20221110213403.3592364-1-philipp.tomsich@vrull.eu> <1feb8f91-cacc-dacf-afd9-098c3ab59b4b@gmail.com> In-Reply-To: <1feb8f91-cacc-dacf-afd9-098c3ab59b4b@gmail.com> From: Philipp Tomsich Date: Sun, 13 Nov 2022 16:40:46 +0100 Message-ID: Subject: Re: [PATCH v2] RISC-V: costs: support shift-and-add in strength-reduction To: Jeff Law Cc: gcc-patches@gcc.gnu.org, Palmer Dabbelt , Vineet Gupta , Jeff Law , Christoph Muellner , Kito Cheng Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,JMQ_SPF_NEUTRAL,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Applied to master. Thanks! Note that the multiply-by-200 (in the testcase) originates from Dhrystone. Philipp. On Sun, 13 Nov 2022 at 02:23, Jeff Law wrote: > > > On 11/10/22 14:34, Philipp Tomsich wrote: > > The strength-reduction implementation in expmed.cc will assess the > > profitability of using shift-and-add using a RTL expression that wraps > > a MULT (with a power-of-2) in a PLUS. Unless the RISC-V rtx_costs > > function recognizes this as expressing a sh[123]add instruction, we > > will return an inflated cost---thus defeating the optimization. > > > > This change adds the necessary idiom recognition to provide an > > accurate cost for this for of expressing sh[123]add. > > > > Instead on expanding to > > li a5,200 > > mulw a0,a5,a0 > > with this change, the expression 'a * 200' is sythesized as: > > sh2add a0,a0,a0 // *5 = a + 4 * a > > sh2add a0,a0,a0 // *5 = a + 4 * a > > slli a0,a0,3 // *8 > > > > gcc/ChangeLog: > > > > * config/riscv/riscv.c (riscv_rtx_costs): Recognize shNadd, > > if expressed as a plus and multiplication with a power-of-2. > > Split costing for MINUS from PLUS. > > > > gcc/testsuite/ChangeLog: > > > > * gcc.target/riscv/zba-shNadd-07.c: New test. > > OK. Note that getting this right can impact one of the spec2017 integer > benchmarks notably. I don't recall which one, but it has a div and a > mod by the same constant which is fairly reasonably implement with > shifts and adds. You won't see it in instruction count data, but would > see it if you had cycle count data or instrumented for div/mod instructions. > > > Jeff > >