From patchwork Tue Dec 19 09:53:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Lewis X-Patchwork-Id: 82442 X-Patchwork-Delegate: jlaw@ventanamicro.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9CA8B385E018 for ; Tue, 19 Dec 2023 09:54:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id D66FA3858439 for ; Tue, 19 Dec 2023 09:53:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D66FA3858439 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D66FA3858439 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702979634; cv=none; b=l3oRlp6zNGuRzW5pLUtRpremuwWLFBpH/rP46XpQE7I6RyPxLwLQWH280Lz6UDwe2KMUs2EwCAa9sVB59G3Tc2ZjgX0PToDhPohjdu1vgiRdF+DCOSFSA12KnAiYOcfw8qIENFf2qQ0NF8fFIZtW8SkJHG7zMPVu+6tUI88uc6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702979634; c=relaxed/simple; bh=AzmlhSvYWgVR6k748R1nfJl8Uj8eb8o49vjFI0kVdVk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=JAjlzaZDjJ5r3PPAIkPRKolkDb6aaQBEtCkbTmh5KWeWGV4E6hn1lgrNjU5MVgsIxGWd7/AwJ71B7z817oBqY0uJLNCbNM6wAVtg5k8Cpc1+BjxvOIpn1XNUZ5NinZh5mSTM/X171SzDGUZnvIdAM3KXTEDX0Cl55WrvaOGkqwI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-33664b4e038so2302864f8f.3 for ; Tue, 19 Dec 2023 01:53:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1702979631; x=1703584431; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=0QiLqOW6hhzpOcupW89dRnkLpt88za/TgK25dLcOyBY=; b=c53gS7TbXU24rYYKR8vaaFHdTZ0IaV/mRwCSeDFOorv6Bb0zUB6HiYvPL+Qe6ZSpqG AcfERc9FPN9FzU1LiVwCtkumuiTvgD5lLQfEhbcjTESrqCYGkb0u9oUMD3viFh05aPew VbXi0CeNMw9t0UTSMmNg/9GibV9PqaeA7Kpjb8ky1UP/noywtY9j6cUvWxUpnfqvOTYQ a2nCQdtfjjHMHzdOLAGRDXgzn44+AeHiPKvq5gik89uZPAeBiuQwA2M2gSKc8xP2VniJ 8Kb1czgTNDYdjlDgbAPIBYOaacjgVVtH+6yEnv/DXOqaVi4WcbNaQYmjgh1VYCbMRf3p oMOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702979631; x=1703584431; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0QiLqOW6hhzpOcupW89dRnkLpt88za/TgK25dLcOyBY=; b=aLC8qCw9Bm/CQ15KoJsUz57vSpsq7UmYAHKxfCPSq5Z7RyOIYIapIIN+0OT0a7Lbfy OT2PZPyueqRwEW/4j43+3z1V3Ns2uyDqz1JtCv+w2cwjdTkljJz9zqzomeDnaimwpMbt Pe7gaVoC3xiZNGDIS4/izdcfpjqj2quUl78ZqColgdFrXddHiFULxaLvswRdZLD8XYnV ZzuXwkdbGgHjrA76VekVOn8jQW5nx/kebiLyaanpBcelMPIQGfF6V9CouJVccbpbFDur kwe5bpRzwocgueBLnkv8njqGVuA6Ms6QWkcL5KK9K29yI9yh3NW4ZzYYzKOd/nrZpaWA s4ng== X-Gm-Message-State: AOJu0YznSnvDNMIDaAsIXtQjZqzhU7rzXk7Xr+DvzAukdpVgudk2nbtB JwVjtWhXqWnxjk6VTC3E2+/g4+Pgfqor1FBh6O1Jvg== X-Google-Smtp-Source: AGHT+IHYMnACi/YwzsdyacI6zBDujIjoYGJ0cAlhLtdl9lrS6eyzhHQg+wz6au7BTWiHTjtB1MWQ9w== X-Received: by 2002:a05:600c:1395:b0:40c:6e33:e212 with SMTP id u21-20020a05600c139500b0040c6e33e212mr3130872wmf.67.1702979630241; Tue, 19 Dec 2023 01:53:50 -0800 (PST) Received: from slewis-laptop.ba.rivosinc.com ([51.52.155.69]) by smtp.gmail.com with ESMTPSA id q19-20020a05600c46d300b0040b632f31d2sm2079985wmo.5.2023.12.19.01.53.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 01:53:49 -0800 (PST) From: Sergei Lewis To: gcc-patches@gcc.gnu.org Subject: [PATCH v2 1/3] RISC-V: movmem for RISCV with V extension Date: Tue, 19 Dec 2023 09:53:46 +0000 Message-Id: <20231219095348.356551-2-slewis@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231219095348.356551-1-slewis@rivosinc.com> References: <20231219095348.356551-1-slewis@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, 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+patchwork=sourceware.org@gcc.gnu.org gcc/ChangeLog * config/riscv/riscv.md (movmem): Use riscv_vector::expand_block_move, if and only if we know the entire operation can be performed using one vector load followed by one vector store 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 ee8b71c22aa..1b3f66fd15c 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -2365,6 +2365,28 @@ 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..0ecc3f7e3b7 --- /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 --param=riscv-autovec-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); +}