[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

[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)

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

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |rguenth at gcc dot 
gnu.org
   Target Milestone|16.0|15.2
   Priority|P3  |P2

--- Comment #7 from Richard Biener  ---
I will have a look somewhen later this week.

[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)

2025-07-13 Thread rguenther at suse dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121059

--- Comment #6 from rguenther at suse dot de  ---
On Mon, 14 Jul 2025, pinskia at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121059
> 
> Andrew Pinski  changed:
> 
>What|Removed |Added
> 
>  Ever confirmed|0   |1
>   Known to work||14.3.0
>  Status|UNCONFIRMED |NEW
>   Known to fail||15.1.0
>Last reconfirmed||2025-07-14
>Keywords||needs-bisection
> 
> --- Comment #5 from Andrew Pinski  ---
> (In reply to Sam James from comment #4)
> > (In reply to Sam James from comment #2)
> > > Created attachment 61857 [details]
> > > reduced.i
> > > 
> > > bisecting
> > 
> > r16-2088-ge9079e4f43d135 but given my luck with going back further in the
> > other bug, I won't bother here
> 
> `-O3 -march=x86-64-v4 --param vect-partial-vector-usage=1` ICEs for GCC 15.1.0
> also. But works in GCC 14.3.0.

It's good we get some more coverage for masked epilogue vect now, but
yeah - this was expected to some extent ...