From patchwork Wed Feb 1 01:47:33 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: 64061 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 43CB33858284 for ; Wed, 1 Feb 2023 01:48:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbg151.qq.com (smtpbg151.qq.com [18.169.211.239]) by sourceware.org (Postfix) with ESMTPS id 328503858D38 for ; Wed, 1 Feb 2023 01:47:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 328503858D38 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: bizesmtp67t1675216056t54pbrn0 Received: from rios-cad5.localdomain ( [58.60.1.11]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 01 Feb 2023 09:47:36 +0800 (CST) X-QQ-SSF: 01400000000000E0L000000A0000000 X-QQ-FEAT: QityeSR92A1alguik0oDjdFNZwD3yP7Hfw/2FK4hZZAVpk5G5fnSvfWb+WQuU zjJmkGHbQS2fx6V5pzNGGFtv1kxQc3viDfjekaaZa173LS6kbrXrxA2eroctFXiA82DJ1bE Cf05g2wEwvgKDG9GSEou4xC6fdgwvO/9tX0ncwf5XtGrRe6aqW31LoSnn2aeZVntgkIAZye JbQc5m/duMONtU+BNpNrohJJP0JePwblKztRM5RuWK/fNMfY2kcsj0hHrCM5ESiCevLU7yk U+D0ihrxtC/ASp3Q48cuq1mTv5jfypOpviPgCVxI4chfENzmutkgWI3zMjPBPf3CP4XNZ7U HFVMF8GzfUeagzEGTwAeP+wxiqY5SvkAT4oYjr+H2pGJkKrUrcdE7T/hlVgW62UPrwkbaG3 G9FIvIQ0I7Y= X-QQ-GoodBg: 2 From: juzhe.zhong@rivai.ai To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, Ju-Zhe Zhong Subject: [PATCH] RISC-V: Fix constraint bug for binary operation Date: Wed, 1 Feb 2023 09:47:33 +0800 Message-Id: <20230201014733.172099-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:qybglogicsvr:qybglogicsvr7 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, 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.29 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 Sender: "Gcc-patches" From: Ju-Zhe Zhong Current constraint configuration will generate: vadd.vv v0,v24,v25,v0.t vsll.vx v0,v24,a5,v0.t They are incorrect according to RVV ISA. This patch fix this obvious issue. gcc/ChangeLog: * config/riscv/vector-iterators.md (sll.vi): Fix constraint bug. (sll.vv): Ditto. (%3,%4): Ditto. (%3,%v4): Ditto. * config/riscv/vector.md: Ditto. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/binop_vv_constraint-1.c: * gcc.target/riscv/rvv/base/shift_vx_constraint-1.c: --- gcc/config/riscv/vector-iterators.md | 86 +++++++++---------- gcc/config/riscv/vector.md | 41 +++++---- .../riscv/rvv/base/binop_vv_constraint-1.c | 8 +- .../riscv/rvv/base/shift_vx_constraint-1.c | 9 +- 4 files changed, 75 insertions(+), 69 deletions(-) diff --git a/gcc/config/riscv/vector-iterators.md b/gcc/config/riscv/vector-iterators.md index a2f192d6ba0..4f9799ade05 100644 --- a/gcc/config/riscv/vector-iterators.md +++ b/gcc/config/riscv/vector-iterators.md @@ -229,42 +229,42 @@ (umod "register_operand")]) (define_code_attr binop_rhs1_constraint [ - (plus "vr,vr,vr") - (minus "vr,vr,vi") - (ior "vr,vr,vr") - (xor "vr,vr,vr") - (and "vr,vr,vr") - (ashift "vr,vr,vr") - (ashiftrt "vr,vr,vr") - (lshiftrt "vr,vr,vr") - (smin "vr,vr,vr") - (smax "vr,vr,vr") - (umin "vr,vr,vr") - (umax "vr,vr,vr") - (mult "vr,vr,vr") - (div "vr,vr,vr") - (mod "vr,vr,vr") - (udiv "vr,vr,vr") - (umod "vr,vr,vr")]) + (plus "vr,vr,vr,vr,vr,vr") + (minus "vr,vr,vr,vr,vi,vi") + (ior "vr,vr,vr,vr,vr,vr") + (xor "vr,vr,vr,vr,vr,vr") + (and "vr,vr,vr,vr,vr,vr") + (ashift "vr,vr,vr,vr,vr,vr") + (ashiftrt "vr,vr,vr,vr,vr,vr") + (lshiftrt "vr,vr,vr,vr,vr,vr") + (smin "vr,vr,vr,vr,vr,vr") + (smax "vr,vr,vr,vr,vr,vr") + (umin "vr,vr,vr,vr,vr,vr") + (umax "vr,vr,vr,vr,vr,vr") + (mult "vr,vr,vr,vr,vr,vr") + (div "vr,vr,vr,vr,vr,vr") + (mod "vr,vr,vr,vr,vr,vr") + (udiv "vr,vr,vr,vr,vr,vr") + (umod "vr,vr,vr,vr,vr,vr")]) (define_code_attr binop_rhs2_constraint [ - (plus "vr,vi,vr") - (minus "vr,vj,vr") - (ior "vr,vi,vr") - (xor "vr,vi,vr") - (and "vr,vi,vr") - (ashift "vr,vk,vr") - (ashiftrt "vr,vk,vr") - (lshiftrt "vr,vk,vr") - (smin "vr,vr,vr") - (smax "vr,vr,vr") - (umin "vr,vr,vr") - (umax "vr,vr,vr") - (mult "vr,vr,vr") - (div "vr,vr,vr") - (mod "vr,vr,vr") - (udiv "vr,vr,vr") - (umod "vr,vr,vr")]) + (plus "vr,vr,vi,vi,vr,vr") + (minus "vr,vr,vj,vj,vr,vr") + (ior "vr,vr,vi,vi,vr,vr") + (xor "vr,vr,vi,vi,vr,vr") + (and "vr,vr,vi,vi,vr,vr") + (ashift "vr,vr,vk,vk,vr,vr") + (ashiftrt "vr,vr,vk,vk,vr,vr") + (lshiftrt "vr,vr,vk,vk,vr,vr") + (smin "vr,vr,vr,vr,vr,vr") + (smax "vr,vr,vr,vr,vr,vr") + (umin "vr,vr,vr,vr,vr,vr") + (umax "vr,vr,vr,vr,vr,vr") + (mult "vr,vr,vr,vr,vr,vr") + (div "vr,vr,vr,vr,vr,vr") + (mod "vr,vr,vr,vr,vr,vr") + (udiv "vr,vr,vr,vr,vr,vr") + (umod "vr,vr,vr,vr,vr,vr")]) (define_code_attr int_binop_insn_type [ (plus "vialu") @@ -285,9 +285,9 @@ (udiv "vidiv") (umod "vidiv")]) -;; expands to the insn name of binop matching constraint alternative = 1. +;; expands to the insn name of binop matching constraint rhs1 is immediate. ;; minus is negated as vadd and ss_minus is negated as vsadd, others remain . -(define_code_attr binop_alt1_insn [(ashift "sll.vi") +(define_code_attr binop_imm_rhs1_insn [(ashift "sll.vi") (ashiftrt "sra.vi") (lshiftrt "srl.vi") (div "div.vv") @@ -305,9 +305,9 @@ (umax "maxu.vv") (mult "mul.vv")]) -;; expands to the insn name of binop matching constraint alternative = 2. +;; expands to the insn name of binop matching constraint rhs2 is immediate. ;; minus is reversed as vrsub, others remain . -(define_code_attr binop_alt2_insn [(ashift "sll.vv") +(define_code_attr binop_imm_rhs2_insn [(ashift "sll.vv") (ashiftrt "sra.vv") (lshiftrt "srl.vv") (div "div.vv") @@ -325,9 +325,9 @@ (umax "maxu.vv") (mult "mul.vv")]) -(define_code_attr binop_alt1_op [(ashift "%3,%4") - (ashiftrt "%3,%4") - (lshiftrt "%3,%4") +(define_code_attr binop_imm_rhs1_op [(ashift "%3,%v4") + (ashiftrt "%3,%v4") + (lshiftrt "%3,%v4") (div "%3,%4") (mod "%3,%4") (udiv "%3,%4") @@ -335,7 +335,7 @@ (ior "%3,%4") (xor "%3,%4") (and "%3,%4") - (plus "%3,%4") + (plus "%3,%v4") (minus "%3,%V4") (smin "%3,%4") (smax "%3,%4") @@ -343,7 +343,7 @@ (umax "%3,%4") (mult "%3,%4")]) -(define_code_attr binop_alt2_op [(ashift "%3,%4") +(define_code_attr binop_imm_rhs2_op [(ashift "%3,%4") (ashiftrt "%3,%4") (lshiftrt "%3,%4") (div "%3,%4") diff --git a/gcc/config/riscv/vector.md b/gcc/config/riscv/vector.md index 36b0e07728c..5267417465a 100644 --- a/gcc/config/riscv/vector.md +++ b/gcc/config/riscv/vector.md @@ -1127,25 +1127,28 @@ ;; ------------------------------------------------------------------------------- (define_insn "@pred_" - [(set (match_operand:VI 0 "register_operand" "=vr, vr, vr") + [(set (match_operand:VI 0 "register_operand" "=vd, vr, vd, vr, vd, vr") (if_then_else:VI (unspec: - [(match_operand: 1 "vector_mask_operand" " vmWc1,vmWc1,vmWc1") - (match_operand 5 "vector_length_operand" " rK, rK, rK") - (match_operand 6 "const_int_operand" " i, i, i") - (match_operand 7 "const_int_operand" " i, i, i") - (match_operand 8 "const_int_operand" " i, i, i") + [(match_operand: 1 "vector_mask_operand" " vm,Wc1, vm,Wc1, vm,Wc1") + (match_operand 5 "vector_length_operand" " rK, rK, rK, rK, rK, rK") + (match_operand 6 "const_int_operand" " i, i, i, i, i, i") + (match_operand 7 "const_int_operand" " i, i, i, i, i, i") + (match_operand 8 "const_int_operand" " i, i, i, i, i, i") (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) (any_int_binop:VI (match_operand:VI 3 "" "") (match_operand:VI 4 "" "")) - (match_operand:VI 2 "vector_merge_operand" " 0vu, 0vu, 0vu")))] + (match_operand:VI 2 "vector_merge_operand" "0vu,0vu,0vu,0vu,0vu,0vu")))] "TARGET_VECTOR" "@ v.vv\t%0,%3,%4%p1 - v\t%0,%p1 - v\t%0,%p1" + v.vv\t%0,%3,%4%p1 + v\t%0,%p1 + v\t%0,%p1 + v\t%0,%p1 + v\t%0,%p1" [(set_attr "type" "") (set_attr "mode" "")]) @@ -1154,23 +1157,25 @@ ;; For vsll.vx/vsra.vx/vsrl.vx the scalar mode should be Pmode wheras the ;; scalar mode is inner mode of the RVV mode for other vx patterns. (define_insn "@pred__scalar" - [(set (match_operand:VI 0 "register_operand" "=vr, vr") + [(set (match_operand:VI 0 "register_operand" "=vd, vr, vd, vr") (if_then_else:VI (unspec: - [(match_operand: 1 "vector_mask_operand" "vmWc1,vmWc1") - (match_operand 5 "vector_length_operand" " rK, rK") - (match_operand 6 "const_int_operand" " i, i") - (match_operand 7 "const_int_operand" " i, i") - (match_operand 8 "const_int_operand" " i, i") + [(match_operand: 1 "vector_mask_operand" " vm,Wc1, vm,Wc1") + (match_operand 5 "vector_length_operand" " rK, rK, rK, rK") + (match_operand 6 "const_int_operand" " i, i, i, i") + (match_operand 7 "const_int_operand" " i, i, i, i") + (match_operand 8 "const_int_operand" " i, i, i, i") (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) (any_shift:VI - (match_operand:VI 3 "register_operand" " vr, vr") - (match_operand 4 "pmode_reg_or_uimm5_operand" " r, K")) - (match_operand:VI 2 "vector_merge_operand" "0vu, 0vu")))] + (match_operand:VI 3 "register_operand" " vr, vr, vr, vr") + (match_operand 4 "pmode_reg_or_uimm5_operand" " r, r, K, K")) + (match_operand:VI 2 "vector_merge_operand" "0vu,0vu,0vu,0vu")))] "TARGET_VECTOR" "@ v.vx\t%0,%3,%4%p1 + v.vx\t%0,%3,%4%p1 + v.vi\t%0,%3,%4%p1 v.vi\t%0,%3,%4%p1" [(set_attr "type" "vshift") (set_attr "mode" "")]) diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/binop_vv_constraint-1.c b/gcc/testsuite/gcc.target/riscv/rvv/base/binop_vv_constraint-1.c index 3ab1ccee035..3372ec1d230 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/base/binop_vv_constraint-1.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/binop_vv_constraint-1.c @@ -29,7 +29,7 @@ void f1 (void * in, void *out) ** vsetivli\tzero,4,e32,m1,ta,ma ** vle32.v\tv[0-9]+,0\([a-x0-9]+\),v0.t ** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+ -** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t +** vadd\.vv\tv[1-9][0-9]?,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t ** vse32.v\tv[0-9]+,0\([a-x0-9]+\) ** ret */ @@ -52,7 +52,7 @@ void f2 (void * in, void *out) ** vle32\.v\tv[0-9]+,0\([a-x0-9]+\) ** vle32.v\tv[0-9]+,0\([a-x0-9]+\),v0.t ** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+ -** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t +** vadd\.vv\tv[1-9][0-9]?,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t ** vse32.v\tv[0-9]+,0\([a-x0-9]+\) ** ret */ @@ -93,7 +93,7 @@ void f4 (void * in, void *out) ** vsetivli\tzero,4,e8,mf8,ta,ma ** vle8.v\tv[0-9]+,0\([a-x0-9]+\),v0.t ** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+ -** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t +** vadd\.vv\tv[1-9][0-9]?,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t ** vse8.v\tv[0-9]+,0\([a-x0-9]+\) ** ret */ @@ -116,7 +116,7 @@ void f5 (void * in, void *out) ** vle8\.v\tv[0-9]+,0\([a-x0-9]+\) ** vle8.v\tv[0-9]+,0\([a-x0-9]+\),v0.t ** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+ -** vadd\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t +** vadd\.vv\tv[1-9][0-9]?,\s*v[0-9]+,\s*v[0-9]+,\s*v0.t ** vse8.v\tv[0-9]+,0\([a-x0-9]+\) ** ret */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/shift_vx_constraint-1.c b/gcc/testsuite/gcc.target/riscv/rvv/base/shift_vx_constraint-1.c index ae3883c5af9..e40e193220c 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/base/shift_vx_constraint-1.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/shift_vx_constraint-1.c @@ -28,9 +28,10 @@ void f1 (void * in, void *out) ** vlm.v\tv[0-9]+,0\([a-x0-9]+\) ** ... ** vsetivli\tzero,4,e32,m1,ta,ma +** ... ** vle32.v\tv[0-9]+,0\([a-x0-9]+\),v0.t ** vsll\.vx\tv[0-9]+,\s*v[0-9]+,\s*[a-x0-9]+ -** vsll\.vx\tv[0-9]+,\s*v[0-9]+,\s*[a-x0-9]+,\s*v0.t +** vsll\.vx\tv[1-9][0-9]?,\s*v[0-9]+,\s*[a-x0-9]+,\s*v0.t ** vse32.v\tv[0-9]+,0\([a-x0-9]+\) ** ret */ @@ -53,7 +54,7 @@ void f2 (void * in, void *out) ** vle32\.v\tv[0-9]+,0\([a-x0-9]+\) ** vle32.v\tv[0-9]+,0\([a-x0-9]+\),v0.t ** vsll\.vi\tv[0-9]+,\s*v[0-9]+,\s*17 -** vsll\.vi\tv[0-9]+,\s*v[0-9]+,\s*17,\s*v0.t +** vsll\.vi\tv[1-9][0-9]?,\s*v[0-9]+,\s*17,\s*v0.t ** vse32.v\tv[0-9]+,0\([a-x0-9]+\) ** ret */ @@ -94,7 +95,7 @@ void f4 (void * in, void *out, size_t x) ** vsetivli\tzero,4,e8,mf8,ta,ma ** vle8.v\tv[0-9]+,0\([a-x0-9]+\),v0.t ** vsll\.vi\tv[0-9]+,\s*v[0-9]+,\s*5 -** vsll\.vi\tv[0-9]+,\s*v[0-9]+,\s*5,\s*v0.t +** vsll\.vi\tv[1-9][0-9]?,\s*v[0-9]+,\s*5,\s*v0.t ** vse8.v\tv[0-9]+,0\([a-x0-9]+\) ** ret */ @@ -117,7 +118,7 @@ void f5 (void * in, void *out) ** vle8\.v\tv[0-9]+,0\([a-x0-9]+\) ** vle8.v\tv[0-9]+,0\([a-x0-9]+\),v0.t ** vsll\.vx\tv[0-9]+,\s*v[0-9]+,\s*[a-x0-9]+ -** vsll\.vx\tv[0-9]+,\s*v[0-9]+,\s*[a-x0-9]+,\s*v0.t +** vsll\.vx\tv[1-9][0-9]?,\s*v[0-9]+,\s*[a-x0-9]+,\s*v0.t ** vse8.v\tv[0-9]+,0\([a-x0-9]+\) ** ret */