https://gcc.gnu.org/g:44eaf4ae9e1d26c120a92540abfc225ec634243c

commit r17-5338-g44eaf4ae9e1d26c120a92540abfc225ec634243c
Author: Kyrylo Tkachov <[email protected]>
Date:   Fri Oct 9 10:50:10 2026 -0700

    testsuite: Add clzsi and ctzsi effective targets
    
    A GIMPLE FE test with a .CLZ or .CTZ call needs the clz or ctz
    instruction pattern for the mode of the call, because the expansion of
    these internal functions has no fallback.  The clz and ctz effective
    targets only check that __builtin_clz and __builtin_ctz do not become
    library calls.  They are also true when the expander makes the count
    from other patterns, for example ctz on s390 before z17.
    
    Add clzsi and ctzsi, named after the clzsi2 and ctzsi2 patterns.  They
    check that niter analysis turns a counting loop on a 32-bit unsigned
    integer into a .CLZ or .CTZ call, which it does only if the target has
    the pattern.  The pattern can be an expander that uses other
    operations.  The niter tests keep the clz and ctz effective targets,
    because they also accept the __builtin_clz and __builtin_ctz forms.
    
    Bootstrapped and tested on aarch64-none-linux-gnu and x86_64-linux.
    
    gcc/ChangeLog:
    
            * doc/sourcebuild.texi (clzsi, ctzsi): Document.
    
    gcc/testsuite/ChangeLog:
    
            * lib/target-supports.exp (check_effective_target_clzsi)
            (check_effective_target_ctzsi): New procedures.
    
    Signed-off-by: Kyrylo Tkachov <[email protected]>

Diff:
---
 gcc/doc/sourcebuild.texi              | 10 +++++++++
 gcc/testsuite/lib/target-supports.exp | 40 +++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 3aa9fcbb5778..db7250875668 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2774,6 +2774,11 @@ Target supports a clz optab on long.
 @item clzll
 Target supports a clz optab on long long.
 
+@item clzsi
+Target has a @code{clzsi2} pattern, which can be an expander, so a
+@code{.CLZ} internal function call on a 32-bit unsigned integer can be
+expanded.
+
 @item ctz
 Target supports a ctz optab on int.
 
@@ -2783,6 +2788,11 @@ Target supports a ctz optab on long.
 @item ctzll
 Target supports a ctz optab on long long.
 
+@item ctzsi
+Target has a @code{ctzsi2} pattern, which can be an expander, so a
+@code{.CTZ} internal function call on a 32-bit unsigned integer can be
+expanded.
+
 @item cmpccxadd
 Target supports the execution of @code{cmpccxadd} instructions.
 
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index a75c2c51e7e4..ee6343b38ebe 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -10761,6 +10761,46 @@ proc check_effective_target_ctzll { } {
     } "" ]
 }
 
+# Return 1 if the target has a clzsi2 pattern, so that a .CLZ call on
+# a 32-bit unsigned integer can be expanded.  The pattern can be an
+# expander that uses other operations.  Niter analysis turns the loop
+# into such a call only in that case.
+
+proc check_effective_target_clzsi { } {
+    return [check_no_messages_and_pattern clzsi "\\.CLZ \\(" tree-optimized {
+       int foo (__UINT32_TYPE__ b)
+         {
+           int c = 0;
+           while (b)
+             {
+               b >>= 1;
+               c++;
+             }
+           return c;
+         }
+    } "-O2" ]
+}
+
+# Return 1 if the target has a ctzsi2 pattern, so that a .CTZ call on
+# a 32-bit unsigned integer can be expanded.  The pattern can be an
+# expander that uses other operations.  Niter analysis turns the loop
+# into such a call only in that case.
+
+proc check_effective_target_ctzsi { } {
+    return [check_no_messages_and_pattern ctzsi "\\.CTZ \\(" tree-optimized {
+       int foo (__UINT32_TYPE__ b)
+         {
+           int c = 0;
+           while (b)
+             {
+               b <<= 1;
+               c++;
+             }
+           return c;
+         }
+    } "-O2" ]
+}
+
 # Return 1 if the target supports atomic operations on "long long"
 # and can execute them.
 #

Reply via email to