From patchwork Sat Jun 29 12:48:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1954245 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=JlIOXJsq; 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 4WBBtm64Hgz20Xp for ; Sat, 29 Jun 2024 22:48:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6887C381776D for ; Sat, 29 Jun 2024 12:48:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by sourceware.org (Postfix) with ESMTPS id 3259D3899097 for ; Sat, 29 Jun 2024 12:48:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3259D3899097 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 3259D3899097 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4860:4864:20::33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719665289; cv=none; b=bzL8NYP3eDVdVzrNrLzfTGMxYydxBCDBmtYagpIL8Xenb9Thp0wT2R0YOhaeBP5TjggmbXN3LiEnHs49vdwP/DdLgtq/s6M0265+XhK9LawWWRgUddzR07/4fmPkgfEVTQx7cxZxVhNkBnf0Mc5hljNVL6i0rIJ4VjQiRvB+aBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719665289; c=relaxed/simple; bh=eY/Mc2yyrq0dEWG9Rlh8t9NyNtg/5ooH35vpSJkqA4c=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=ZnSwuodSxu0YDOLF0SfYeS/HUuMlRg3qPQvx6DHRFF8Jx/aCQC29NquWpBiycs4UGgKVa6/Elg9wdEUgPnM1pSNjIJVLvMBwnI9sPmjsN43Iqh3A/e3n1GUZbMqcza6c6JHOpzGzPGcKvTGQKfn8CvKC3558ZVSFJ/D+zFAOVTk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-25c4d8ae511so738458fac.2 for ; Sat, 29 Jun 2024 05:48:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719665285; x=1720270085; 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=KbvA/TrGgqCpPwWgy936lXBerVffVyLmmih6ijc2A6o=; b=JlIOXJsqxsOiy5qVxO6YyfgSY2M2PRaGooUBWzWq42mjPP+bhy6OoN1qppoAV4NU1X X498UDGndNcCpA/kvbj81ksCeMNv5YCgcyjfGiUAJNFosmw8SMaGMX/kCi/ayMZTzd+u /JpUhldm3pmkPMSFmbueU+IQrMiAjVNegNFn4F9UTlvfycoTRWOU6BFWT7rb8OL3iHis RUOeQYh7GHEK9dwbz90Rnz0shBOu19nugstMM8qw+Y/lGlTBSJMxQwNrA1zXdAjfJUbE sviG70Cyq+lsICadt9ow4144NYW4OtmGk7AR4D+fqR5gig/7SxL+kLz0RfL/t0/7IjLE Zslg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719665285; x=1720270085; 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=KbvA/TrGgqCpPwWgy936lXBerVffVyLmmih6ijc2A6o=; b=tWIFXvpioBctOB2c3vjWuNy8oNi7XslgWoM3E4R3ASxqZO9jrW2IqCLQk6o5YaAq+3 92Tyo8Ve712I7h4aOp2lI0R/VgZpHdoMPv8RjT/StL5m+evjSygxOnwBAwI2UuAOLgAr 3CPwWzMsT/Q41OLK4kvi2tU4jHUM9GyDQbrCx9ybCa9DS/RcoZJOqf8i6lSPAYq/1yY5 IlCyM1HBiqdeC+vu6WS28ECnPV77+0GlNXVYopChF0nPAR4BqIU5bD3Xfvjcg1pUTLhJ hpwrQVy3L2MkMzUAKMUTjINyvVeD0Xkwk5/6Z7rr+86Jwd/h85Gq7wW0qT9//DRuIu+1 ChwA== X-Gm-Message-State: AOJu0YwxJ5ZsAJEI+oalvfE1/INzzJj0HEzb0a/sWgQ2p/jwQ3Roc4no 0WH0xMH1WNgQeQ6R8dQ1/Ka8u/lAVYiXwhVCeJijrUscgW8OxnyAr3AGAw== X-Google-Smtp-Source: AGHT+IErCOPGmcqDuz7tF5Dr+mYvBUzvTN1fSwLcYZwyEuT/qjyKyv1r1aJC4asN26Zx67iCKrjtbw== X-Received: by 2002:a05:6870:514:b0:254:aada:cc8b with SMTP id 586e51a60fabf-25db3494dffmr657514fac.31.1719665285212; Sat, 29 Jun 2024 05:48:05 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-25d8e234b66sm894092fac.30.2024.06.29.05.48.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 29 Jun 2024 05:48:04 -0700 (PDT) Message-ID: <6c580a19-cc64-4915-b7e7-fd1ab972ddd7@gmail.com> Date: Sat, 29 Jun 2024 06:48:03 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US To: "gcc-patches@gcc.gnu.org" From: Jeff Law Subject: [to-be-committed][RISC-V][V4] movmem for RISCV with V extension X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, 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 I hadn't updated my repo on the host where I handle email, so it picked up the older version of this patch without the testsuite fix. So, V4 with the testsuite option for lmul fixed. --- And Sergei's movmem patch. Just trivial testsuite adjustment for an option name change and a whitespace fix from me. I've spun this in my tester for rv32 and rv64. I'll wait for pre-commit CI before taking further action. Just a reminder, this patch is designed to handle the case where we can issue a single vector load/store which avoids all the complexities of determining which direction to copy. -- gcc/ChangeLog * config/riscv/riscv.md (movmem): New expander. gcc/testsuite/ChangeLog PR target/112109 * gcc.target/riscv/rvv/base/movmem-1.c: New test gcc/ChangeLog * config/riscv/riscv.md (movmem): New expander. gcc/testsuite/ChangeLog PR target/112109 * gcc.target/riscv/rvv/base/movmem-1.c: New test --- gcc/config/riscv/riscv.md | 22 +++++++ .../gcc.target/riscv/rvv/base/movmem-1.c | 60 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/movmem-1.c diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index ff37125e3f2..c0c960353eb 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -2723,6 +2723,28 @@ (define_expand "setmem" FAIL; }) +;; Inlining general memmove is a pessimisation: we can't avoid having to decide +;; which direction to go at runtime, which is costly in instruction count +;; however for situations where the entire move fits in one vector operation +;; we can do all reads before doing any writes so we don't have to worry +;; so generate the inline vector code in such situations +;; nb. prefer scalar path for tiny memmoves. +(define_expand "movmem" + [(parallel [(set (match_operand:BLK 0 "general_operand") + (match_operand:BLK 1 "general_operand")) + (use (match_operand:P 2 "const_int_operand")) + (use (match_operand:SI 3 "const_int_operand"))])] + "TARGET_VECTOR" +{ + if ((INTVAL (operands[2]) >= TARGET_MIN_VLEN / 8) + && (INTVAL (operands[2]) <= TARGET_MIN_VLEN) + && riscv_vector::expand_block_move (operands[0], operands[1], + operands[2])) + DONE; + else + FAIL; +}) + ;; Expand in-line code to clear the instruction cache between operand[0] and ;; operand[1]. (define_expand "clear_cache" diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/movmem-1.c b/gcc/testsuite/gcc.target/riscv/rvv/base/movmem-1.c new file mode 100644 index 00000000000..d9d4a70a392 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/movmem-1.c @@ -0,0 +1,60 @@ +/* { dg-do compile } */ +/* { dg-add-options riscv_v } */ +/* { dg-additional-options "-O3 -mrvv-max-lmul=dynamic" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +#define MIN_VECTOR_BYTES (__riscv_v_min_vlen / 8) + +/* Tiny memmoves should not be vectorised. +** f1: +** li\s+a2,\d+ +** tail\s+memmove +*/ +char * +f1 (char *a, char const *b) +{ + return __builtin_memmove (a, b, MIN_VECTOR_BYTES - 1); +} + +/* Vectorise+inline minimum vector register width with LMUL=1 +** f2: +** ( +** vsetivli\s+zero,16,e8,m1,ta,ma +** | +** li\s+[ta][0-7],\d+ +** vsetvli\s+zero,[ta][0-7],e8,m1,ta,ma +** ) +** vle8\.v\s+v\d+,0\(a1\) +** vse8\.v\s+v\d+,0\(a0\) +** ret +*/ +char * +f2 (char *a, char const *b) +{ + return __builtin_memmove (a, b, MIN_VECTOR_BYTES); +} + +/* Vectorise+inline up to LMUL=8 +** f3: +** li\s+[ta][0-7],\d+ +** vsetvli\s+zero,[ta][0-7],e8,m8,ta,ma +** vle8\.v\s+v\d+,0\(a1\) +** vse8\.v\s+v\d+,0\(a0\) +** ret +*/ +char * +f3 (char *a, char const *b) +{ + return __builtin_memmove (a, b, MIN_VECTOR_BYTES * 8); +} + +/* Don't vectorise if the move is too large for one operation +** f4: +** li\s+a2,\d+ +** tail\s+memmove +*/ +char * +f4 (char *a, char const *b) +{ + return __builtin_memmove (a, b, MIN_VECTOR_BYTES * 8 + 1); +}