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?

Reply via email to