From patchwork Tue May 7 04:30:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1932218 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=H1FKzPUh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4VYQLl1stYz1ymg for ; Tue, 7 May 2024 14:30:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 63D1D3858429 for ; Tue, 7 May 2024 04:30:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) by sourceware.org (Postfix) with ESMTPS id 64A113858D1E for ; Tue, 7 May 2024 04:30:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 64A113858D1E 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 64A113858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::22a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715056218; cv=none; b=tqX2Rojnr3F+UlgnSG2FX6Pa6ZU/sMslQJDQ5F5jg8qU0Swyz0P9qMbfa4Fu2BngXPAGKh+WLInjRsUn7W4seNrS7yOcJ39fE8lIq/S/fMULGn0KxUpdi1W0M3PplcSqNe2YvciSVhggFTd/sq+9szVgj9/wNXbeMT8gdaoBkE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715056218; c=relaxed/simple; bh=qkGESQBaDgu/cV++OROL8gxnmkwTaB1E/A/skuypKTQ=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=tMxWt1p0W2U+igE/N9apa3z2yvlhf3MNSYkx/H8S3vWuhxU/wDiNGZfI/PK686XijgtsNGkfvatg7R5BdMhtJfvcA3Ouxhhrxou5zOncXunLjetX05pJ2toTAUOKnHOprDM2o/x9oKkGPxPvwwWcGPe8F4k1DHDyaCxORT0mAkQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-3c97dab75bbso36028b6e.0 for ; Mon, 06 May 2024 21:30:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1715056215; x=1715661015; darn=gcc.gnu.org; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=oUrKo/88J/gV2SfmsCmPdPHe2m5+gIfeAPIUwd/XtgM=; b=H1FKzPUh8///PSTHw0NfT7BpzYO9N5bcQnHPZG8ddYBPJaLW36I/xENUzank8B+Anq cZjpwAlo9baWPJBOqWdoPuMEe5CyFapt3rkFHf+fcJwPS+LnomNuswRRANmsolvaB2W4 CWAeFoJtwrHGk3yXEexYnhjQHbHLZSA/RnsCyNBOLcHLoIZsSpmPpBwByU4XXFn8IhSl 5C0JnGmab2ALCketOv3bwGqAIh8snfoSMhmpdWjVqCIbVglyQTvLOixMQ7rHCAsb2l3Y nri8X23ZqK83IHBa7dt/xQ3tSp8D+e5l/idZT2UJ7J8Mq6Y47u5C1mD/dZdQkxD3gKwi FahA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715056215; x=1715661015; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oUrKo/88J/gV2SfmsCmPdPHe2m5+gIfeAPIUwd/XtgM=; b=aqx0epjLcMs3D36JaooYTTV8MPjNdRAG9+6T6GtC+v9GI7Tk/B24vqUG7PzpYZS1dD dDVVlgZ/QBRLthwQVifbM1ZqXw7VgH7OGnuVsYxCPcC/Z+xxL4M1U5HLwFsdUGrFVOKx gJexywTqIpRrRU00qaSSuVfSdcoaQWiFf613tNUl7mpAzd9Y3ljPRNDN8MkcOcQn0myi GyBk6ns4w9k7VoOR4D/blb/0nORBohb51SPSH3BWTCOiaDkWPehrd+j49+lKQjTSxMY6 tDFEdUHP5bf1vTwTJDZomk1C8iFRp7xs4TwFgmSjmSGkGTxfqeVABc1sHK9MrC3JiNfm u0/Q== X-Gm-Message-State: AOJu0Yy/AqFkbNeG47dlk8krdWbvbndxVSUHqKQ9EmD3VIZWFjuVod10 LCFpFeGJpn71HKD/7kLYMwXSo6AaSQpcWRxDUrGHb4Y1S/ovUj8nRTj+hweMjJEhQw5M4/by5rf e X-Google-Smtp-Source: AGHT+IHL1BnXHqUhCfhekCq2nAkZN5FAz647SHGra5yB/J15Jam0NWyB6l/YkEkmamCwMZUXU758lw== X-Received: by 2002:a05:6808:152b:b0:3c5:f62a:435 with SMTP id u43-20020a056808152b00b003c5f62a0435mr15838805oiw.48.1715056215167; Mon, 06 May 2024 21:30:15 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id h15-20020a056808014f00b003c966fb7876sm910590oie.54.2024.05.06.21.30.14 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 May 2024 21:30:14 -0700 (PDT) Message-ID: <59224523-8af7-4b2a-94b1-e24645337313@ventanamicro.com> Date: Mon, 6 May 2024 22:30:13 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US To: "gcc-patches@gcc.gnu.org" From: Jeff Law Subject: [RISC-V][V2] 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 Reposting without the patch that ignores whitespace. The CI system doesn't like including both patches, that'll generate a failure to apply and none of the tests actually get run. 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. 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,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; } }