https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113134
--- Comment #8 from JuzheZhong <juzhe.zhong at rivai dot ai> --- (In reply to Tamar Christina from comment #7) > You may be able to use the same approach as > > else if (LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)) > > 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_FIRST 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 = perm_mask_for_reverse (TREE_TYPE (mask)); tree perm_dest = copy_ssa_name (mask); gimple *perm_stmt = gimple_build_assign (perm_dest, VEC_PERM_EXPR, mask, mask, perm_mask); vect_finish_stmt_generation (loop_vinfo, stmt_info, perm_stmt, &gsi); mask = perm_dest; /* Then permute the vector contents. */ tree perm_elem = perm_mask_for_reverse (vectype); perm_dest = copy_ssa_name (vec_lhs_phi); perm_stmt = 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 = 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 = whilo (0, res) if res = 6, then mask = 11111000. data = 12345678 Then if it is early break. You are reversing both data and mask as follows: new_mask = 00011111 new_data = 87654321 Then use the EXTRACT_LAST, we will get value = 1 for early break. Am I right ?