From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B76C23858D38; Mon, 18 Sep 2023 03:24:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B76C23858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695007483; bh=UjnCLUs8Yw2Wgxdgmb4n3HJM9Pvpty7mYhUrKmUaNkE=; h=From:To:Subject:Date:From; b=ZRypwLuxKbQ8IjUXmwMXOx0Bwf0z24FZqzviuLD7wGxkUHuBRkbAO6Of1ZhgEfa9O Pujr2cSO9U0SlrP4pzfj8ZT5CAcVEbyK4Q5pSluGy7bo3/AsOal529Jsv8HF2/JvWV HOPjtL+VwI9dIeAxDhcWYmE6NP7QT3YNOHM13UkU= From: "juzhe.zhong at rivai dot ai" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/111451] New: RISC-V: Missed optimization of vrgather.vv into vrgatherei16.vv Date: Mon, 18 Sep 2023 03:24:42 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: juzhe.zhong at rivai dot ai X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111451 Bug ID: 111451 Summary: RISC-V: Missed optimization of vrgather.vv into vrgatherei16.vv Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: juzhe.zhong at rivai dot ai Target Milestone: --- Consider this following case: #include typedef int32_t vnx32si __attribute__ ((vector_size (128))); #define MASK_2(X, Y) (Y) - 1 - (X), (Y) - 2 - (X) #define MASK_4(X, Y) MASK_2 (X, Y), MASK_2 (X + 2, Y) #define MASK_8(X, Y) MASK_4 (X, Y), MASK_4 (X + 4, Y) #define MASK_16(X, Y) MASK_8 (X, Y), MASK_8 (X + 8, Y) #define MASK_32(X, Y) MASK_16 (X, Y), MASK_16 (X + 16, Y) #define MASK_64(X, Y) MASK_32 (X, Y), MASK_32 (X + 32, Y) #define MASK_128(X, Y) MASK_64 (X, Y), MASK_64 (X + 64, Y) #define PERMUTE(TYPE, NUNITS)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20 \ __attribute__ ((noipa)) void permute_##TYPE (TYPE values1, TYPE values2,= =20=20=20=20 \ TYPE *out)=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 \ {=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20 \ TYPE v=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 \ =3D __builtin_shufflevector (values1, values2, MASK_##NUNITS (0, NUNI= TS)); \ *(TYPE *) out =3D v;=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20 \ } #define TEST_ALL(T)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 \ T (vnx32si, 32)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 \ TEST_ALL (PERMUTE) ASM: permute_vnx32si: li a5,32 li a4,31 vsetvli zero,a5,e32,m8,ta,ma vid.v v8 vle32.v v24,0(a0) vrsub.vx v8,v8,a4 vrgather.vv v16,v24,v8 vse32.v v16,0(a2) ret https://godbolt.org/z/Mh77YY91r Here we use: vsetvli zero,a5,e32,m8,ta,ma ... vrgather.vv v16,v24,v8 The index vector register "v8" occupies 8 registers. We should optimize it into vrgatherei16.vv which is using int16 as the inde= x=20 elements. Then with vrgatherei16.vv, the v8 will occupy 4 registers instead of 8. Lower the register consuming and register pressure.=