From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D99BE3858D38; Thu, 28 Dec 2023 04:23:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D99BE3858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1703737436; bh=Bj37s5lgfiogASp+t7Zaq0kJnlH+aoF9Grx9W8rUjqI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KyA4h1MbfmQHN9S+SPEc84ux2FNPZcPP+q2kwbrAKoBG4odwE8Lo8pT9P3R3m+3CJ Od0bgQUbQEARc6xFHXHsPM+5auywHDE2iaBUzc9xxQx4gMRhTdUquQqngDwyk3Kkyh ElH0uXyKyQGEwavCPYN6EAnwlZX37BezoDEK6bhk= 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:23:56 +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 #8 from JuzheZhong --- (In reply to Tamar Christina from comment #7) > You may be able to use the same approach as >=20 > else if (LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)) >=20 > that is, reverse both the mask and the vector and using extract last. > It's not going to be performance critical so it's more important to be > correct rather than fast. I just carefully read this code: /* For an inverted control flow with early breaks we want EXTRACT_FIR= ST instead of EXTRACT_LAST. Emulate by reversing the vector and mask= . */ if (restart_loop && LOOP_VINFO_EARLY_BREAKS (loop_vinfo)) { /* First create the permuted mask. */ tree perm_mask =3D perm_mask_for_reverse (TREE_TYPE (mask)); tree perm_dest =3D copy_ssa_name (mask); gimple *perm_stmt =3D gimple_build_assign (perm_dest, VEC_PERM_EXPR, mask, mask, perm_mask); vect_finish_stmt_generation (loop_vinfo, stmt_info, perm_stmt, &gsi); mask =3D perm_dest; /* Then permute the vector contents. */ tree perm_elem =3D perm_mask_for_reverse (vectype); perm_dest =3D copy_ssa_name (vec_lhs_phi); perm_stmt =3D gimple_build_assign (perm_dest, VEC_PERM_EXPR, vec_lhs_= phi, vec_lhs_phi, perm_elem); vect_finish_stmt_generation (loop_vinfo, stmt_info, perm_stmt, &gsi); vec_lhs_phi =3D perm_dest; } Suppose the loop mask is generated by whilelo instruction of ARM SVE. Suppose we have 8 elements in a single whole vector. mask =3D whilo (0, res) if res =3D 6, then mask =3D 11111000. data =3D 12345678 Then if it is early break. You are reversing both data and mask as follows: new_mask =3D 00011111 new_data =3D 87654321 Then use the EXTRACT_LAST, we will get value =3D 1 for early break. Am I right ?=