https://gcc.gnu.org/g:1bedb5ac23801c6639387e53b544157f2f51cd34

commit r17-5529-g1bedb5ac23801c6639387e53b544157f2f51cd34
Author: Tamar Christina <[email protected]>
Date:   Sat Oct 24 11:37:25 2026 +0100

    middle-end: Rename extract_last to extract_last_active
    
    The extract_last operation takes a vector and a mask and extracts the 
element
    selected by the last set bit in the mask.  The current name leaves the role 
of
    the mask implicit.
    
    For example, with
    
      values = { 10, 20, 30, 40 }
      mask   = {  1,  0,  1,  0 }
    
    the result is 30, since lane 2 is the last active lane.
    
    This patch renames the internal function to EXTRACT_LAST_ACTIVE and the 
optab
    and target patterns to extract_last_active.  This makes the selection of an
    active lane explicit in the name.
    
    This is a mechanical renaming which I was asked to do for my early break
    patch series that introduces extract_first_active.
    
    Bootstrapped Regtested on aarch64-none-linux-gnu, arm-none-linux-gnueabihf,
    x86_64-pc-linux-gnu -m32, -m64 and no issues.
    
    gcc/ChangeLog:
    
            * config/aarch64/aarch64-sve.md (vec_extract<mode><Vel>): Call
            gen_extract_last_active_<mode>.
            (@extract_<last_op>_<mode>): Generate extract_last_active_<mode>
            for UNSPEC_LASTB through the last_op attribute.
            * config/aarch64/iterators.md (last_op): Change the UNSPEC_LASTB
            mapping from last to last_active.
            * config/gcn/gcn-valu.md (extract_last_<mode>): Rename to...
            (extract_last_active_<mode>): ...this.
            (fold_extract_last_<mode>): Call gen_extract_last_active_<mode>.
            * doc/ifn.texi (IFN_EXTRACT_LAST): Rename to IFN_EXTRACT_LAST_ACTIVE
            and update the corresponding pattern name.
            * doc/md.texi (extract_last_m): Rename to extract_last_active_m.
            * internal-fn.def (EXTRACT_LAST): Rename to EXTRACT_LAST_ACTIVE and
            use the extract_last_active optab.
            * optabs.def (extract_last_optab): Rename to
            extract_last_active_optab and use the extract_last_active pattern.
            * tree-vect-loop.cc (vectorizable_live_operation_1): Emit
            CFN_EXTRACT_LAST_ACTIVE and update the comment.
            (vectorizable_live_operation): Check IFN_EXTRACT_LAST_ACTIVE 
support.

Diff:
---
 gcc/config/aarch64/aarch64-sve.md | 6 ++++--
 gcc/config/aarch64/iterators.md   | 2 +-
 gcc/config/gcn/gcn-valu.md        | 4 ++--
 gcc/doc/ifn.texi                  | 8 ++++----
 gcc/doc/md.texi                   | 4 ++--
 gcc/internal-fn.def               | 4 ++--
 gcc/optabs.def                    | 2 +-
 gcc/tree-vect-loop.cc             | 6 +++---
 8 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-sve.md 
b/gcc/config/aarch64/aarch64-sve.md
index 8d171758a36d..da5e5ce49f26 100644
--- a/gcc/config/aarch64/aarch64-sve.md
+++ b/gcc/config/aarch64/aarch64-sve.md
@@ -3154,7 +3154,8 @@
        /* For VLA, extract the last element with a LASTB and a false
           predicate. */
        rtx sel = aarch64_pfalse_reg (<VPRED>mode);
-       emit_insn (gen_extract_last_<mode> (operands[0], sel, operands[1]));
+       emit_insn (gen_extract_last_active_<mode> (operands[0], sel,
+                                           operands[1]));
        DONE;
       }
     if (!CONST_INT_P (operands[2]))
@@ -3173,7 +3174,8 @@
        emit_insn (gen_vec_cmp<v_int_equiv><vpred> (sel, cmp, series, zero));
 
        /* Select the element using LASTB.  */
-       emit_insn (gen_extract_last_<mode> (operands[0], sel, operands[1]));
+       emit_insn (gen_extract_last_active_<mode> (operands[0], sel,
+                                           operands[1]));
        DONE;
       }
   }
diff --git a/gcc/config/aarch64/iterators.md b/gcc/config/aarch64/iterators.md
index f38a39fd6e36..ae78fbe5b5bd 100644
--- a/gcc/config/aarch64/iterators.md
+++ b/gcc/config/aarch64/iterators.md
@@ -4793,7 +4793,7 @@
 (define_int_attr last_op [(UNSPEC_CLASTA "after_last")
                          (UNSPEC_CLASTB "last")
                          (UNSPEC_LASTA "after_last")
-                         (UNSPEC_LASTB "last")])
+                         (UNSPEC_LASTB "last_active")])
 
 ;; "s" for signed operations and "u" for unsigned ones.
 (define_int_attr su [(UNSPEC_SADDV "s")
diff --git a/gcc/config/gcn/gcn-valu.md b/gcc/config/gcn/gcn-valu.md
index 9c14a489ad0d..f816f82559bb 100644
--- a/gcc/config/gcn/gcn-valu.md
+++ b/gcc/config/gcn/gcn-valu.md
@@ -1063,7 +1063,7 @@
     DONE;
   })
 
-(define_expand "extract_last_<mode>"
+(define_expand "extract_last_active_<mode>"
   [(match_operand:<SCALAR_MODE> 0 "register_operand")
    (match_operand:DI 1 "gcn_alu_operand")
    (match_operand:V_MOV 2 "register_operand")]
@@ -1096,7 +1096,7 @@
 
     rtx cond = gen_rtx_EQ (VOIDmode, mask, const0_rtx);
     emit_jump_insn (gen_cbranchdi4 (cond, mask, const0_rtx, else_label));
-    emit_insn (gen_extract_last_<mode> (dst, mask, vect));
+    emit_insn (gen_extract_last_active_<mode> (dst, mask, vect));
     emit_jump_insn (gen_jump (end_label));
     emit_barrier ();
     emit_label (else_label);
diff --git a/gcc/doc/ifn.texi b/gcc/doc/ifn.texi
index afe8a977f70a..7d58c2233739 100644
--- a/gcc/doc/ifn.texi
+++ b/gcc/doc/ifn.texi
@@ -507,10 +507,10 @@ The @code{IFN_REDUC_SBOOL_IOR} internal function directly 
maps to the
 The @code{IFN_REDUC_SBOOL_XOR} internal function directly maps to the
 @code{reduc_sbool_xor_scal} instruction pattern.
 
-@cindex @code{IFN_EXTRACT_LAST} internal function
-@item @samp{IFN_EXTRACT_LAST}
-The @code{IFN_EXTRACT_LAST} internal function directly maps to the
-@code{extract_last} instruction pattern.
+@cindex @code{IFN_EXTRACT_LAST_ACTIVE} internal function
+@item @samp{IFN_EXTRACT_LAST_ACTIVE}
+The @code{IFN_EXTRACT_LAST_ACTIVE} internal function directly maps to the
+@code{extract_last_active} instruction pattern.
 
 @cindex @code{IFN_FOLD_EXTRACT_LAST} internal function
 @item @samp{IFN_FOLD_EXTRACT_LAST}
diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index 648c12f6e7b9..d72f29e5a71a 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -7913,8 +7913,8 @@ with its value either zero or one.  If mode @var{m} is a 
scalar integer mode
 then operand 2 is the number of elements in the input vector to provide
 disambiguation for the case @var{m} is ambiguous.
 
-@mdindex extract_last_@var{m}
-@item @code{extract_last_@var{m}}
+@mdindex extract_last_active_@var{m}
+@item @code{extract_last_active_@var{m}}
 Find the last set bit in mask operand 1 and extract the associated element
 of vector operand 2.  Store the result in scalar operand 0.  Operand 2
 has vector mode @var{m} while operand 0 has the mode appropriate for one
diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def
index b1c46a82a520..7feb236d8026 100644
--- a/gcc/internal-fn.def
+++ b/gcc/internal-fn.def
@@ -364,8 +364,8 @@ DEF_INTERNAL_OPTAB_FN (REDUC_SBOOL_XOR, ECF_CONST | 
ECF_NOTHROW,
 
 
 /* Extract the last active element from a vector.  */
-DEF_INTERNAL_OPTAB_FN (EXTRACT_LAST, ECF_CONST | ECF_NOTHROW,
-                      extract_last, fold_left)
+DEF_INTERNAL_OPTAB_FN (EXTRACT_LAST_ACTIVE, ECF_CONST | ECF_NOTHROW,
+                      extract_last_active, fold_left)
 
 /* Same, but return the first argument if no elements are active.  */
 DEF_INTERNAL_OPTAB_FN (FOLD_EXTRACT_LAST, ECF_CONST | ECF_NOTHROW,
diff --git a/gcc/optabs.def b/gcc/optabs.def
index faecb796d015..4ee434ea1a7c 100644
--- a/gcc/optabs.def
+++ b/gcc/optabs.def
@@ -429,7 +429,7 @@ OPTAB_D (fold_left_plus_optab, "fold_left_plus_$a")
 OPTAB_D (mask_fold_left_plus_optab, "mask_fold_left_plus_$a")
 OPTAB_D (mask_len_fold_left_plus_optab, "mask_len_fold_left_plus_$a")
 
-OPTAB_D (extract_last_optab, "extract_last_$a")
+OPTAB_D (extract_last_active_optab, "extract_last_active_$a")
 OPTAB_D (fold_extract_last_optab, "fold_extract_last_$a")
 OPTAB_D (len_fold_extract_last_optab, "len_fold_extract_last_$a")
 
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 7ed3f58bf238..dbb677c44bd5 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -10245,7 +10245,7 @@ vectorizable_live_operation_1 (loop_vec_info 
loop_vinfo, basic_block exit_bb,
     {
       /* Emit:
 
-        SCALAR_RES = EXTRACT_LAST <VEC_LHS, MASK>
+        SCALAR_RES = EXTRACT_LAST_ACTIVE <VEC_LHS, MASK>
 
         where VEC_LHS is the vectorized live-out result and MASK is
         the loop mask for the final iteration.  */
@@ -10259,7 +10259,7 @@ vectorizable_live_operation_1 (loop_vec_info 
loop_vinfo, basic_block exit_bb,
       tree scalar_res;
       gimple_seq_add_seq (&stmts, tem);
 
-      scalar_res = gimple_build (&stmts, CFN_EXTRACT_LAST, scalar_type,
+      scalar_res = gimple_build (&stmts, CFN_EXTRACT_LAST_ACTIVE, scalar_type,
                                 mask, vec_lhs_phi);
 
       /* Convert the extracted vector element to the scalar type.  */
@@ -10418,7 +10418,7 @@ vectorizable_live_operation (vec_info *vinfo, 
stmt_vec_info stmt_info,
            }
          else
            {
-             if (direct_internal_fn_supported_p (IFN_EXTRACT_LAST, vectype,
+             if (direct_internal_fn_supported_p (IFN_EXTRACT_LAST_ACTIVE, 
vectype,
                                                  OPTIMIZE_FOR_SPEED))
                vect_record_loop_mask (loop_vinfo,
                                       &LOOP_VINFO_MASKS (loop_vinfo),

Reply via email to