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 564713858D32 for ; Sun, 4 Jun 2023 03:59:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 564713858D32 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 d2e1a72fcca58-653fcd58880so751766b3a.0 for ; Sat, 03 Jun 2023 20:59:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685851160; x=1688443160; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=tzAeJ0CMyl+NPFIkwCn0ykXhVNCiEyUa+99bjt2T2BY=; b=ayyHDOeB+LyCM0cPwo3E/Eule9kXh+e5f467H4uxyGWqc3eFMSgFHhgxouTJUxj0KM jVZd4SNgt8Bu/xAUEAu5myWdbTr5SfjnJb1UT+vU32Njdiw8apQIUZIPUMZrcDy3psQA cw4XF5pG3427/M493uuHmUVJxQDtE85ySn7zo2UKLf5O09ER6m+2MQTko+8YQd6LeDtc QWKO3Y8ZXcC7JQFGxx35xA91mCzrW0ZpvExaV5/hKWsezuF+uZwn9SU7CGVjgDX1pGiR z9RY/exAr0m96CuFpIS5qtDJnBIc6WJXeD8oqOXI/7RYU+RfSADJ7NjXR1+DmsdSQ1kX n19w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685851160; x=1688443160; h=content-transfer-encoding:in-reply-to:from:references: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=tzAeJ0CMyl+NPFIkwCn0ykXhVNCiEyUa+99bjt2T2BY=; b=cDW81VmGTEOnD8ezsHUuCDwmOxUQ0kE4XZ4WWlQcQMebvFcEEoQjf3VedkfOWtdw7F 4TFcT/oeQ4QQ0S6cMG/iJO3uPOR8y1T3QCPik8xdy3oAp4DF2RyCeRglGt8/QiL1AOPv s7jeaC9+yCg0U0lNabvcvfDbW+Zm+7XaJb6RHispPhdv97EF97yMi5I+YTujK/u+6jmN nT1UtZVmZK0XzMb4rYg+in3kzocMYjd0gx5E8aKgrufH6Ga2MlFY2DQZKsLe3YiUy5tU 6/vM2zwIA1ZNLnnWJSthxDAXqiNGCLpZLtD3CNAcKkD035GNR1c86L9stI/xwgU2EukV jHyg== X-Gm-Message-State: AC+VfDx5RkiptqmErXuifz7sKOkjPdNkda8g7ZvHX2Xy3ulYda6tuRuv WcD5zaHReGK2/ehHtx9EQ1w= X-Google-Smtp-Source: ACHHUZ7guk8ykudlqdWXHr1o4khm09lh5cI7BxrqyqF/ieqf/v9eY/9XxA5TkKtHBoBalrHjmEEJ3A== X-Received: by 2002:a05:6a20:158b:b0:10c:4c76:e909 with SMTP id h11-20020a056a20158b00b0010c4c76e909mr1150600pzj.8.1685851159994; Sat, 03 Jun 2023 20:59:19 -0700 (PDT) Received: from ?IPV6:2607:fb90:469:b40a:c15c:6a92:5516:c5a5? ([2607:fb90:469:b40a:c15c:6a92:5516:c5a5]) by smtp.gmail.com with ESMTPSA id q14-20020a170902dace00b001b042c0939fsm3923811plx.99.2023.06.03.20.59.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 03 Jun 2023 20:59:19 -0700 (PDT) Message-ID: Date: Sat, 3 Jun 2023 21:59:16 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [RFC] RISC-V: Eliminate extension after for *w instructions Content-Language: en-US To: Jivan Hakobyan , 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.2 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,T_SCC_BODY_TEXT_LINE 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 5/24/23 17:14, Jivan Hakobyan via Gcc-patches wrote: > `This patch tries to prevent generating unnecessary sign extension > after *w instructions like "addiw" or "divw". > > The main idea of it is to add SUBREG_PROMOTED fields during expanding. > > I have tested on SPEC2017 there is no regression. > Only gcc.dg/pr30957-1.c test failed. > To solve that I did some changes in loop-iv.cc, but not sure that it is > suitable. So this generally looks good and I did some playing around with it over the weekend. It's generally a win, though it can result in performance regressions under the "right" circumstances. The case I was looking at was omnetpp in spec. I suspect you didn't see it because we have a parameter which increases the threshold for when a string comparison against a constant string should be inlined. I suspect you aren't using that param. I inherited that param usage and haven't tried to eliminate it yet. If you compile a test like this: #include int foo (char *x) { return strcmp (x, "lowerLayout"); } With -O2 --param builtin-string-cmp-inline-length=100 You'll see the regression. This is reasonable representation of the code in omnetpp. It's actually a fairly interesting little problem. We end up with overlapping lifetimes for the 32 and 64bit results. The register allocator doesn't really try hard to detect the case where it can ignore a conflict because the two objects hold the same value. I remember kicking this around with Vlad at least 10 years ago and we concluded (based on experience and data at the time) that this case wasn't that important to handle. Anyway... Another approach to this problem would be to twiddle the strcmp expander to work in word_mode, then convert the word mode result to the final mode at the end of the sequence. I need to ponder the semantics of this a bit more, but if the semantics are right, it seems like it might be a viable solution. I briefly looked at the big improvement in leela (33b instructions, roughly 1.7% of the dynamic count removed). The hope was that if I looked at the cases where we improved that they would all be shifts, rotates and the like and we could consider a more limited version of your patch. But it was quite clear that the improvement in leela as due to better handling of 32bit additions. So that idea's a non-starter. I didn't look at the big gains in xz (they're smaller in absolute count terms, but larger in percentage of instructions removed). So I'm going to play a bit more with the expander for comparisons against constant strings. If done correctly it might actually be an improvement on other targets as well. Jeff > > > gcc/ChangeLog: > * config/riscv/bitmanip.md (rotrdi3): New pattern. > (rotrsi3): Likewise. > (rotlsi3): Likewise. > * config/riscv/riscv-protos.h (riscv_emit_binary): New function > declaration > * config/riscv/riscv.cc (riscv_emit_binary): Removed static > * config/riscv/riscv.md (addsi3): New pattern > (subsi3): Likewise. > (negsi2): Likewise. > (mulsi3): Likewise. > (si3): New pattern for any_div. > (si3): New pattern for any_shift. > * loop-iv.cc (get_biv_step_1): Process src of extension when it > PLUS > > gcc/testsuite/ChangeLog: > * testsuite/gcc.target/riscv/shift-and-2.c: New test > * testsuite/gcc.target/riscv/shift-shift-2.c: New test > * testsuite/gcc.target/riscv/sign-extend.c: New test > * testsuite/gcc.target/riscv/zbb-rol-ror-03.c: New test > >