public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592
@ 2024-09-02 12:14 ktkachov at gcc dot gnu.org
  2024-09-02 12:14 ` [Bug tree-optimization/116569] " ktkachov at gcc dot gnu.org
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: ktkachov at gcc dot gnu.org @ 2024-09-02 12:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

            Bug ID: 116569
           Summary: [15 Regression] ICE in to_constant, at poly-int.h:592
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: aarch64-sve, ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---
            Target: aarch64

int a;
short b, c, e;
long d, f;
long g(long h) {
  if (h)
    return h;
  return d;
}
void i(int h[][0][0][0]) {
  for (short j; j; j += 3) {
    a = g(h[1][2] ? 0 : h[1][1][1][1]);
    b = e ?: f % c;
  }
}

with -O3 -mcpu=neoverse-v2 ICEs with trunk:
0x24ef04b internal_error(char const*, ...)
        $SRC/gcc/diagnostic-global-context.cc:492
0x80ebd7 fancy_abort(char const*, int, char const*)
        $SRC/gcc/diagnostic.cc:1658
0x7fcc03 poly_int<2u, unsigned long>::to_constant() const
        $SRC/gcc/poly-int.h:592
0x1589ae7 poly_int<2u, unsigned long>::to_constant() const
        $SRC/gcc/poly-int.h:590
0x1589ae7 nunits_for_known_piecewise_op
        $SRC/gcc/tree-vect-generic.cc:96
0x1589ae7 expand_vector_piecewise
        $SRC/gcc/tree-vect-generic.cc:290
0x158c673 expand_vector_operation
        $SRC/gcc/tree-vect-generic.cc:1257
0x158d657 expand_vector_operations_1
        $SRC/gcc/tree-vect-generic.cc:2366
0x158d657 expand_vector_operations
        $SRC/gcc/tree-vect-generic.cc:2400
0x158d657 execute
        $SRC/gcc/tree-vect-generic.cc:2454

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
@ 2024-09-02 12:14 ` ktkachov at gcc dot gnu.org
  2024-09-02 13:03 ` acoplan at gcc dot gnu.org
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: ktkachov at gcc dot gnu.org @ 2024-09-02 12:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

ktkachov at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |15.0

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
  2024-09-02 12:14 ` [Bug tree-optimization/116569] " ktkachov at gcc dot gnu.org
@ 2024-09-02 13:03 ` acoplan at gcc dot gnu.org
  2024-09-02 13:51 ` rguenth at gcc dot gnu.org
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: acoplan at gcc dot gnu.org @ 2024-09-02 13:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

Alex Coplan <acoplan at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-09-02
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
                 CC|                            |acoplan at gcc dot gnu.org,
                   |                            |jschmitz at gcc dot gnu.org

--- Comment #1 from Alex Coplan <acoplan at gcc dot gnu.org> ---
Confirmed.  Started with r15-3082-g9bbad3685131ec95d970f81bf75f9556d4d92742.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
  2024-09-02 12:14 ` [Bug tree-optimization/116569] " ktkachov at gcc dot gnu.org
  2024-09-02 13:03 ` acoplan at gcc dot gnu.org
@ 2024-09-02 13:51 ` rguenth at gcc dot gnu.org
  2024-09-02 21:57 ` pinskia at gcc dot gnu.org
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-09-02 13:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Apparently the vectorizer introduces ops that are not supported by the target. 
Or vector lowering indentifes them wrong.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-09-02 13:51 ` rguenth at gcc dot gnu.org
@ 2024-09-02 21:57 ` pinskia at gcc dot gnu.org
  2024-09-06  4:10 ` pinskia at gcc dot gnu.org
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-09-02 21:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #2)
> Apparently the vectorizer introduces ops that are not supported by the
> target.  Or vector lowering indentifes them wrong.

Or rather match-and-simplify puts it back together:
Applying pattern match.pd:5024, gimple-match-6.cc:5803
Applying pattern match.pd:898, gimple-match-9.cc:1334
gimple_simplified to _282 = vect_cst__192 % vect_cst__193;
vect_patt_106.24_204 = _282;

Match pattern:
```
/* X - (X / Y) * Y is the same as X % Y.  */
(simplify
 (minus (convert1? @0) (convert2? (mult:c (trunc_div @@0 @@1) @1)))
 (if (INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type))
  (convert (trunc_mod @0 @1))))
```

I think we need to add a check to make sure we support the mod optab here (for
after the lowering). I also think veclowering should also lower % case too (for
general vector usage too).

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2024-09-02 21:57 ` pinskia at gcc dot gnu.org
@ 2024-09-06  4:10 ` pinskia at gcc dot gnu.org
  2024-09-06  9:23 ` jschmitz at gcc dot gnu.org
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-09-06  4:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kugan at gcc dot gnu.org

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 116626 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2024-09-06  4:10 ` pinskia at gcc dot gnu.org
@ 2024-09-06  9:23 ` jschmitz at gcc dot gnu.org
  2024-09-06  9:28 ` pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: jschmitz at gcc dot gnu.org @ 2024-09-06  9:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

--- Comment #5 from Jennifer Schmitz <jschmitz at gcc dot gnu.org> ---
I looked into the issue and summarize below what I found:

My current fix that checks for the support of the mod optab for vectors looks
like this:

@@ -894,7 +894,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* X - (X / Y) * Y is the same as X % Y.  */
 (simplify
  (minus (convert1? @0) (convert2? (mult:c (trunc_div @@0 @@1) @1)))
- (if (INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type))
+ (if (INTEGRAL_TYPE_P (type)
+      || (VECTOR_INTEGER_TYPE_P (type)
+         && target_supports_op_p (type, TRUNC_MOD_EXPR, optab_vector)))
   (convert (trunc_mod @0 @1))))

However, the test fold-minus-1.c fails, because the simplification is not
applied anymore:

/* { dg-options "-O -fdump-tree-gimple" } */
void f(vec*x,vec*y){
  *x -= *x / *y * *y;
}

/* { dg-final { scan-tree-dump-times "%" 1 "gimple"} } */
/* { dg-final { scan-tree-dump-not "/" "gimple"} } */

I looked into applying the simplification in early tree passes only instead of
checking for support of the mod optab and found functions like
optimize_vectors_before_lowering_p that use the PROP_gimple_xxx macros (in
tree-pass.h) as mask.

I tried different PROP_xxx macros and all tests (fold-minus-1.c; the minimal
testcase Kyrill posted that produced the ICE; and my previous vect-mod tests)
run successfully for

@@ -896,7 +896,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (minus (convert1? @0) (convert2? (mult:c (trunc_div @@0 @@1) @1)))
  (if (INTEGRAL_TYPE_P (type)
       || (VECTOR_INTEGER_TYPE_P (type)
-         && target_supports_op_p (type, TRUNC_MOD_EXPR, optab_vector)))
+         && (!cfun || (cfun->curr_properties & PROP_gimple_any) == 0)))
   (convert (trunc_mod @0 @1))))

But I don't think that the PROP_gimple_any is exactly what I want, but I
haven't found anything that fits perfectly.

Any advise on how to proceed?

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2024-09-06  9:23 ` jschmitz at gcc dot gnu.org
@ 2024-09-06  9:28 ` pinskia at gcc dot gnu.org
  2024-09-06  9:35 ` jschmitz at gcc dot gnu.org
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-09-06  9:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Try optimize_vectors_before_lowering_p () like what is used a few other places.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2024-09-06  9:28 ` pinskia at gcc dot gnu.org
@ 2024-09-06  9:35 ` jschmitz at gcc dot gnu.org
  2024-09-06  9:37 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: jschmitz at gcc dot gnu.org @ 2024-09-06  9:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

--- Comment #7 from Jennifer Schmitz <jschmitz at gcc dot gnu.org> ---
Thanks for the quick reply. I tried

(simplify
 (minus (convert1? @0) (convert2? (mult:c (trunc_div @@0 @@1) @1)))
 (if (INTEGRAL_TYPE_P (type)
      || (VECTOR_INTEGER_TYPE_P (type)
          && optimize_vectors_before_lowering_p ()))
  (convert (trunc_mod @0 @1))))

and the result is that the test case still ICEs, but fold-minus-1.c passes.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2024-09-06  9:35 ` jschmitz at gcc dot gnu.org
@ 2024-09-06  9:37 ` pinskia at gcc dot gnu.org
  2024-09-06  9:41 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-09-06  9:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jennifer Schmitz from comment #7)
> Thanks for the quick reply. I tried
> 
> (simplify
>  (minus (convert1? @0) (convert2? (mult:c (trunc_div @@0 @@1) @1)))
>  (if (INTEGRAL_TYPE_P (type)
>       || (VECTOR_INTEGER_TYPE_P (type)
>           && optimize_vectors_before_lowering_p ()))
>   (convert (trunc_mod @0 @1))))
> 
> and the result is that the test case still ICEs, but fold-minus-1.c passes.

Try:
INTEGRAL_TYPE_P (type)
|| (VECTOR_INTEGER_TYPE_P (type)
    && (optimize_vectors_before_lowering_p ()
        || target_supports_op_p (type, TRUNC_MOD_EXPR, optab_vector)))

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2024-09-06  9:37 ` pinskia at gcc dot gnu.org
@ 2024-09-06  9:41 ` pinskia at gcc dot gnu.org
  2024-09-06  9:52 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-09-06  9:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #8)
> (In reply to Jennifer Schmitz from comment #7)
> > Thanks for the quick reply. I tried
> > 
> > (simplify
> >  (minus (convert1? @0) (convert2? (mult:c (trunc_div @@0 @@1) @1)))
> >  (if (INTEGRAL_TYPE_P (type)
> >       || (VECTOR_INTEGER_TYPE_P (type)
> >           && optimize_vectors_before_lowering_p ()))
> >   (convert (trunc_mod @0 @1))))
> > 
> > and the result is that the test case still ICEs, but fold-minus-1.c passes.
> 
> Try:
> INTEGRAL_TYPE_P (type)
> || (VECTOR_INTEGER_TYPE_P (type)
>     && (optimize_vectors_before_lowering_p ()
>         || target_supports_op_p (type, TRUNC_MOD_EXPR, optab_vector)))

Oh wait the problem is this is before lowering but SVE vectors can't be
lowered.

I think maybe the lowering pass should handle the case where:
!target_supports_op_p (type, TRUNC_MOD_EXPR, optab_vector) &&
target_supports_op_p (type, TRUNC_DIV_EXPR, optab_vector) &&
target_supports_op_p (type, MULT_EXPR, optab_vector) && target_supports_op_p
(type, MINUS_EXPR, optab_vector)

And expand TRUNC_MOD_EXPR there.

I am thinking about adding a similar thing for MIN/MAX too.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2024-09-06  9:41 ` pinskia at gcc dot gnu.org
@ 2024-09-06  9:52 ` pinskia at gcc dot gnu.org
  2024-09-06 10:12 ` ktkachov at gcc dot gnu.org
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-09-06  9:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #9)
> Oh wait the problem is this is before lowering but SVE vectors can't be
> lowered.
> 
> I think maybe the lowering pass should handle the case where:
> !target_supports_op_p (type, TRUNC_MOD_EXPR, optab_vector) &&
> target_supports_op_p (type, TRUNC_DIV_EXPR, optab_vector) &&
> target_supports_op_p (type, MULT_EXPR, optab_vector) && target_supports_op_p
> (type, MINUS_EXPR, optab_vector)


That would also help if you add that lowering to vect lowering:
```
#define vect16 __attribute__((vector_size(16)))
vect16 unsigned g(vect16 unsigned a, vect16 unsigned b)
{
        return a % b;
}
```

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
                   ` (10 preceding siblings ...)
  2024-09-06  9:52 ` pinskia at gcc dot gnu.org
@ 2024-09-06 10:12 ` ktkachov at gcc dot gnu.org
  2024-09-06 11:22 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: ktkachov at gcc dot gnu.org @ 2024-09-06 10:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

ktkachov at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu.org

--- Comment #11 from ktkachov at gcc dot gnu.org ---
(In reply to Andrew Pinski from comment #9)
> (In reply to Andrew Pinski from comment #8)
> > (In reply to Jennifer Schmitz from comment #7)
> > > Thanks for the quick reply. I tried
> > > 
> > > (simplify
> > >  (minus (convert1? @0) (convert2? (mult:c (trunc_div @@0 @@1) @1)))
> > >  (if (INTEGRAL_TYPE_P (type)
> > >       || (VECTOR_INTEGER_TYPE_P (type)
> > >           && optimize_vectors_before_lowering_p ()))
> > >   (convert (trunc_mod @0 @1))))
> > > 
> > > and the result is that the test case still ICEs, but fold-minus-1.c passes.
> > 
> > Try:
> > INTEGRAL_TYPE_P (type)
> > || (VECTOR_INTEGER_TYPE_P (type)
> >     && (optimize_vectors_before_lowering_p ()
> >         || target_supports_op_p (type, TRUNC_MOD_EXPR, optab_vector)))
> 
> Oh wait the problem is this is before lowering but SVE vectors can't be
> lowered.
> 
> I think maybe the lowering pass should handle the case where:
> !target_supports_op_p (type, TRUNC_MOD_EXPR, optab_vector) &&
> target_supports_op_p (type, TRUNC_DIV_EXPR, optab_vector) &&
> target_supports_op_p (type, MULT_EXPR, optab_vector) && target_supports_op_p
> (type, MINUS_EXPR, optab_vector)
> 
> And expand TRUNC_MOD_EXPR there.
> 
> I am thinking about adding a similar thing for MIN/MAX too.

I don't think we have other lowering of SVE ops in the veclower, is that
something we want to start doing now?

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
                   ` (11 preceding siblings ...)
  2024-09-06 10:12 ` ktkachov at gcc dot gnu.org
@ 2024-09-06 11:22 ` rguenth at gcc dot gnu.org
  2024-09-06 11:23 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-09-06 11:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

--- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> (In reply to Richard Biener from comment #2)
> > Apparently the vectorizer introduces ops that are not supported by the
> > target.  Or vector lowering indentifes them wrong.
> 
> Or rather match-and-simplify puts it back together:
> Applying pattern match.pd:5024, gimple-match-6.cc:5803
> Applying pattern match.pd:898, gimple-match-9.cc:1334
> gimple_simplified to _282 = vect_cst__192 % vect_cst__193;
> vect_patt_106.24_204 = _282;
> 
> Match pattern:
> ```
> /* X - (X / Y) * Y is the same as X % Y.  */
> (simplify
>  (minus (convert1? @0) (convert2? (mult:c (trunc_div @@0 @@1) @1)))
>  (if (INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type))
>   (convert (trunc_mod @0 @1))))
> ```
> 
> I think we need to add a check to make sure we support the mod optab here
> (for after the lowering).

Yes.

> I also think veclowering should also lower % case
> too (for general vector usage too).

Yeah, but isn't that handled by generic binop code?

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
                   ` (12 preceding siblings ...)
  2024-09-06 11:22 ` rguenth at gcc dot gnu.org
@ 2024-09-06 11:23 ` rguenth at gcc dot gnu.org
  2024-09-18 11:07 ` cvs-commit at gcc dot gnu.org
  2024-09-18 11:09 ` jschmitz at gcc dot gnu.org
  15 siblings, 0 replies; 17+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-09-06 11:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

--- Comment #13 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to ktkachov from comment #11)
> (In reply to Andrew Pinski from comment #9)
> > (In reply to Andrew Pinski from comment #8)
> > > (In reply to Jennifer Schmitz from comment #7)
> > > > Thanks for the quick reply. I tried
> > > > 
> > > > (simplify
> > > >  (minus (convert1? @0) (convert2? (mult:c (trunc_div @@0 @@1) @1)))
> > > >  (if (INTEGRAL_TYPE_P (type)
> > > >       || (VECTOR_INTEGER_TYPE_P (type)
> > > >           && optimize_vectors_before_lowering_p ()))
> > > >   (convert (trunc_mod @0 @1))))
> > > > 
> > > > and the result is that the test case still ICEs, but fold-minus-1.c passes.
> > > 
> > > Try:
> > > INTEGRAL_TYPE_P (type)
> > > || (VECTOR_INTEGER_TYPE_P (type)
> > >     && (optimize_vectors_before_lowering_p ()
> > >         || target_supports_op_p (type, TRUNC_MOD_EXPR, optab_vector)))
> > 
> > Oh wait the problem is this is before lowering but SVE vectors can't be
> > lowered.
> > 
> > I think maybe the lowering pass should handle the case where:
> > !target_supports_op_p (type, TRUNC_MOD_EXPR, optab_vector) &&
> > target_supports_op_p (type, TRUNC_DIV_EXPR, optab_vector) &&
> > target_supports_op_p (type, MULT_EXPR, optab_vector) && target_supports_op_p
> > (type, MINUS_EXPR, optab_vector)
> > 
> > And expand TRUNC_MOD_EXPR there.
> > 
> > I am thinking about adding a similar thing for MIN/MAX too.
> 
> I don't think we have other lowering of SVE ops in the veclower, is that
> something we want to start doing now?

No, I think you can only get there with intrinsics in which case it's the
users fault?  GCC generic vectors do not support variable-length vectors IIRC.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
                   ` (13 preceding siblings ...)
  2024-09-06 11:23 ` rguenth at gcc dot gnu.org
@ 2024-09-18 11:07 ` cvs-commit at gcc dot gnu.org
  2024-09-18 11:09 ` jschmitz at gcc dot gnu.org
  15 siblings, 0 replies; 17+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-09-18 11:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

--- Comment #14 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jennifer Schmitz <jschmitz@gcc.gnu.org>:

https://gcc.gnu.org/g:6f3b6a451771cd54c98768e7db3c5d58aab2b6aa

commit r15-3683-g6f3b6a451771cd54c98768e7db3c5d58aab2b6aa
Author: Jennifer Schmitz <jschmitz@nvidia.com>
Date:   Thu Sep 5 08:10:02 2024 -0700

    match.pd: Check trunc_mod vector obtap before folding.

    In the pattern X - (X / Y) * Y to X % Y, this patch guards the
    simplification for vector types by a check for:
    1) Support of the mod optab for vectors OR
    2) Application before vector lowering for non-VL vectors.
    This is to prevent reverting vectorization of modulo to div/mult/sub
    if the target does not support vector mod optab.

    The patch was bootstrapped and tested with no regression on
    aarch64-linux-gnu and x86_64-linux-gnu.
    OK for mainline?

    Signed-off-by: Jennifer Schmitz <jschmitz@nvidia.com>

    gcc/
            PR tree-optimization/116569
            * match.pd: Guard simplification to trunc_mod with check for
            mod optab support.

    gcc/testsuite/
            PR tree-optimization/116569
            * gcc.dg/torture/pr116569.c: New test.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug tree-optimization/116569] [15 Regression] ICE in to_constant, at poly-int.h:592
  2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
                   ` (14 preceding siblings ...)
  2024-09-18 11:07 ` cvs-commit at gcc dot gnu.org
@ 2024-09-18 11:09 ` jschmitz at gcc dot gnu.org
  15 siblings, 0 replies; 17+ messages in thread
From: jschmitz at gcc dot gnu.org @ 2024-09-18 11:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116569

Jennifer Schmitz <jschmitz at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #15 from Jennifer Schmitz <jschmitz at gcc dot gnu.org> ---
fixed in GCC 15.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-09-18 11:09 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-02 12:14 [Bug tree-optimization/116569] New: [15 Regression] ICE in to_constant, at poly-int.h:592 ktkachov at gcc dot gnu.org
2024-09-02 12:14 ` [Bug tree-optimization/116569] " ktkachov at gcc dot gnu.org
2024-09-02 13:03 ` acoplan at gcc dot gnu.org
2024-09-02 13:51 ` rguenth at gcc dot gnu.org
2024-09-02 21:57 ` pinskia at gcc dot gnu.org
2024-09-06  4:10 ` pinskia at gcc dot gnu.org
2024-09-06  9:23 ` jschmitz at gcc dot gnu.org
2024-09-06  9:28 ` pinskia at gcc dot gnu.org
2024-09-06  9:35 ` jschmitz at gcc dot gnu.org
2024-09-06  9:37 ` pinskia at gcc dot gnu.org
2024-09-06  9:41 ` pinskia at gcc dot gnu.org
2024-09-06  9:52 ` pinskia at gcc dot gnu.org
2024-09-06 10:12 ` ktkachov at gcc dot gnu.org
2024-09-06 11:22 ` rguenth at gcc dot gnu.org
2024-09-06 11:23 ` rguenth at gcc dot gnu.org
2024-09-18 11:07 ` cvs-commit at gcc dot gnu.org
2024-09-18 11:09 ` jschmitz at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).