From patchwork Thu Sep 14 08:03:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "juzhe.zhong@rivai.ai" X-Patchwork-Id: 139428 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp185549vqi; Thu, 14 Sep 2023 01:04:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbm+d1Vpikx6nh/TYcFLS6q5t8NVdkKXVu7oICoKxoNThOyR1nWG0lzzfOceglW9qjZziE X-Received: by 2002:a17:906:8a7b:b0:9a1:c9c5:5fa1 with SMTP id hy27-20020a1709068a7b00b009a1c9c55fa1mr4088752ejc.4.1694678651428; Thu, 14 Sep 2023 01:04:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694678651; cv=none; d=google.com; s=arc-20160816; b=Hus2dm3t49/4CWMI+f1OJ24Sqo44tQ4QL1Jo7IGU1lfAZm6Q4Vamya/dpci36mwHWi UFMD5QZ++xlrGl6WjXAm3NDc2BCKxJ6qOfQfoEVxqpqWC03QVR2EvQ0uSJKq4o1jpSaD 64HoLXHzF4amzCjnXIEQ/8xGHo2YcLpinCQxDXUTL+LxY12tOlpkHnNJoxMqS1UG3g7J uNnIrg76qTOtARkuDje+v/Xq1cqjZvQWmUjBQST6xjBes+VcFfvWPPLrKbOkBI5tW0Kj QAGII9tZvuA3FwEuyw/+9aYJJ0ZQyXzhh1lJxfW91FM0W4sVdfshhgEtTbEL3+0BAj8V 03/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:feedback-id :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dmarc-filter:delivered-to; bh=X4BW6v8Rn2HYHm4WhkQBzgTN0zvsnSjw6Nml0tLnVfU=; fh=12MRPJmZ1mgDpHqWoogMKqnaGRGM2b7lcuJroqfjJiw=; b=CBmVpZAo0m7oghgC7tnhP1bE/8T6+6ql3cVrTWjeE4E3Whwmubke/Rxnriqa92i8xD lC5cwUsaSiXVcF5EANEosi4Dm4gbz/5fsdEB2xXTWm/1I7fMGN5KEXRGaRZFECzKjC3f 6+FI2/Ya8w1+fhdTSKjzrdydWgEIAXriQ2uEYEW6MCytLpbNTLfahM/0Vx+NGCBcePAA 2C5NqH12yOGnseiPG11J/WzEHLHESCERBhH9grfUW1vEZuYr9E2WhWws9SPYjkX9w6M7 iK7zhJqaj3va1e0cN0SOl5pu8P8oDqejD6CWYWpoeSGdSMScgm2WPKn76poaDi8Q9Czo QeiQ== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j22-20020a170906255600b009926007b7dasi884461ejb.126.2023.09.14.01.04.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 01:04:11 -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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C761B385697F for ; Thu, 14 Sep 2023 08:04:04 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbguseast1.qq.com (smtpbguseast1.qq.com [54.204.34.129]) by sourceware.org (Postfix) with ESMTPS id F23C03858CDA for ; Thu, 14 Sep 2023 08:03:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F23C03858CDA Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai X-QQ-mid: bizesmtp86t1694678604tvi24dby Received: from rios-cad121.hadoop.rioslab.org ( [58.60.1.9]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 14 Sep 2023 16:03:22 +0800 (CST) X-QQ-SSF: 01400000000000G0V000000A0000000 X-QQ-FEAT: +oIWmpEafD/G5QSFq2vqXlEzGTWYEmrPfAUPg0Eq1TkUtepmlGURhGIa4Ka/1 lm3LRyY07LSl9kU47vniE6qeD7W2830JfNJ/datheYnjfiruf9aD/kkq4VSytMRByZeXZnx TPZwGRquYOdwMETdpy+R2MB1hOEEzOx3r+a+yBlQ0iQX1DutsEf6GUaaYxeoIXI5ORbLsn+ YC3xO24lgyuVAv6IqMWoD9Z5fz8U5V15GD8JacPPr7YvncOzIkpoFO3UE2vxwkUvQH2jWs+ r+slAA/aQUd0mOYXOanB0fNNY9S9lVwMeG7o1976I6qhmgvgl2MNaJKfU9HmPENq6RB9vDY h06952xbo/BrBj7cf18QwFB/McXIgD42KEAIFUEuTIiLB+kA1FAWYes2Y88UAZg1roWSimM X-QQ-GoodBg: 2 X-BIZMAIL-ID: 15221922663433965525 From: Juzhe-Zhong To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, kito.cheng@sifive.com, jeffreyalaw@gmail.com, rdapp.gcc@gmail.com, Juzhe-Zhong Subject: [PATCH V3] RISC-V: Expand VLS mode to scalar mode move[PR111391] Date: Thu, 14 Sep 2023 16:03:21 +0800 Message-Id: <20230914080321.3234794-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.3 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz7a-one-0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, 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 Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776999361921065848 X-GMAIL-MSGID: 1776999361921065848 This patch fixes https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111391 I notice that previous patch (V2 patch) cause additional execution fail of pr69719.c This FAIL is because of the latent BUG of VSETVL PASS. So this patch includes VSETVL PASS fix even though it's not related to the PR111391. I have confirm the whole regression no additional FAILs are introduced. PR target/111391 gcc/ChangeLog: * config/riscv/autovec.md (@vec_extract): Remove @. (vec_extract): Ditto. * config/riscv/riscv-vsetvl.cc (emit_vsetvl_insn): Fix bug. (pass_vsetvl::local_eliminate_vsetvl_insn): Ditto. * config/riscv/riscv.cc (riscv_legitimize_move): Expand move. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/partial/slp-9.c: Adapt test. * gcc.target/riscv/rvv/autovec/pr111391.c: New test. --- gcc/config/riscv/autovec.md | 2 +- gcc/config/riscv/riscv-vsetvl.cc | 4 ++- gcc/config/riscv/riscv.cc | 32 +++++++++++++++++++ .../riscv/rvv/autovec/partial/slp-9.c | 1 - .../gcc.target/riscv/rvv/autovec/pr111391.c | 28 ++++++++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr111391.c diff --git a/gcc/config/riscv/autovec.md b/gcc/config/riscv/autovec.md index e74a1695709..7121bab1716 100644 --- a/gcc/config/riscv/autovec.md +++ b/gcc/config/riscv/autovec.md @@ -1442,7 +1442,7 @@ ;; ------------------------------------------------------------------------- ;; ---- [INT,FP] Extract a vector element. ;; ------------------------------------------------------------------------- -(define_expand "@vec_extract" +(define_expand "vec_extract" [(set (match_operand: 0 "register_operand") (vec_select: (match_operand:V_VLS 1 "register_operand") diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index f81361c4ccd..7731e2a5f20 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -649,6 +649,8 @@ emit_vsetvl_insn (enum vsetvl_type insn_type, enum emit_type emit_type, { fprintf (dump_file, "\nInsert vsetvl insn PATTERN:\n"); print_rtl_single (dump_file, pat); + fprintf (dump_file, "\nfor insn:\n"); + print_rtl_single (dump_file, rinsn); } if (emit_type == EMIT_DIRECT) @@ -3861,7 +3863,7 @@ pass_vsetvl::local_eliminate_vsetvl_insn (const bb_info *bb) const skip_one = true; } - curr_avl = get_avl (rinsn); + curr_avl = curr_dem.get_avl (); /* Some instrucion like pred_extract_first don't reqruie avl, so the avl is null, use vl_placeholder for unify the handling diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 762937b0e37..3ba6379028f 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -2513,6 +2513,38 @@ riscv_legitimize_move (machine_mode mode, rtx dest, rtx src) } return true; } + /* Expand + (set (reg:DI target) (subreg:DI (reg:V8QI reg) 0)) + Expand this data movement instead of simply forbid it since + we can improve the code generation for this following scenario + by RVV auto-vectorization: + (set (reg:V8QI 149) (vec_duplicate:V8QI (reg:QI)) + (set (reg:DI target) (subreg:DI (reg:V8QI reg) 0)) + Since RVV mode and scalar mode are in different REG_CLASS, + we need to explicitly move data from V_REGS to GR_REGS by scalar move. */ + if (SUBREG_P (src) && riscv_v_ext_mode_p (GET_MODE (SUBREG_REG (src)))) + { + machine_mode vmode = GET_MODE (SUBREG_REG (src)); + unsigned int mode_size = GET_MODE_SIZE (mode).to_constant (); + unsigned int vmode_size = GET_MODE_SIZE (vmode).to_constant (); + unsigned int nunits = vmode_size / mode_size; + scalar_mode smode = as_a (mode); + vmode = riscv_vector::get_vector_mode (smode, nunits).require (); + enum insn_code icode + = convert_optab_handler (vec_extract_optab, vmode, mode); + gcc_assert (icode != CODE_FOR_nothing); + class expand_operand ops[3]; + create_output_operand (&ops[0], dest, mode); + ops[0].target = 1; + create_input_operand (&ops[1], gen_lowpart (vmode, SUBREG_REG (src)), + vmode); + unsigned int index = SUBREG_BYTE (src).to_constant () / mode_size; + create_integer_operand (&ops[2], index); + expand_insn (icode, 3, ops); + if (ops[0].value != dest) + emit_move_insn (dest, ops[0].value); + return true; + } /* Expand (set (reg:QI target) (mem:QI (address))) to diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-9.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-9.c index 5fba27c7a35..7c42438c9d9 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-9.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-9.c @@ -29,4 +29,3 @@ TEST_ALL (VEC_PERM) /* { dg-final { scan-assembler-times {viota.m} 2 } } */ -/* { dg-final { scan-assembler-not {vmv\.v\.i} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr111391.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr111391.c new file mode 100644 index 00000000000..a7f64c937c6 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr111391.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64d -Wno-int-conversion -Wno-implicit-function -Wno-incompatible-pointer-types -Wno-implicit-function-declaration -Ofast -ftree-vectorize" } */ + +int d (); +typedef struct +{ + int b; +} c; +int +e (char *f, long g) +{ + f += g; + while (g--) + *--f = d; +} + +int +d (c * f) +{ + while (h ()) + switch (f->b) + case 'Q': + { + long a; + e (&a, sizeof (a)); + i (a); + } +}