Hi!

When a function returns void or the return value is ignored, ass_var
is NULL_TREE.  The tail recursion handling generally assumes DCE has been
performed and so doesn't expect to encounter useless assignments after the
call and expects them to be part of the return value adjustment that need
to be changed into tail recursion additions/multiplications.
process_assignment does some verification and has a way to tell the caller
to try to move dead or whatever other stmts that don't participate in the
return value modifications before it is returned.
For binary rhs assignments it is just fine, neither op0 nor op1 will be
NULL_TREE and thus if *ass_var is NULL_TREE, it will not match, but unary
rhs is handled by only setting op0 to rhs1 and setting op1 to NULL_TREE.
And at this point, NULL_TREE == NULL_TREE and thus we think e.g. the
  c_2 = -e_3(D);
dead stmt is actually a return value modification, so we queue it as
multiplication and then create a void type SSA_NAME accumulator for it
and ICE shortly after.

Fixed by making sure op1 == *ass_var comparison is done only if *ass_var.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2020-03-04  Jakub Jelinek  <ja...@redhat.com>

        PR tree-optimization/94001
        * tree-tailcall.c (process_assignment): Before comparing op1 to
        *ass_var, verify *ass_var is non-NULL.

        * gcc.dg/pr94001.c: New test.

--- gcc/tree-tailcall.c.jj      2020-01-12 11:54:38.517381665 +0100
+++ gcc/tree-tailcall.c 2020-03-03 20:38:54.282458700 +0100
@@ -339,7 +339,8 @@ process_assignment (gassign *stmt,
           && (non_ass_var = independent_of_stmt_p (op1, stmt, call,
                                                    to_move)))
     ;
-  else if (op1 == *ass_var
+  else if (*ass_var
+          && op1 == *ass_var
           && (non_ass_var = independent_of_stmt_p (op0, stmt, call,
                                                    to_move)))
     ;
--- gcc/testsuite/gcc.dg/pr94001.c.jj   2020-03-03 20:40:20.848184911 +0100
+++ gcc/testsuite/gcc.dg/pr94001.c      2020-03-03 20:34:13.415591577 +0100
@@ -0,0 +1,11 @@
+/* PR tree-optimization/94001 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-dce" } */
+
+void
+bar (int e)
+{
+  bar (3);
+  int c;
+  c = -e;
+}

        Jakub

Reply via email to