From patchwork Mon Jun 10 13:44:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1945886 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Ko3eprGV; 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 4VyY2R5fMfz20Py for ; Mon, 10 Jun 2024 23:44:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 06B0A3858429 for ; Mon, 10 Jun 2024 13:44:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 39CCA3858CDB for ; Mon, 10 Jun 2024 13:44:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 39CCA3858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 39CCA3858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718027069; cv=none; b=c18bWC+5X3AFfE6iME0lmh8ZA5JZZ0IQdoRBkoE9nl2iwampUsx3DoBY1tcWe4M5GIRQQhlOf4Qns10/jkCbMQhWH0ISK3+D6pWQ1gSis8hUSB5lwO51KnkpKAHgYn/eBLSNDg+DFlAU/Qu03nKeePvNTUQQRGNFuSJj2DmpuC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718027069; c=relaxed/simple; bh=vqTN7ArDggG0yqGx/Q2SV0EqVkd/IZ8RDa63Cy9zHl0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:Subject:To; b=PdGKKOIM66tYG817zAOIqJqaE3Fs4zexOeE1LYO/pYAqJQNYXKy5UaLmu62vJRClRNStLN8Mwv2fyBEiiO8J3mJ+Nh4U4TKIgPJLp53aqk6yiYn2Kh80pEE9FtyQWZvpFXue48jVgTZwJpTbUdd67o4dz7eQpsUgyga679KyqEM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-7042882e741so1340785b3a.2 for ; Mon, 10 Jun 2024 06:44:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718027066; x=1718631866; darn=gcc.gnu.org; h=to:subject:from:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=aWwZWoXFqK81BRhBp1J1Avh/VLW1sx7sbSA4ck+tfVs=; b=Ko3eprGVoWZlBPzBXGiLXI6mIrOtjWHNfMZLYOd+Xcp/dAKQre2BLVUq+pQQXAuRpX hR6Gw7lwp8K9wEqjg5dGZtSmiTKSypFzcAfpTOwj3prmBnG1o0/VlwPzhBc0T289DNDZ qGwqsIMxlvv0VsIUwv1+ZHqvj8/hIWS4Kq3bvAIJ48HODtCKwS1C/ufFD1faqaoNR527 1IAlXka2g5Vx44WexiHIhaiP/NVMMfWWl77ucCvVMqIxa/RaH16NwK2U2cxho1CN9UXt lW32/5AJaoKo8TaKiPHlR9k2QRJ7pzGmaEijDAcRMKyJkOkCNm4zunSjcJRF+p9Hv6Sl kaJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718027066; x=1718631866; h=to:subject:from:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aWwZWoXFqK81BRhBp1J1Avh/VLW1sx7sbSA4ck+tfVs=; b=vEKSFQlbdJLedtypGqY4149UIDkhk+qh8E5ag3bDQyoVVsagETebm9rmAwzZjAuXp1 71NvMGP8/jCmsGl+xJD3D+es2yXLdNhi++cQjTmIjQb1cmnpqYOyPPGkX16VNwlGbju+ uCOfSG4v5xV2G3NLGgDxgm52Xy+JBQrGxrveHvvd1bC3DlOFVEDjQiDEAlpRwxOoYIla q76gfia6fVX99ALFr8hlNFtL1M4wsyv+ru2aFfzz5JKXVBF4/t0R+OiaqZMf/P69MHNV /8eK9dltjiGs/XFhjINjMFu7+tQA2jKUzluAwSrSFbRcKS0e6KYIQbQyh3Mgmu+yFflq Owow== X-Gm-Message-State: AOJu0YxcaKMfS9TW7YfN/yxtRaRfhVHR1ELivQ4U8/BCD9GJZ0VScDGZ b4pY4rfqQPMwF5n1kF2WIvfvJx8uxUsFjHqAWlAN7SgqSp17uambIB5P3Q== X-Google-Smtp-Source: AGHT+IF5ebsVHb74GtJvVfMvroxjHCrHrO3eXucAByz+z7kft1YX6GzGmaVcBFfLTxzWspVyF2lznw== X-Received: by 2002:a05:6a00:982:b0:6f3:e9bc:7ed5 with SMTP id d2e1a72fcca58-7040c5fee9fmr10465045b3a.4.1718027065461; Mon, 10 Jun 2024 06:44:25 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70420fdaa28sm4319715b3a.143.2024.06.10.06.44.24 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 Jun 2024 06:44:24 -0700 (PDT) Message-ID: Date: Mon, 10 Jun 2024 07:44:20 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US From: Jeff Law Subject: [to-be-committed][RISC-V] Generate bclr more often for rv64 To: "gcc-patches@gcc.gnu.org" X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, 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 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 Another of Raphael's patches to improve our ability to safely generate a Zbs instruction, bclr in this instance. In this case we have something like ~(1 << N) & C where N is variable, but C is a constant. If C has 33 or more leading zeros, then no matter what bit we clear via bclr, the result will always have at least bits 31..63 clear. So we don't have to worry about any of the extension issues with SI objects in rv64. Odds are this was seen in spec at some point by the RAU team, thus leading to Raphael's pattern. Anyway, this has been through Ventana's CI system in the past. I'll wait for it to work through upstream pre-commit CI before taking further action, but the plan is to commit after successful CI run. Jeff gcc/ * config/riscv/bitmanip.md ((~1 << N) & C): New splitter. gcc/testsuite/ * gcc.target/riscv/zbs-ext.c: New test. diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index 6559d4d6950..4361be1c265 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -784,6 +784,23 @@ (define_insn_and_split "*bclridisi_nottwobits" } [(set_attr "type" "bitmanip")]) +;; An outer AND with a constant where bits 31..63 are 0 can be seen as +;; a virtual zero extension from 31 to 64 bits. +(define_split + [(set (match_operand:DI 0 "register_operand") + (and:DI (not:DI (subreg:DI + (ashift:SI (const_int 1) + (match_operand:QI 1 "register_operand")) 0)) + (match_operand:DI 2 "arith_operand"))) + (clobber (match_operand:DI 3 "register_operand"))] + "TARGET_64BIT && TARGET_ZBS + && clz_hwi (INTVAL (operands[2])) >= 33" + [(set (match_dup 3) + (match_dup 2)) + (set (match_dup 0) + (and:DI (rotate:DI (const_int -2) (match_dup 1)) + (match_dup 3)))]) + (define_insn "*binv" [(set (match_operand:X 0 "register_operand" "=r") (xor:X (ashift:X (const_int 1) diff --git a/gcc/testsuite/gcc.target/riscv/zbs-ext.c b/gcc/testsuite/gcc.target/riscv/zbs-ext.c new file mode 100644 index 00000000000..65f42545b5f --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zbs-ext.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zbs -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-O1" } } */ +typedef unsigned long uint64_t; +typedef unsigned int uint32_t; + +uint64_t bclr (const uint32_t i) +{ + uint64_t checks = 10; + checks &= ~(1U << i); + return checks; +} + +/* { dg-final { scan-assembler-times "bclr\t" 1 } } */ +/* { dg-final { scan-assembler-not "sllw\t"} } */