From patchwork Fri May 3 16:51:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1931123 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=IkjN8pA4; 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 4VWH0S6sg1z1ybC for ; Sat, 4 May 2024 02:52:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 241793844742 for ; Fri, 3 May 2024 16:52:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-yw1-x1129.google.com (mail-yw1-x1129.google.com [IPv6:2607:f8b0:4864:20::1129]) by sourceware.org (Postfix) with ESMTPS id EAEE9384AB58 for ; Fri, 3 May 2024 16:52:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EAEE9384AB58 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 EAEE9384AB58 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1129 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714755126; cv=none; b=uGDmfQJm4btF2iv/VYvfeiSZZ/ytYRBmmbHIwL48+V7tF1fCHMtuK/vPMdT9waYfUtKsO3sNDfH26LXP1dW/8K6I6eE+L3/P2TbLW1P9n22D6H8o/jOSx5Wi5CTxiv78kWYN81U69vV8c+PEFj3kq/Ix3ob4lcTBZXdQ7Ml2+OY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714755126; c=relaxed/simple; bh=MmNx3RLOefJUw2KA5trWABvYDamky/YNMPN8KkXNo1A=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=Q3qNUSfGwRp4JAv9maujndqlFRNuCO9jQKrQZirljG1Xk7lDl5gwAHIBovWEdsjVEnGHNfcX1B2NiHvGTuBCXZXhV1mBTIpMhYj3h5OYvNIKYUSDU8hcCCwdDfvLiknWO8/bXOd+f9WLQPJRXnKEOKi+SzTzlPvyKAGOA3k1IdY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-61be4b9869dso52510487b3.1 for ; Fri, 03 May 2024 09:52:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1714755121; x=1715359921; 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=p73zemtX8tW+//WbYWERtKgjmh4CQxTHvmEWMpfUNr8=; b=IkjN8pA4UqHWc2UfFCAf4JSlk1R+UZ/dgRpWXSj9CxCacHyxUZoba6R7QQjjhsws8C TkXifBTK0gpEc9JQ28oNghVmAQuPSiYGuWVngMMIUi+R5Ly9p5DPVLbWDgantUTRnFrj DtvpjFwBXdSrRMF2lEM8CQTwppNlO8e8KYJrZJu0SpBMYvOSVVvzDVePwZGMTDgMlOa4 xl501zE4zBcI8JTyanN5opUV/ok4vLZmISd6dv7wM3JSPaRpnBLOaPa0DKcCfM0lh/BV 8AhzLY7UJch31i/UieRAgq9ZzhJaF47MMaVuLJk6OhjKDN2B8gGNufNKUshf9Kenu0sn f9zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714755121; x=1715359921; 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=p73zemtX8tW+//WbYWERtKgjmh4CQxTHvmEWMpfUNr8=; b=f6oTPyJoxryWt7l+KVJglwN0t7z31IUC5zF+fMoG25SpK12nKAiNyGn9WB4HiYOxFB MwUZuqiJNq6WTs/Jr/l/QLT6w7BnNvNIdA39hu3PRj2V/RIdQEmDFNfN3D5cRudZRRJx 87A3vDcc6ToVBjhAgsaRTdenCJ8cRa3OoZNB0BSnwVNg9OaFHLuQwXwIbuEXZ4OBWKKl Depri/fyiC4Mm9By1zryaAr2CHxWCJdVZUPFotsogQWqz0i9CGe7UA67NEvhc7rnfs0c pHC15l64b8NPy+jYpPn7MNBShjJGkxQRW5hCyZWJXEvSBNmROHWGaUaijTKMQtyfL6q5 P9+g== X-Gm-Message-State: AOJu0Yy6RVYJ+oV7ayMNM7HzqKIduvUVft65t5P8la7eOTkdlqejcSlb g20A8N3M7VKmdvkupHBXTNyQeKBrRaUrUukr9IT8Od6VTiKwi37Vdf9mG8q0dOmARWprAb6yslB k X-Google-Smtp-Source: AGHT+IHyexeNX8BZL+QGsG6Po40FW128VCTIwMGyi959hsE6xhXC4SQQSejoiaWa0E3O689hb2bPtw== X-Received: by 2002:a81:7246:0:b0:615:4e88:c036 with SMTP id n67-20020a817246000000b006154e88c036mr1856539ywc.41.1714755120734; Fri, 03 May 2024 09:52:00 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id t201-20020a0dead2000000b0061beae3ca64sm741258ywe.16.2024.05.03.09.51.59 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 May 2024 09:52:00 -0700 (PDT) Message-ID: <40366b72-9168-468f-a18a-7a64373d8329@ventanamicro.com> Date: Fri, 3 May 2024 10:51:59 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US To: "gcc-patches@gcc.gnu.org" From: Jeff Law Subject: [RFA][RISC-V] Enable inlining str* by default X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, LIKELY_SPAM_BODY, 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 with Chrstoph's patches from late 2022 we've had the ability to inline strlen, and str[n]cmp (scalar). However, we never actually turned this capability on by default! This patch flips the those default to allow inlinining by default. It also fixes one bug exposed by our internal testing when NBYTES is zero for strncmp. I don't think that case happens enough to try and optimize it, we just disable inline expansion for that instance. This has been bootstrapped and regression tested on rv64gc at various times as well as cross tested on rv64gc more times than I can probably count (we've have this patch internally for a while). More importantly, I just successfully tested it on rv64gc and rv32gcv elf configurations with the trunk ;-) OK for the trunk (assuming it passes pre-commit CI)? Jeff [RFA][RISC-V] Enable inlining str* by default So with Chrstoph's patches from late 2022 we've had the ability to inline strlen, and str[n]cmp (scalar). However, we never actually turned this capability on by default! This patch flips the those default to allow inlinining by default. It also fixes one bug exposed by our internal testing when NBYTES is zero for strncmp. I don't think that case happens enough to try and optimize it, we just disable inline expansion for that instance. This has been bootstrapped and regression tested on rv64gc at various times as well as cross tested on rv64gc more times than I can probably count (we've have this patch internally for a while). More importantly, I just successfully tested it on rv64gc and rv32gcv elf configurations with the trunk ;-) OK for the trunk (assuming it passes pre-commit CI)? gcc/ * config/riscv/riscv-string.cc (riscv_expand_strcmp): Do not inline strncmp with zero size. * config/riscv/riscv.opt (var_inline_strcmp): Enable by default. (vriscv_inline_strncmp, riscv_inline_strlen): Likewise. gcc/testsuite * gcc.target/riscv/zbb-strlen-disabled-2.c: Turn off inlining. diff --git a/gcc/config/riscv/riscv-string.cc b/gcc/config/riscv/riscv-string.cc index 36587f983b7..3b1b3bcfd94 100644 --- a/gcc/config/riscv/riscv-string.cc +++ b/gcc/config/riscv/riscv-string.cc @@ -497,6 +497,13 @@ riscv_expand_strcmp (rtx result, rtx src1, rtx src2, return false; nbytes = UINTVAL (bytes_rtx); + /* If NBYTES is zero the result of strncmp will always be zero, + but that would require special casing in the caller. So for + now just don't do an inline expansion. This probably rarely + happens in practice, but it is tested by the testsuite. */ + if (nbytes == 0) + return false; + /* We don't emit parts of a strncmp() call. */ if (nbytes > compare_max) return false; diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index ee824756381..95165e5fa89 100644 --- a/gcc/config/riscv/riscv.opt +++ b/gcc/config/riscv/riscv.opt @@ -515,15 +515,15 @@ Target Var(TARGET_INLINE_SUBWORD_ATOMIC) Init(1) Always inline subword atomic operations. minline-strcmp -Target Var(riscv_inline_strcmp) Init(0) +Target Var(riscv_inline_strcmp) Init(1) Inline strcmp calls if possible. minline-strncmp -Target Var(riscv_inline_strncmp) Init(0) +Target Var(riscv_inline_strncmp) Init(1) Inline strncmp calls if possible. minline-strlen -Target Var(riscv_inline_strlen) Init(0) +Target Var(riscv_inline_strlen) Init(1) Inline strlen calls if possible. -param=riscv-strcmp-inline-limit= diff --git a/gcc/testsuite/gcc.target/riscv/zbb-strlen-disabled-2.c b/gcc/testsuite/gcc.target/riscv/zbb-strlen-disabled-2.c index a481068aa0c..1295aeb0086 100644 --- a/gcc/testsuite/gcc.target/riscv/zbb-strlen-disabled-2.c +++ b/gcc/testsuite/gcc.target/riscv/zbb-strlen-disabled-2.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-march=rv32gc_zbb" { target { rv32 } } } */ -/* { dg-options "-march=rv64gc_zbb" { target { rv64 } } } */ +/* { dg-options "-mno-inline-strlen -march=rv32gc_zbb" { target { rv32 } } } */ +/* { dg-options "-mno-inline-strlen -march=rv64gc_zbb" { target { rv64 } } } */ /* { dg-skip-if "" { *-*-* } { "-O0" "-Os" "-Og" "-Oz" } } */ typedef long unsigned int size_t;