From patchwork Mon May 6 20:09:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1932154 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=QMI4ZFqn; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VYCFS44Dwz1xnT for ; Tue, 7 May 2024 06:10:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E6A373858417 for ; Mon, 6 May 2024 20:10:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by sourceware.org (Postfix) with ESMTPS id 4F8FE3858D1E for ; Mon, 6 May 2024 20:09:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4F8FE3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ventanamicro.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4F8FE3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::231 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715026182; cv=none; b=c0C2I6Y0u4vSDvw7Pxry+LJSlGrElULsCgXpQqZSNteIEOO+WWGrKvKpci3v/jJkAMX0qLEtzj9bY3Kbt1htHRTzVFbOuNB2ZPVcTbYtlNPAugLy2zWp3GLFyqgaOPXxMdY9lvwr6cF7uz9L4u2mub2Wewcn7jJLJmIQV/A82uE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715026182; c=relaxed/simple; bh=SpsOwUwuTDbJMMDMUY0+cBrvc14CfRq2yeFcC3shQXw=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:To:Subject; b=KT6GCH2hsMCI7a+QLfPBNMtajiiOSQLI+GQGPRsQyjYgv1H+zpDFClYHY7j16JlzWyCZMAGDC7KQ8oCDP+YMyo+Jv4TtJ6MWtR/OAwRmiyAz8B+vzrsPZ7MIAF8XDT9HjxXb7Uhz9sV+qD/tPq2zj5nmzYjYviTwHNFTcikl0vA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3c96be1ef20so824903b6e.1 for ; Mon, 06 May 2024 13:09:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1715026178; x=1715630978; darn=gcc.gnu.org; h=subject:to:from:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=ZZsNGC+5y2Pz2m/VjdC89NpErdPRm7nl9lZ6UCOkIyc=; b=QMI4ZFqnpjlzqog6nmo2ir9+8shQGDWVhI+hfwug3+2ujwV/qcGHRdxH2mlRVMUDmM YIFTckKzhONrelPtKaXCxCR60PJpgtSKpWnjq62cAiMNJPXkI/lJdbi6+6g9BCAHst+7 bDtzOHE00CMdFxbPl+rVexIWtdS8AGv3ZuJJC7jnEcj7aft3X75hj+qZoudi8FDGRwaX 6sSL0ejuXHhfyQ+yOA7SCIxS7rql1MMzaNpIXxpdC9MPUOuKea55HLso5svkXTU3n6TU 6+hrkYRQGYnGnJ02ZkelQ5o4iR55YGbXDb7CT0BhHA7ckxWw+gtoML3yqnbsUt2uf6Cl vTaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715026178; x=1715630978; h=subject:to:from:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZZsNGC+5y2Pz2m/VjdC89NpErdPRm7nl9lZ6UCOkIyc=; b=WavXKu7bhmPZoXZRLnt58bwYBXtdoSLqv4tBvQ7iBAqZl6liU9vxofot8wxP5kuawW UVKy5i2e6PcYC8ZZ3SE2DrKWtimXfXplJMs5eEN0CMbrvVxfWbtmqm1+9biU4DS81DH8 kaiiR6qxEVVfIQJ9sQYoZSgW9u8hJOXFK+ftGJGt08cpUtZwJU/lmPSVt5Obr6hKaktT oQvl0+M0KvFfHSYPTd18mstMsSl9ca3Fy0tZozi7fFzdEvAgCREVKWy9Macwx65Kqty/ VzsIAR7lMeUBqxd3WLzP5H0GqIovvcIU3BkcjvyAAaqqMuRMpdNO3zZWDKckc1B9vMDc JCMA== X-Gm-Message-State: AOJu0YwIqCPavl0gm9btJhLdoCkws35WaubO3bipASQWasx4xoBjB/9Q +TUgVfTpMB0Mcj4/BcyKL1srPJ5My1+Q4hakLMMMQ/JX0vV3G8wE4p96zHR+L2MtNp7/30sYEiV 5 X-Google-Smtp-Source: AGHT+IEJGftobWEW2bPPEph7iAkEo3+XeO9Ac1jHKGdcnMspLp/t1bhT8jkCgB7M86hLwyjSdvG3Cg== X-Received: by 2002:a05:6808:f0e:b0:3c9:5ad8:ba04 with SMTP id m14-20020a0568080f0e00b003c95ad8ba04mr14398821oiw.29.1715026178126; Mon, 06 May 2024 13:09:38 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id c19-20020a056808139300b003c7523cf984sm1555006oiw.22.2024.05.06.13.09.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 May 2024 13:09:37 -0700 (PDT) Message-ID: <351f140f-8b0f-41d1-b606-dceefe0165f8@ventanamicro.com> Date: Mon, 6 May 2024 14:09:36 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US From: Jeff Law To: "gcc-patches@gcc.gnu.org" Subject: [RISC-V] Fix incorrect if-then-else nesting of Zbs usage in constant synthesis X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org So I managed to goof the if-then-else level of the bseti bits last week. They were supposed to be a last ditch effort to improve the result, but ended up inside a conditional where they don't really belong. I almost always use Zba, Zbb and Zbs together, so it slipped by. So it's NFC if you always test with Zbb and Zbs enabled together. But if you enabled Zbs without Zbb you'd see a failure to use bseti. Planning to commit once pre-commit CI passes. I'm attaching the actual patch (P) and a diff with whitespace ignored (P2) so it's easier to see what actually changed. Jeff diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 6f1c67bf3f7..dddb7f8d673 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -869,8 +869,10 @@ riscv_build_integer_1 (struct riscv_integer_op codes[RISCV_MAX_INTEGER_OPS], codes[1].use_uw = false; cost = 2; } + } + /* Final cases, particularly focused on bseti. */ - else if (cost > 2 && TARGET_ZBS) + if (cost > 2 && TARGET_ZBS) { int i = 0; @@ -914,7 +916,6 @@ riscv_build_integer_1 (struct riscv_integer_op codes[RISCV_MAX_INTEGER_OPS], cost = i; } } - } gcc_assert (cost <= RISCV_MAX_INTEGER_OPS); return cost; diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 6f1c67bf3f7..dddb7f8d673 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -869,50 +869,51 @@ riscv_build_integer_1 (struct riscv_integer_op codes[RISCV_MAX_INTEGER_OPS], codes[1].use_uw = false; cost = 2; } - /* Final cases, particularly focused on bseti. */ - else if (cost > 2 && TARGET_ZBS) - { - int i = 0; + } - /* First handle any bits set by LUI. Be careful of the - SImode sign bit!. */ - if (value & 0x7ffff800) - { - alt_codes[i].code = (i == 0 ? UNKNOWN : IOR); - alt_codes[i].value = value & 0x7ffff800; - alt_codes[i].use_uw = false; - value &= ~0x7ffff800; - i++; - } + /* Final cases, particularly focused on bseti. */ + if (cost > 2 && TARGET_ZBS) + { + int i = 0; - /* Next, any bits we can handle with addi. */ - if (value & 0x7ff) - { - alt_codes[i].code = (i == 0 ? UNKNOWN : PLUS); - alt_codes[i].value = value & 0x7ff; - alt_codes[i].use_uw = false; - value &= ~0x7ff; - i++; - } + /* First handle any bits set by LUI. Be careful of the + SImode sign bit!. */ + if (value & 0x7ffff800) + { + alt_codes[i].code = (i == 0 ? UNKNOWN : IOR); + alt_codes[i].value = value & 0x7ffff800; + alt_codes[i].use_uw = false; + value &= ~0x7ffff800; + i++; + } - /* And any residuals with bseti. */ - while (i < cost && value) - { - HOST_WIDE_INT bit = ctz_hwi (value); - alt_codes[i].code = (i == 0 ? UNKNOWN : IOR); - alt_codes[i].value = 1UL << bit; - alt_codes[i].use_uw = false; - value &= ~(1ULL << bit); - i++; - } + /* Next, any bits we can handle with addi. */ + if (value & 0x7ff) + { + alt_codes[i].code = (i == 0 ? UNKNOWN : PLUS); + alt_codes[i].value = value & 0x7ff; + alt_codes[i].use_uw = false; + value &= ~0x7ff; + i++; + } - /* If LUI+ADDI+BSETI resulted in a more efficient - sequence, then use it. */ - if (i < cost) - { - memcpy (codes, alt_codes, sizeof (alt_codes)); - cost = i; - } + /* And any residuals with bseti. */ + while (i < cost && value) + { + HOST_WIDE_INT bit = ctz_hwi (value); + alt_codes[i].code = (i == 0 ? UNKNOWN : IOR); + alt_codes[i].value = 1UL << bit; + alt_codes[i].use_uw = false; + value &= ~(1ULL << bit); + i++; + } + + /* If LUI+ADDI+BSETI resulted in a more efficient + sequence, then use it. */ + if (i < cost) + { + memcpy (codes, alt_codes, sizeof (alt_codes)); + cost = i; } }