[Bug tree-optimization/121059] [15/16 regression] ICE when building imagemagick-7.1.1-47 (vect_get_loop_mask, at tree-vect-loop.cc:10960) since r15-5383-g8f68d9cb7897df

2025-07-15 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121059

--- Comment #16 from GCC Commits  ---
The master branch has been updated by Richard Biener :

https://gcc.gnu.org/g:71be87055548cf942c7bc56d10ffd479db8569e4

commit r16-2259-g71be87055548cf942c7bc56d10ffd479db8569e4
Author: Richard Biener 
Date:   Mon Jul 14 14:09:28 2025 +0200

tree-optimization/121059 - fixup loop mask query

When we opportunistically mask an operand of a AND with an already
available loop mask we need to query that set with the correct number
of masks we expect.

PR tree-optimization/121059
* tree-vect-stmts.cc (vectorizable_operation): Query
scalar_cond_masked_set with the correct number of masks.

* gcc.dg/vect/pr121059.c: New testcase.

Co-Authored-By: Richard Sandiford  

[Bug tree-optimization/121059] [15/16 regression] ICE when building imagemagick-7.1.1-47 (vect_get_loop_mask, at tree-vect-loop.cc:10960) since r15-5383-g8f68d9cb7897df

2025-07-14 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121059

Richard Biener  changed:

   What|Removed |Added

Summary|[15 regression] ICE when|[15/16 regression] ICE when
   |building|building
   |imagemagick-7.1.1-47|imagemagick-7.1.1-47
   |(vect_get_loop_mask, at |(vect_get_loop_mask, at
   |tree-vect-loop.cc:10960)|tree-vect-loop.cc:10960)
   |since   |since
   |r15-5383-g8f68d9cb7897df|r15-5383-g8f68d9cb7897df
  Known to work|16.0|

--- Comment #15 from Richard Biener  ---
Fix was reverted.

[Bug tree-optimization/121059] [15/16 regression] ICE when building imagemagick-7.1.1-47 (vect_get_loop_mask, at tree-vect-loop.cc:10960) since r15-5383-g8f68d9cb7897df

2025-07-14 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121059

--- Comment #12 from GCC Commits  ---
The master branch has been updated by Richard Biener :

https://gcc.gnu.org/g:66346b6d800fc4baae876e0fe4e932401bcc85fa

commit r16-2236-g66346b6d800fc4baae876e0fe4e932401bcc85fa
Author: Richard Biener 
Date:   Mon Jul 14 14:09:28 2025 +0200

tree-optimization/121059 - record loop mask when required

For loop masking we need to mask a mask AND operation with the loop
mask.  The following makes sure we have a corresponding mask
available.  There's no good way to distinguish loop masking from
len masking here, so assume we have recorded a mask for the operands
mask producers.

PR tree-optimization/121059
* tree-vect-stmts.cc (vectorizable_operation): Record a
loop mask for mask AND operations.

* gcc.dg/vect/pr121059.c: New testcase.

[Bug tree-optimization/121059] [15/16 regression] ICE when building imagemagick-7.1.1-47 (vect_get_loop_mask, at tree-vect-loop.cc:10960) since r15-5383-g8f68d9cb7897df

2025-07-14 Thread rsandifo at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121059

--- Comment #11 from Richard Sandiford  ---
>   if (masked_loop_p
>   && code == BIT_AND_EXPR
>   && VECTOR_BOOLEAN_TYPE_P (vectype))
> {
>   if (loop_vinfo->scalar_cond_masked_set.contains ({ op0, 1 }))
> {
>   mask = vect_get_loop_mask (loop_vinfo, gsi, masks,
>  vec_num, vectype, i);
I think the bug is the hard-coded 1 for SLP.  It should be vec_num instead, to
match the vect_get_loop_len argument.  The ICE occurs in a 4-vector operation
rather than a 1-vector operation.

[Bug tree-optimization/121059] [15/16 regression] ICE when building imagemagick-7.1.1-47 (vect_get_loop_mask, at tree-vect-loop.cc:10960) since r15-5383-g8f68d9cb7897df

2025-07-14 Thread rsandifo at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121059

--- Comment #10 from Richard Sandiford  ---
(In reply to Richard Biener from comment #9)
> vectorizable_operation during transform does
> 
>   /* When combining two masks check if either of them is elsewhere
>  combined with a loop mask, if that's the case we can mark that
> the
>  new combined mask doesn't need to be combined with a loop mask.
> */
>   if (masked_loop_p
>   && code == BIT_AND_EXPR
>   && VECTOR_BOOLEAN_TYPE_P (vectype))
> {
>   if (loop_vinfo->scalar_cond_masked_set.contains ({ op0, 1 }))
> {
>   mask = vect_get_loop_mask (loop_vinfo, gsi, masks,
>  vec_num, vectype, i);
> 
> but that's not reflected by analysis, which misses to record a loop mask
> for !mask_out_inactive operations.  So the fix is as simple as the following,
> but this might put us to using masks?  There is no good way to do this
> I guess.  The scalar_cond_masked_set optimization does not have a
> corresponding
> len operation.  I'm not sure what we can do here?
> 
> diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
> index 4aa69da2218..55002bd0cc2 100644
> --- a/gcc/tree-vect-stmts.cc
> +++ b/gcc/tree-vect-stmts.cc
> @@ -6978,6 +6978,16 @@ vectorizable_operation (vec_info *vinfo,
>   LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
> }
> }
> +  else if (loop_vinfo
> +  && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
> +  && code == BIT_AND_EXPR
> +  && VECTOR_BOOLEAN_TYPE_P (vectype))
> +   vect_record_loop_mask (loop_vinfo, masks, vec_num, vectype, NULL);
>  
>/* Put types on constant and invariant SLP children.  */
>if (!vect_maybe_update_slp_op_vectype (slp_op0, vectype)
Yeah, we shouldn't do that.  The question is why op0 is in
scalar_cond_masked_set with masked_loop_p true if there's no associated loop
mask.

[Bug tree-optimization/121059] [15/16 regression] ICE when building imagemagick-7.1.1-47 (vect_get_loop_mask, at tree-vect-loop.cc:10960) since r15-5383-g8f68d9cb7897df

2025-07-14 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121059

Richard Biener  changed:

   What|Removed |Added

 CC||rsandifo at gcc dot gnu.org

--- Comment #9 from Richard Biener  ---
vectorizable_operation during transform does

  /* When combining two masks check if either of them is elsewhere
 combined with a loop mask, if that's the case we can mark that the
 new combined mask doesn't need to be combined with a loop mask. 
*/
  if (masked_loop_p
  && code == BIT_AND_EXPR
  && VECTOR_BOOLEAN_TYPE_P (vectype))
{
  if (loop_vinfo->scalar_cond_masked_set.contains ({ op0, 1 }))
{
  mask = vect_get_loop_mask (loop_vinfo, gsi, masks,
 vec_num, vectype, i);

but that's not reflected by analysis, which misses to record a loop mask
for !mask_out_inactive operations.  So the fix is as simple as the following,
but this might put us to using masks?  There is no good way to do this
I guess.  The scalar_cond_masked_set optimization does not have a corresponding
len operation.  I'm not sure what we can do here?

diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 4aa69da2218..55002bd0cc2 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -6978,6 +6978,16 @@ vectorizable_operation (vec_info *vinfo,
  LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
}
}
+  else if (loop_vinfo
+  && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
+  && code == BIT_AND_EXPR
+  && VECTOR_BOOLEAN_TYPE_P (vectype))
+   vect_record_loop_mask (loop_vinfo, masks, vec_num, vectype, NULL);

   /* Put types on constant and invariant SLP children.  */
   if (!vect_maybe_update_slp_op_vectype (slp_op0, vectype)

[Bug tree-optimization/121059] [15/16 regression] ICE when building imagemagick-7.1.1-47 (vect_get_loop_mask, at tree-vect-loop.cc:10960) since r15-5383-g8f68d9cb7897df

2025-07-14 Thread sjames at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121059

Sam James  changed:

   What|Removed |Added

 CC||rdapp at gcc dot gnu.org
Summary|[15/16 regression] ICE when |[15/16 regression] ICE when
   |building|building
   |imagemagick-7.1.1-47|imagemagick-7.1.1-47
   |(vect_get_loop_mask, at |(vect_get_loop_mask, at
   |tree-vect-loop.cc:10960)|tree-vect-loop.cc:10960)
   ||since
   ||r15-5383-g8f68d9cb7897df
   Keywords|needs-bisection |

--- Comment #8 from Sam James  ---
r15-5383-g8f68d9cb7897df