From patchwork Thu Oct 12 18:40:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 152117 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1429296vqb; Thu, 12 Oct 2023 11:41:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHBjiY/GVFS1dF330os749iadnhw6YzTyEMTPG6jSe4+e84dHsl3MMn4exPIlPErMI4iedw X-Received: by 2002:a05:620a:2a11:b0:776:cf78:905a with SMTP id o17-20020a05620a2a1100b00776cf78905amr25215064qkp.50.1697136063046; Thu, 12 Oct 2023 11:41:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697136063; cv=none; d=google.com; s=arc-20160816; b=phbWW5zWsPgbBINqUMQQBjOH2EzwTC8GYlDBbFpTnliOYjuWEgfz09oExxY3G6+I9j aDLW0Elv5UtgToQ+gp2KI6z5I20g0DFxM3Duq00d8g+NHX+e0u9xrU2vZuc7OE20S5uH R87/QNTt70UaVy0bnf9NXyRu+NfU7e2VvQssb16quYlzGwsrnx1TX7TMmm9+O7nYwZpZ yoyDtXdSQsfVnfcqNn2rl1Shr8AgqOFjib7e/Kq2IYPZXT9xaJN7ieuXrJuVpZKS7wGc /7GIttEP+1N/2Iic0D4DtKozgzycTtq9n38we3FMjPvZKZGFXKpcT2h4ZijiHbLPj2ZG 7IzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=kQDbCTXbIDQDCgxBRPQHKa+uMI7oB/yIZyoeKbSjkgw=; fh=kbV0NOqiTuorklH6HBA9bfclLeeDA0ay8K7s4dUrk/A=; b=gkJWsCtHfbDk8UVud0YUsPchKQq93MBzaez1sQE5Feh20V3pnaO7z2lkwhFmkVP4ii 3a0r1kGlmm2Pxi9oZZOgGTTyxN3vYPlkHoPpR+HEymmIyFMTPuhxMm20YGBf5BaUcud3 4wehpCXPneFw2WI4+w2FuvhXq/vwW9Q4wSICH2dD8bF+yx8yZeBRDylwMsef4UReRFoH DzVYjyWuoOTQtCoMbzo6LCYUxHYeLwwZ1743f+zWDgCYPFC1DY1FQd83GwA8Dqm/wAeO WCEg2EbzchAxm+ckV9puhTIqIoY8FgrpOF5GrrIpynhJh1JqxWHEUT+ukKpvklbc+HGV rGoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=MoWlalj5; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id m8-20020a05620a290800b00774252f79f7si11474830qkp.306.2023.10.12.11.41.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 11:41:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=MoWlalj5; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C8A19385841B for ; Thu, 12 Oct 2023 18:41:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id A88FD3858C5E for ; Thu, 12 Oct 2023 18:40:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A88FD3858C5E Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1c9d7a98abbso11143275ad.1 for ; Thu, 12 Oct 2023 11:40:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1697136036; x=1697740836; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=kQDbCTXbIDQDCgxBRPQHKa+uMI7oB/yIZyoeKbSjkgw=; b=MoWlalj5y62WTZUMdbhCXVVS9Bir+UvUj0tA7LCg31Q11RE1xBZ/TbDG2rDq32V65z j59RtlA6iZvuH18quPxrSf4N8OEfCt3+wAZ1ZUCADqNaPgEpcYxHN4jf28LPQGhhBNkt xTIe/JOZeDip0YzOP2yRT7e3ciluZcvGAVdJJgZ8H38c1WBdKcEeK4EN115NmF+6aat3 w33tYGzNSwleb7gjz+5nNMBdMNbOAAJQkwy/wDvKu9QMm53hoJgpestS+ZHL57aa3vR6 tWu6Sxl8f7efEd/dSqhmcD4bA2tK6p470ie6nOUUZKdrgFTryGJAOel8BBdXZVa6BZdm c7Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697136036; x=1697740836; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kQDbCTXbIDQDCgxBRPQHKa+uMI7oB/yIZyoeKbSjkgw=; b=a8bDyZSsQB8OThSL5EiSSzUOoOOcSpXyub+U2uBcVJ6ck2TJtLoLZq5ui3Al8R7ZAm inaoTaQ6GfS3Jo4Sjm1DjQfBxKImSmHR90uR7V1Pu6IBCBT0zTMM4a7BDA0mzCyAXB50 3SWr3SPjzhdhtnLnrCqnmY5V6dfPjy46J/Ij1uE1wN6g68T79t7fyEGeduFi2LJQAwd/ mjaM72S58Ok/vakPPtFFPXhy9RbveQ4AZDe1WwA3bTfnFPp/b6BU2uM/qEHXMMrgy8Sa HZWf3jgtmfmaEBK/HrFpv+87w3zV0V3ivtaOnXIc2QGsnq39+Ttb0k1LBd32LQN+in/d R6VA== X-Gm-Message-State: AOJu0YxmmSqxEQGw1gS162MKOTqWQ1CGmPxEzlh5DuR2Svjd2+ZycfAX yhFTw2WfD3kp5RVDas3TTjGJK9lFqL/sch9d6WdsS9vk8x+clFv1YevWR7bmMgetLA2GuQl2d0X aGNKWDfpUTwM6KJKSjynwf07ekfa+vU3xbtfq1SYop4VOLEGHPJnug4t7gtJp10FcWCtK/LiOBR aVnlLAAg== X-Received: by 2002:a17:902:d50f:b0:1c3:bc2a:f6b4 with SMTP id b15-20020a170902d50f00b001c3bc2af6b4mr27097981plg.42.1697136035920; Thu, 12 Oct 2023 11:40:35 -0700 (PDT) Received: from SiX1E.. ([12.199.206.21]) by smtp.gmail.com with ESMTPSA id w8-20020a170902d70800b001c9b2e66795sm2349298ply.85.2023.10.12.11.40.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 11:40:35 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, palmer@dabbelt.com, jeffreyalaw@gmail.com, rdapp@ventanamicro.com, juzhe.zhong@rivai.ai Cc: Kito Cheng Subject: [PATCH v2] RISC-V: Fix the riscv_legitimize_poly_move issue on targets where the minimal VLEN exceeds 512. Date: Thu, 12 Oct 2023 11:40:29 -0700 Message-Id: <20231012184029.21114-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779576144653781820 X-GMAIL-MSGID: 1779576144653781820 riscv_legitimize_poly_move was expected to ensure the poly value is at most 32 times smaller than the minimal VLEN (32 being derived from '4096 / 128'). This assumption held when our mode modeling was not so precisely defined. However, now that we have modeled the mode size according to the correct minimal VLEN info, the size difference between different RVV modes can be up to 64 times. For instance, comparing RVVMF64BI and RVVMF1BI, the sizes are [1, 1] versus [64, 64] respectively. gcc/ChangeLog: * config/riscv/riscv.cc (riscv_legitimize_poly_move): Bump max_power to 64. gcc/testsuite/ChangeLog: * g++.target/riscv/rvv/autovec/bug-01.C: New. * g++.target/riscv/rvv/rvv.exp: Add autovec folder. --- gcc/config/riscv/riscv.cc | 5 ++- gcc/config/riscv/riscv.h | 5 +++ .../g++.target/riscv/rvv/autovec/bug-01.C | 33 +++++++++++++++++++ gcc/testsuite/g++.target/riscv/rvv/rvv.exp | 3 ++ 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.target/riscv/rvv/autovec/bug-01.C diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 739fc77e785..d43bc765ce7 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -2411,9 +2411,8 @@ riscv_legitimize_poly_move (machine_mode mode, rtx dest, rtx tmp, rtx src) } else { - /* FIXME: We currently DON'T support TARGET_MIN_VLEN > 4096. */ - int max_power = exact_log2 (4096 / 128); - for (int i = 0; i < max_power; i++) + int max_power = exact_log2 (MAX_POLY_VARIANT); + for (int i = 0; i <= max_power; i++) { int possible_div_factor = 1 << i; if (factor % (vlenb / possible_div_factor) == 0) diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h index 4b8d57509fb..3d2723f5339 100644 --- a/gcc/config/riscv/riscv.h +++ b/gcc/config/riscv/riscv.h @@ -1197,4 +1197,9 @@ extern void riscv_remove_unneeded_save_restore_calls (void); #define OPTIMIZE_MODE_SWITCHING(ENTITY) (TARGET_VECTOR) #define NUM_MODES_FOR_MODE_SWITCHING {VXRM_MODE_NONE, riscv_vector::FRM_NONE} + +/* The size difference between different RVV modes can be up to 64 times. + e.g. RVVMF64BI vs RVVMF1BI on zvl512b, which is [1, 1] vs [64, 64]. */ +#define MAX_POLY_VARIANT 64 + #endif /* ! GCC_RISCV_H */ diff --git a/gcc/testsuite/g++.target/riscv/rvv/autovec/bug-01.C b/gcc/testsuite/g++.target/riscv/rvv/autovec/bug-01.C new file mode 100644 index 00000000000..fd10009ddbe --- /dev/null +++ b/gcc/testsuite/g++.target/riscv/rvv/autovec/bug-01.C @@ -0,0 +1,33 @@ +/* { dg-options "-march=rv64gcv_zvl512b -mabi=lp64d -O3" } */ + +class c { +public: + int e(); + void j(); +}; +float *d; +class k { + int f; + +public: + k(int m) : f(m) {} + float g; + float h; + void n(int m) { + for (int i; i < m; i++) { + d[0] = d[1] = d[2] = g; + d[3] = h; + d += f; + } + } +}; +c l; +void o() { + int b = l.e(); + k a(b); + for (;;) + if (b == 4) { + l.j(); + a.n(2); + } +} diff --git a/gcc/testsuite/g++.target/riscv/rvv/rvv.exp b/gcc/testsuite/g++.target/riscv/rvv/rvv.exp index 249530580d7..c30d6e93144 100644 --- a/gcc/testsuite/g++.target/riscv/rvv/rvv.exp +++ b/gcc/testsuite/g++.target/riscv/rvv/rvv.exp @@ -40,5 +40,8 @@ set CFLAGS "-march=$gcc_march -O3" dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/base/*.C]] \ "" $CFLAGS +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/autovec/*.\[C\]]] \ + "" $CFLAGS + # All done. dg-finish