From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D76D83858D32; Thu, 28 Dec 2023 04:51:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D76D83858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1703739087; bh=J1kZ0C0+GU2JeUHqGQFmKrkJQMyata4cLEEPSm3pQJs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iqUxnccGY9ZOqB0c5Ezv6LhqajvfAWvdCcZzdm4JEmoLM501IUrGIKvIDjyBxIHA7 ltViKFLGT+Fr0NP75qOX0Q6JS+JROcy18MpqGisVwEwX+gOhqjdExy34hK8hvsPBWw chifF/xIT1AJ1oJ+YvQj9776F2FjEaB45fIoUQeo= From: "juzhe.zhong at rivai dot ai" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/113134] gcc does not version loops with early break conditions that don't have side-effects Date: Thu, 28 Dec 2023 04:51:27 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: juzhe.zhong at rivai dot ai X-Bugzilla-Status: NEW 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: Message-ID: In-Reply-To: References: 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=3D113134 --- Comment #14 from JuzheZhong --- (In reply to Tamar Christina from comment #13) > (In reply to JuzheZhong from comment #12) > > (In reply to Tamar Christina from comment #11) > > > (In reply to JuzheZhong from comment #10) > > > > (In reply to Tamar Christina from comment #9) > > > > > (In reply to JuzheZhong from comment #8) > > > > > > Suppose the loop mask is generated by whilelo instruction of AR= M SVE. > > > > > >=20 > > > > > > Suppose we have 8 elements in a single whole vector. > > > > > >=20 > > > > > > mask =3D whilo (0, res) if res =3D 6, then mask =3D 11111000. > > > > > > data =3D 12345678 > > > > > >=20 > > > > > > Then if it is early break. You are reversing both data and mask= as follows: > > > > > >=20 > > > > > > new_mask =3D 00011111 > > > > > > new_data =3D 87654321 > > > > > >=20 > > > > > > Then use the EXTRACT_LAST, we will get value =3D 1 for early br= eak. > > > > > >=20 > > > > > > Am I right ? > > > > >=20 > > > > > Yeah, the idea being the scalar loop will then run from 1 to 6 to= do any > > > > > side effects that we couldn't apply. > > > > >=20 > > > > > We went with this approach first because it works for non-masked > > > > > architectures too. In GCC-15 we'll try to implement staying entir= ely inside > > > > > a vector loop by splitting the mask in elements until first activ= e and > > > > > element from first active so we can correctly mask the operations. > > > >=20 > > > > Ok. For the current approach. Isn't it the first element is always = element 0 > > > > ? > > > >=20 > > > > Since for ARM SVE loop mask is generated by whilelo instructions, i= t always > > > > set > > > > mask bit from 0 to the last active element - 1. > > >=20 > > > sure, but you can't use BIT_FIELD_REF on VLA vectors. > >=20 > > So, for length partial vector. We can use VEC_EXTRACT with index =3D 0 = since > > VEC_EXTRACT optab allows VLA vectors now for length target. >=20 > Sounds good :) I wonder whether ARM SVE can also use this approach VEC_EXTRACT with index = =3D 0. I guess the only issue is that when mask =3D all zero. That is, there is no active elements, What behavior should be here for early break ?=