Bug 65972 - ICE after applying a patch to enable verify_ssa with auto-pgo
Summary: ICE after applying a patch to enable verify_ssa with auto-pgo
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ipa (show other bugs)
Version: 5.1.0
: P3 normal
Target Milestone: ---
Assignee: Martin Liška
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2015-05-01 21:23 UTC by AK
Modified: 2017-05-29 09:16 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 7.0.1
Known to fail: 5.4.0, 6.3.0
Last reconfirmed: 2017-04-18 00:00:00


Attachments
Preprocesed unwind-arm.i (20.27 KB, text/plain)
2015-05-04 15:05 UTC, AK
Details

Note You need to log in before you can comment on or make changes to this bug.
Description AK 2015-05-01 21:23:24 UTC
I was trying to debug a compiler crash while compiling a program with auto-fdo enabled during which the compiler crashed. I could triage the bug to this small case. The issue  here is that ssa is not in a valid form at this point and the compiler analyzes a function for inlining.

diff --git a/gcc/ipa-inline-analysis.c b/gcc/ipa-inline-analysis.c
index 5d99887..d76f396 100644
--- a/gcc/ipa-inline-analysis.c
+++ b/gcc/ipa-inline-analysis.c
@@ -128,6 +128,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "ipa-utils.h"
 #include "cilk.h"
 #include "cfgexpand.h"
+#include "tree-ssa.h"
 
 /* Estimate runtime of function can easilly run into huge numbers with many
    nested loops.  Be sure we can compute time * INLINE_SIZE_SCALE * 2 in an
@@ -2506,6 +2507,7 @@ estimate_function_body_sizes (struct cgraph_node *node, bool early)
      <0,2>.  */
   basic_block bb;
   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
+  verify_ssa (false, true);
   int freq;
   struct inline_summary *info = inline_summaries->get (node);
   struct predicate bb_predicate;



Configured with: ../configure --prefix=../install-crash --enable-shared --enable-static --target=arm-foo-linux-gnueabihf --with-sysroot=/compiler/tools/cross/arm-foo-linux-gnueabihf/gcc-5.1/2015-04-22-222321-2c9bf40-release-5.1/arm-foo-linux-gnueabihf/sysroot --disable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib --with-gmp=/compiler/tools/cross/arm-foo-linux-gnueabihf/gcc-5.1/2015-04-22-222321-2c9bf40-release-5.1 --with-mpfr=/compiler/tools/cross/arm-foo-linux-gnueabihf/gcc-5.1/2015-04-22-222321-2c9bf40-release-5.1 --enable-target-optspace --disable-libquadmath --enable-tls --disable-libmudflap --enable-threads --with-mpc=/compiler/tools/cross/arm-foo-linux-gnueabihf/gcc-5.1/2015-04-22-222321-2c9bf40-release-5.1 --disable-decimal-float --enable-languages=c,c++,lto --with-build-time-tools=/compiler/tools/cross/arm-foo-linux-gnueabihf/gcc-5.1/2015-04-22-222321-2c9bf40-release-5.1/arm-foo-linux-gnueabihf/bin --disable-libgomp --with-pkgversion='Built at foo from commit SHA:2c9bf40, Rev:222321' --with-bugurl=foo+cc@samsung.com --with-abi=aapcs-linux --with-cpu=cortex-a15 --with-fpu=neon --with-float=hard --with-mode=arm --disable-bootstrap --enable-languages=c,c++
Thread model: posix

The compiler crashes like this:

../../../libgcc/config/arm/unwind-arm.c: In function ‘__gnu_unwind_pr_common’:
../../../libgcc/config/arm/unwind-arm.c:511:1: error: virtual definition of statement not up-to-date
 }
 ^
# .MEM_102 = VDEF <.MEM_97>
_103 = _Unwind_decode_typeinfo_ptr.isra.0 (_101);
../../../libgcc/config/arm/unwind-arm.c:511:1: internal compiler error: verify_ssa failed

gcc/build-crash/./gcc/xgcc -Bgcc/build-crash/./gcc/ -Bgcc/build-crash/../install-crash/arm-foo-linux-gnueabihf/bin/ -Bgcc/build-crash/../install-crash/arm-foo-linux-gnueabihf/lib/ -isystem gcc/build-crash/../install-crash/arm-foo-linux-gnueabihf/include -isystem gcc/build-crash/../install-crash/arm-foo-linux-gnueabihf/sys-include    -g -O2 -g -Os -O2  -g -O2 -g -Os -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE  -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include   -fPIC -fno-inline -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector   -fPIC -fno-inline -I. -I. -I../.././gcc -I../../../libgcc -I../../../libgcc/. -I../../../libgcc/../gcc -I../../../libgcc/../include  -DHAVE_CC_TLS  -o unwind-arm.o -MT unwind-arm.o -MD -MP -MF unwind-arm.dep -fexceptions -c ../../../libgcc/config/arm/unwind-arm.c


0xb80500 convert_callers_for_node
        ../../gcc/tree-sra.c:4940
0xb853cb cgraph_node::call_for_symbol_and_aliases(bool (*)(cgraph_node*, void*), void*, bool)
        ../../gcc/cgraph.h:3025
0xb853cb convert_callers
        ../../gcc/tree-sra.c:4955
0xb853cb modify_function
        ../../gcc/tree-sra.c:5011
0xb8e861 ipa_early_sra
        ../../gcc/tree-sra.c:5239
0xb8e861 execute
        ../../gcc/tree-sra.c:5286
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.



make[2]: *** [unwind-arm.o] Error 1
make[2]: *** Waiting for unfinished jobs....
0xc966ab verify_ssa(bool, bool)
        ../../gcc/tree-ssa.c:1068
0x8ef1d0 estimate_function_body_sizes
        ../../gcc/ipa-inline-analysis.c:2510
0x8f1f43 compute_inline_parameters(cgraph_node*, bool)
        ../../gcc/ipa-inline-analysis.c:2973
0xb80500 convert_callers_for_node
        ../../gcc/tree-sra.c:4940
0xb853cb cgraph_node::call_for_symbol_and_aliases(bool (*)(cgraph_node*, void*), void*, bool)
        ../../gcc/cgraph.h:3025
0xb853cb convert_callers
        ../../gcc/tree-sra.c:4955
0xb853cb modify_function
        ../../gcc/tree-sra.c:5011
0xb8e861 ipa_early_sra
        ../../gcc/tree-sra.c:5239
0xb8e861 execute
        ../../gcc/tree-sra.c:5286
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
Comment 1 AK 2015-05-02 14:37:28 UTC
PS: The bootstrap fails after applying this patch and emits the error reported above.
Comment 2 Richard Biener 2015-05-04 10:38:15 UTC
Can you attach preprocessed source for unwind-arm.c?
Comment 3 AK 2015-05-04 15:05:12 UTC
Created attachment 35457 [details]
Preprocesed unwind-arm.i
Comment 4 Sebastian Pop 2015-05-11 22:07:14 UTC
This patch seems to fix the problem:

diff --git a/gcc/auto-profile.c b/gcc/auto-profile.c
index ba2d5ab..6bd296a 100644
--- a/gcc/auto-profile.c
+++ b/gcc/auto-profile.c
@@ -1547,6 +1547,9 @@ afdo_annotate_cfg (const stmt_set &promoted_stmts)
 static void
 early_inline ()
 {
+  /* compute_inline_parameters needs an up to date SSA form.  */
+  update_ssa (TODO_update_ssa);
+
   compute_inline_parameters (cgraph_node::get (current_function_decl), true);
   unsigned todo = early_inliner (cfun);
   if (todo & TODO_update_ssa_any)


We have not verified yet which other pass is causing the SSA to be in an inconsistent state: instead of adding a call to update_ssa() at this place, we should have a verify_ssa(), and fix the other pass.
Comment 5 Dehao Chen 2015-05-14 22:46:15 UTC
Could you try if the following patch fixes the bug?

Thanks,
Dehao

Index: gcc/auto-profile.c
===================================================================
--- gcc/auto-profile.c	(revision 223204)
+++ gcc/auto-profile.c	(working copy)
@@ -1470,6 +1470,7 @@ afdo_vpt_for_early_inline (stmt_set *promoted_stmt
   if (has_vpt)
     {
       optimize_inline_calls (current_function_decl);
+      update_ssa (TODO_update_ssa);
       return true;
     }
Comment 6 AK 2015-05-15 19:17:11 UTC
Your patch did fix the problem. Thanks!
Comment 7 Martin Liška 2017-04-18 15:00:19 UTC
Looks the patch hasn't been applied to trunk. Should I test it and send to ML?
Comment 8 Sebastian Pop 2017-04-18 18:01:55 UTC
Yes please!
This patch also solves the problem I was chasing a week or so ago:

https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00067.html

I also know that this is ICE-ing on a large proprietary project when I compile it with autoFDO on gcc-5.x and 6.x releases.
Comment 9 Sebastian Pop 2017-04-18 18:07:34 UTC
In the link in the previous comment, Richi has a similar patch as suggested by Dehao pending review/test/commit: let's close this bug when Richi's patch lands in trunk.
Comment 10 Martin Liška 2017-04-19 08:14:32 UTC
I'm testing the suggested patch.
Comment 11 Martin Liška 2017-04-19 12:07:08 UTC
Author: marxin
Date: Wed Apr 19 12:06:35 2017
New Revision: 246996

URL: https://gcc.gnu.org/viewcvs?rev=246996&root=gcc&view=rev
Log:
Update SSA after AutoPGO early inlining (PR ipa/65972).

2017-04-19  Richard Biener  <rguenther@suse.de>

	PR ipa/65972
	* auto-profile.c (afdo_vpt_for_early_inline): Update SSA
	when needed by AutoPGO.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/auto-profile.c
Comment 12 Martin Liška 2017-04-19 12:08:59 UTC
Fixed on trunk, queued for active branches.
Comment 13 Martin Liška 2017-05-26 11:32:25 UTC
Author: marxin
Date: Fri May 26 11:31:52 2017
New Revision: 248503

URL: https://gcc.gnu.org/viewcvs?rev=248503&root=gcc&view=rev
Log:
Backport r246996

2017-05-26  Martin Liska  <mliska@suse.cz>

	Backport from mainline
	2017-04-19  Richard Biener  <rguenther@suse.de>

	PR ipa/65972
	* auto-profile.c (afdo_vpt_for_early_inline): Update SSA
	when needed by AutoPGO.

Modified:
    branches/gcc-6-branch/gcc/ChangeLog
    branches/gcc-6-branch/gcc/auto-profile.c
Comment 14 Martin Liška 2017-05-29 09:13:52 UTC
Author: marxin
Date: Mon May 29 09:13:20 2017
New Revision: 248568

URL: https://gcc.gnu.org/viewcvs?rev=248568&root=gcc&view=rev
Log:
Backport r246996

2017-05-29  Martin Liska  <mliska@suse.cz>

	Backport from mainline
	2017-04-19  Richard Biener  <rguenther@suse.de>

	PR ipa/65972
	* auto-profile.c (afdo_vpt_for_early_inline): Update SSA
	when needed by AutoPGO.

Modified:
    branches/gcc-5-branch/gcc/ChangeLog
    branches/gcc-5-branch/gcc/auto-profile.c
Comment 15 Martin Liška 2017-05-29 09:16:33 UTC
Fixed on all active branches.