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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
I _think_ that in this particular case (and maybe others) we can avoid the
issue by not telling ISL anything about s4 -- this means treating s4 += xn
(which has
associated PHIs and loop-closed PHIs) as black-boxes.  This probably also means
we can't handle the if (s4 != 0) stmt in itself (we'd need to treat the
sub-CFG controlled by it as black-box).

So in the end this requires re-writing what GRAPHITE associates with a
black-box,
aka ISL user stmt, making it not only possibly sub-BB granular but also
possibly
covering more than one BB (and in case there is no dependence the black boxes
might even overlap in the original GIMPLE - but a valid pre-transform would be
to re-schedule GIMPLE stmts to make them non-overlapping).

That said, the issue is the following original AST:

[scheduler] original ast:
for (int c0 = 0; c0 < -P_2; c0 += 1) {
  S_4(c0);
  for (int c1 = 0; c1 <= 2; c1 += 1)
    S_5(c0, c1);
  S_16(c0);
  if (P_19 + 6 * c0 == 18446744073709551610)
    S_9((-P_19 + 18446744073709551610) / 6);
  S_10(c0);
}

where the if in the AST is from

<bb 4> [local count: 39370534]:
# ns.1_30 = PHI <ns.1_2(3), _8(12)>
# s4_29 = PHI <s4_19(D)(3), s4_22(12)>
# b2_31 = PHI <&ns(3), b2_13(12)>
...

<bb 16> [local count: 39370534]:
s4_22 = s4_29 + 6;
if (s4_22 != 0)
  goto <bb 10>; [50.00%]
else
  goto <bb 9>; [50.00%]

and the scalar evolution of s4_22 in the region is {s4_19(D) + 6, +, 6}_1.
Looks like the zero test is obfuscated a bit ... the pw_aff for s4_22 is

[P_2, P_19] -> { S_9[i1] -> [(6 + P_19 + 6i1 - 18446744073709551616*floor((6 +
P_19 + 6i1)/18446744073709551616))] }

where the obfuscation is from the chrec initial value s4_19(D) + 6 which
is computed in unsigned arithmetic and thus has to properly support
wrapping.

One thing would be to do more clever pattern matching during code-generation
handling for no-ops.  In this particular case

Index: gcc/graphite-isl-ast-to-gimple.c
===================================================================
--- gcc/graphite-isl-ast-to-gimple.c    (revision 256977)
+++ gcc/graphite-isl-ast-to-gimple.c    (working copy)
@@ -326,7 +326,8 @@ binary_op_to_tree (tree type, __isl_take
   /* From our constraint generation we may get modulo operations that
      we cannot represent explicitely but that are no-ops for TYPE.
      Elide those.  */
-  if (expr_type == isl_ast_op_pdiv_r
+  if ((expr_type == isl_ast_op_pdiv_r
+       || expr_type == isl_ast_op_add)
       && isl_ast_expr_get_type (arg_expr) == isl_ast_expr_int
       && (wi::exact_log2 (widest_int_from_isl_expr_int (arg_expr))
          >= TYPE_PRECISION (type)))

is a fix.

Reply via email to