]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tailcall: Fix up process_assignment [PR94001]
authorJakub Jelinek <jakub@redhat.com>
Wed, 4 Mar 2020 08:01:59 +0000 (09:01 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 17 Mar 2020 17:01:13 +0000 (18:01 +0100)
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.

2020-03-04  Jakub Jelinek  <jakub@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/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr94001.c [new file with mode: 0644]
gcc/tree-tailcall.c

index ec0284ad8beeb3be6e62e79b3148b99102ef5ca0..3e93b3ae62b9974601eb0f1cda224086456957ef 100644 (file)
@@ -1,3 +1,12 @@
+2020-03-17  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2020-03-04  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/94001
+       * tree-tailcall.c (process_assignment): Before comparing op1 to
+       *ass_var, verify *ass_var is non-NULL.
+
 2020-03-13  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/94163
index 555d9965efd76510b405702ac6a6f86363123c88..bbc3bef437f358afb7b133bdbfe3aa4233dc068e 100644 (file)
@@ -1,3 +1,11 @@
+2020-03-17  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2020-03-04  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/94001
+       * gcc.dg/pr94001.c: New test.
+
 2020-03-17  Kewen Lin  <linkw@gcc.gnu.org>
 
        Backport from master
diff --git a/gcc/testsuite/gcc.dg/pr94001.c b/gcc/testsuite/gcc.dg/pr94001.c
new file mode 100644 (file)
index 0000000..f83873f
--- /dev/null
@@ -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;
+}
index 255575f1198aeeb7504d68af490adc15c57b62ce..4f42817f7de2e98881969072db5d568b0c1de56c 100644 (file)
@@ -327,7 +327,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)))
     ;