From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk1-xa31.google.com (mail-vk1-xa31.google.com [IPv6:2607:f8b0:4864:20::a31]) by sourceware.org (Postfix) with ESMTPS id BCC18384F00E for ; Fri, 3 Feb 2023 07:17:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BCC18384F00E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vk1-xa31.google.com with SMTP id u199so2118230vkb.12 for ; Thu, 02 Feb 2023 23:17:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=GFHSQMFhIhF6mxdAGBQ3p7T2ppAme+QgXI/U1+woUrc=; b=PWzVqp5HF3HWA7iRaBDjik2Z+IcmQBh0weMPbn4g14jPG7kegoOIBIY+Pb0K5JS2oO KMFY8qq105f/5s50J9AdEU4cBmbKNT8mTzkie4lWij1JgjD8G2TgtcN4OLxPdYdv6VlW guEGpWK9V2796lg83/Qqd/rdioInC8gv+3EW9g850N+YQFfH3yPmINOIMRPo/LuMZTTI IhGEkE7l18qQVxCcYy8Ag8Dv0jOnro9ESMTx1I2h0bY7DrQQdf36fTv6z1/teZnSp5+n zBY+y1amxsfQAiPx7Rnd7SGvBS5moQvY2Gvx7YFQZq9KlSkawJlNiJOM5HdEUQibifT0 LRmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GFHSQMFhIhF6mxdAGBQ3p7T2ppAme+QgXI/U1+woUrc=; b=ug/XU9abxnxxXG/NA0OhIZc6K49R/UTiX2S7wuv81dh32OYjyNoznbcqEFONzRLXhv rY0f1fMPfAOyq+O8csC3Yus6VyB//S9Iw5LO/gA6RrO1CPYpwr58zpJ1VrkxkmuexRTK +yoJ7Dx2E9cfCHQmY5PJGRR1Nu+Uqnf3EgmvNLNc010B8XnIXexcwXgHeZ1jHpccM6xr Vok897Rvj8rfDs9/3sQGv9RxrYXUR79YGLqiZT9C9ph3mdrnxmozuK0KMdDKwN4+/FK4 27EktSA3W++J8Mmtym43n//DsBn7Dw82jbZppv5YrG34UbJVjuv0ZwOLXxF/9TwQUXml v0ZQ== X-Gm-Message-State: AO0yUKXyQKFXql/m1W2hOV23UbOxsvdOnWTLFZxOwRJnzlaR9cznLXZD lB4+13V5av6Vn7x9unF+uqwgJsCTBWw9y4WFwLK9SVZ9slI= X-Google-Smtp-Source: AK7set+9Y0uuDr1R6pGjfhjkqBx6Fg1DLY7h9TKnQ/kcC5eldDFLhBx5HTk3F9QfTR8o+xUxC2VdU/s49KQKzWMsWug= X-Received: by 2002:ac5:cbcf:0:b0:3ea:498c:4e81 with SMTP id h15-20020ac5cbcf000000b003ea498c4e81mr1287912vkn.5.1675408626897; Thu, 02 Feb 2023 23:17:06 -0800 (PST) MIME-Version: 1.0 References: <20230201014733.172099-1-juzhe.zhong@rivai.ai> In-Reply-To: <20230201014733.172099-1-juzhe.zhong@rivai.ai> From: Kito Cheng Date: Fri, 3 Feb 2023 15:16:55 +0800 Message-ID: Subject: Re: [PATCH] RISC-V: Fix constraint bug for binary operation To: juzhe.zhong@rivai.ai Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.1 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 List-Id: committed, thanks! On Wed, Feb 1, 2023 at 9:48 AM wrote: > > 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 > */ > -- > 2.36.3 >