On Thu, Sep 03, 2026 at 04:21:32AM +0100, Alice Carlotti wrote:
> Thanks - I've added this missing line:
> (svpfalse_impl::fold): Handle svcount_t.
>
> and pushed it to master. I'll also push it to the affected branches after
> waiting a bit.
>
> Alice
I've backported this to gcc-16 and gcc-15 (with the ChangeLog tweaked to
mention aarch64-sve-builtins.cc instead). For gcc-14, a couple more changes
are needed:
- The folding for svcount_t uses fold_call_to, which was added in
r15-5957-g5289540ed58e42. I've dropped that change, so it now punts for
svcount_t (which is closer to the existing behaviour).
- The intrinsics were originally added for sme2 in gcc-14, but the tests use
sve2p1, which was added in gcc-15. I've dropped the tests here.
Is this ok for the gcc-14 backport?
---
This fixes an ICE that occurred when trying to fold svwhilelt and
svwhilele predicate-as-counter builtins as if they were
predicate-as-mask builtins.
gcc/ChangeLog:
PR target/126096
* config/aarch64/aarch64-sve-builtins.cc
(gimple_folder::fold_to_pfalse): Punt for svcount_t.
* config/aarch64/aarch64-sve-builtins-base.cc
(svpfalse_impl::fold): Defer svcount_t check.
(svwhilelx_impl::fold_type): Punt for svcount_t.
diff --git a/gcc/config/aarch64/aarch64-sve-builtins-base.cc
b/gcc/config/aarch64/aarch64-sve-builtins-base.cc
index
05ef1c1dcb363a4c0bfdc9c76378f9db47899448..b76cb5ecaa93c471792695bd5664677f41fc88a5
100644
--- a/gcc/config/aarch64/aarch64-sve-builtins-base.cc
+++ b/gcc/config/aarch64/aarch64-sve-builtins-base.cc
@@ -2041,10 +2041,7 @@ public:
gimple *
fold (gimple_folder &f) const override
{
- if (f.type_suffix (0).tclass == TYPE_bool)
- return f.fold_to_pfalse ();
-
- return nullptr;
+ return f.fold_to_pfalse ();
}
rtx
@@ -2907,6 +2904,10 @@ public:
if (m_eq_p ? known_gt (arg0, arg1) : known_ge (arg0, arg1))
return f.fold_to_pfalse ();
+ /* Punt if we are trying to fold a predicate-as-counter builtin. */
+ if (f.type_suffix (0).tclass == TYPE_count)
+ return NULL;
+
/* Punt if we can't tell at compile time whether the result
is all-false. */
if (m_eq_p ? maybe_gt (arg0, arg1) : maybe_ge (arg0, arg1))
diff --git a/gcc/config/aarch64/aarch64-sve-builtins.cc
b/gcc/config/aarch64/aarch64-sve-builtins.cc
index
6416c18e15e5e6409bd7d294bd3904909591d97b..363b05ac02beed19d01f5c4b87adc8a2c4d78ea1
100644
--- a/gcc/config/aarch64/aarch64-sve-builtins.cc
+++ b/gcc/config/aarch64/aarch64-sve-builtins.cc
@@ -3565,7 +3565,16 @@ gimple_folder::fold_to_ptrue ()
gimple *
gimple_folder::fold_to_pfalse ()
{
- return gimple_build_assign (lhs, build_zero_cst (TREE_TYPE (lhs)));
+ if (type_suffix (0).tclass == TYPE_bool)
+ return gimple_build_assign (lhs, build_zero_cst (TREE_TYPE (lhs)));
+
+ if (type_suffix (0).tclass == TYPE_count)
+ {
+ tree svbool_type = abi_vector_types[VECTOR_TYPE_svbool_t];
+ return fold_call_to (build_zero_cst (svbool_type));
+ }
+
+ return NULL;
}
/* Fold an operation to a constant predicate in which the first VL