From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 3539A389365E for ; Sun, 13 Nov 2022 01:23:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3539A389365E 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-pf1-x430.google.com with SMTP id b185so8028737pfb.9 for ; Sat, 12 Nov 2022 17:23:32 -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=tIAv/U6C3EnC9GYDIwGO8bIqbcmWKKwslG5hJMo6Cb8=; b=dj9sBmE2kWEmllOqOsFduMs3tU+SJF3b9+Cg9k2UoD4zba10FYKPaeM2M3vKZyGYuY 7DqCB/jKUtMIkXM6hDPPkWLq4W/veYyG68FE/WDDDRKpeQsiowst84I0687aaATRN+qX O2nU6DCC+kL8ihDdNEXlzLCVy6LkV5kS4TKVQf/w67yK45Bupx10ZyEqPnhO4s1a4/0j kOCz6rk+GeF45P/i3WBkD3xqu+01UAm8P6Us+o+QI/Lc0NPOlS3ndClA2/R08Jhl5DuL CtgqPdnTdj+b0cZ2FJ7taasr+5BpR+MGLI3yxeW2RE0HNlKo2M25GWBPwVU77yy8X5Po yObg== 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=tIAv/U6C3EnC9GYDIwGO8bIqbcmWKKwslG5hJMo6Cb8=; b=YORR4bD14kdM7pUIIo75VMOsWAZoYDXzuTV1+PFdm3xTexdj4yANfft8ksjxK9g/oK EVuRNhYoAv8JPOPqm1gfK45YADBSlbjl3J/28GLEFWim9e5mXawPsDdBzpe/EFvJRLWI dE09vLcXfFltIeQSmgOO64MmOCTLs1/NG9VGCCA9YVD5meBWQypwhuGmfuYpF4b8psKs oQjCKxW3eeyzrKeFnGPWwbMs1dvXxMo4R37/5JPrBHOgGsfzTykTqeMZMkMkcfsT+wtK dK+rcXvTUw1XZDDqnyEndu/qcTXY75UnYjd60wPZ9tDAKur2GjaSex3QzNMdt/kaxOLC eJgA== X-Gm-Message-State: ANoB5plcTbzKSUI7WqxMIlbAZ82tMpewcWXKZyHf/TWQxAtmlgNW4Jr6 cKh0vTXndxloivb891HGNbY= X-Google-Smtp-Source: AA0mqf6PJKZAY65fZqwyEJcm4ZMZlDvmrx6gctwcyU3fRsOEVz3UsHJcXY9g6o8BK14erUSwNcQu5Q== X-Received: by 2002:a62:6dc4:0:b0:56b:c616:287 with SMTP id i187-20020a626dc4000000b0056bc6160287mr8720660pfc.73.1668302611086; Sat, 12 Nov 2022 17:23:31 -0800 (PST) Received: from ?IPV6:2601:681:8600:13d0::f0a? ([2601:681:8600:13d0::f0a]) by smtp.gmail.com with ESMTPSA id b5-20020a170902650500b00180cf894b67sm4249666plk.130.2022.11.12.17.23.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 12 Nov 2022 17:23:30 -0800 (PST) Message-ID: <1feb8f91-cacc-dacf-afd9-098c3ab59b4b@gmail.com> Date: Sat, 12 Nov 2022 18:23:28 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: [PATCH v2] RISC-V: costs: support shift-and-add in strength-reduction Content-Language: en-US To: Philipp Tomsich , gcc-patches@gcc.gnu.org Cc: Palmer Dabbelt , Vineet Gupta , Jeff Law , Christoph Muellner , Kito Cheng References: <20221110213403.3592364-1-philipp.tomsich@vrull.eu> From: Jeff Law In-Reply-To: <20221110213403.3592364-1-philipp.tomsich@vrull.eu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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 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