Created attachment 41792 [details] reproducer gcc trunk, rev250217, x86_64. The attached test case was obtained by reducing the bigger test case with another SSA problem, which is manifested as the following: IMM ERROR : (use_p : tree - 0x7f06c0e56d68:0x7f06c0e56d88)_95049 for SSA_NAME: _95049 in statement: slsr_55910 = PHI <_95049(199), _95049(200)> PHI argument _95049 for PHI node slsr_55910 = PHI <_95049(199), _95049(200)> during GIMPLE pass: slsr Anyway, during the test case reduction (which keep the program at all reduction steps correct and UB-free) compilation started consuming enormous amount of memory - basically all available on the machine (128Gb) and crashing after that. Compilation doesn't take long, it's typically about 2 minutes before it crashes. Here's example of the stack while gcc actively allocating memory: #0 0x00007f7aa06ab70b in __memset_sse2 () from /lib64/libc.so.6 #1 0x0000000000a65e4f in ggc_internal_alloc(unsigned long, void (*)(void*), unsigned long, unsigned long) () at ../../gcc/gcc/ggc-page.c:1392 #2 0x0000000000f4acd9 in ggc_internal_alloc (s=<optimized out>) at ../../gcc/gcc/ggc.h:130 #3 allocate_phi_node (len=<optimized out>) at ../../gcc/gcc/tree-phinodes.c:117 #4 make_phi_node (len=<optimized out>, var=<optimized out>) at ../../gcc/gcc/tree-phinodes.c:174 #5 create_phi_node(tree_node*, basic_block_def*) () at ../../gcc/gcc/tree-phinodes.c:342 #6 0x000000000159219b in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2405 #7 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #8 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #9 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #10 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #11 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #12 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #13 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #14 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #15 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #16 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #17 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #18 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #19 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #20 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #21 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #22 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #23 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #24 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #25 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #26 0x00000000015926ce in create_phi_basis(slsr_cand_d*, gimple*, tree_node*, unsigned int, bool) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2386 #27 0x0000000001592e29 in replace_conditional_candidate (c=0x2bb6e60) at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2446 #28 replace_uncond_cands_and_profitable_phis(slsr_cand_d*) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2545 #29 0x0000000001592c2d in replace_uncond_cands_and_profitable_phis(slsr_cand_d*) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:2552 #30 0x0000000001597ff0 in analyze_candidates_and_replace () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:3732 #31 (anonymous namespace)::pass_strength_reduction::execute(function*) () at ../../gcc/gcc/gimple-ssa-strength-reduction.c:3843 #32 0x0000000000dd0cfb in execute_one_pass(opt_pass*) () at ../../gcc/gcc/passes.c:2492 #33 0x0000000000dd1555 in execute_pass_list_1(opt_pass*) () at ../../gcc/gcc/passes.c:2581 #34 0x0000000000dd1567 in execute_pass_list_1(opt_pass*) () at ../../gcc/gcc/passes.c:2582 #35 0x0000000000dd1599 in execute_pass_list(function*, opt_pass*) () at ../../gcc/gcc/passes.c:2592 #36 0x0000000000ae3c80 in cgraph_node::expand() () at ../../gcc/gcc/cgraphunit.c:2052 #37 0x0000000000ae4e01 in expand_all_functions () at ../../gcc/gcc/cgraphunit.c:2188 #38 symbol_table::compile() [clone .part.54] () at ../../gcc/gcc/cgraphunit.c:2540 #39 0x0000000000ae72a7 in compile (this=0x7f7a99f00100) at ../../gcc/gcc/cgraphunit.c:2632 #40 symbol_table::finalize_compilation_unit (this=0x7f7a99f00100) at ../../gcc/gcc/cgraphunit.c:2629 #41 0x0000000000e9e958 in compile_file () at ../../gcc/gcc/toplev.c:493 #42 0x0000000000800526 in do_compile () at ../../gcc/gcc/toplev.c:2021 #43 toplev::main(int, char**) () at ../../gcc/gcc/toplev.c:2155 #44 0x000000000080252b in main (argc=15, argv=0x7ffda4815b68) at ../../gcc/gcc/main.c:39 My point is that some thresholds are obviously missing and gcc should not consume that much memory. Also, the speed of memory allocation hints that there might be a bug in the algorithm allocating memory. To reproduce: > g++ -std=c++11 -O3 -c func.cpp Note that -O2 compilation takes just 0.38 seconds and 28Mb on memory.
Confirmed via PR81546 (I fixed the ICE now).
Mine. Please be patient while I work through the sudden influx of bug reports.
Doesn't reproduce for powerpc64le on current trunk. I'll try a cross.
With a cross it doesn't reproduce for current trunk (r251128) either, but does reproduce with r250217 as originally reported. So I can look at that. Going to check what made the problem go away also...
Just for the record, the problem disappears with r250523, in which a change to reassociation of multiplication in match.pd causes the SLSR opportunities to disappear. So the SLSR problem has just gone latent, as suspected.
Patch submitted: https://gcc.gnu.org/ml/gcc-patches/2017-08/msg01145.html
Author: wschmidt Date: Tue Aug 22 17:32:26 2017 New Revision: 251286 URL: https://gcc.gnu.org/viewcvs?rev=251286&root=gcc&view=rev Log: 2017-08-22 Bill Schmidt <wschmidt@linux.vnet.ibm.com> PR tree-optimization/81488 * gimple-ssa-strength-reduction (struct slsr_cand_d): Add visited and cached_basis fields. (MAX_SPREAD): New constant. (alloc_cand_and_find_basis): Initialize new fields. (clear_visited): New function. (create_phi_basis_1): Rename from create_phi_basis, set visited and cached_basis fields. (create_phi_basis): New wrapper function. (phi_add_costs_1): Rename from phi_add_costs, add spread parameter, set visited field, short-circuit when limits reached. (phi_add_costs): New wrapper function. (record_phi_increments_1): Rename from record_phi_increments, set visited field. (record_phi_increments): New wrapper function. (phi_incr_cost_1): Rename from phi_incr_cost, set visited field. (phi_incr_cost): New wrapper function. (all_phi_incrs_profitable_1): Rename from all_phi_incrs_profitable, set visited field. (all_phi_incrs_profitable): New wrapper function. Modified: trunk/gcc/ChangeLog trunk/gcc/gimple-ssa-strength-reduction.c
Fixed.
Author: aldyh Date: Wed Sep 13 17:20:57 2017 New Revision: 252535 URL: https://gcc.gnu.org/viewcvs?rev=252535&root=gcc&view=rev Log: 2017-08-22 Bill Schmidt <wschmidt@linux.vnet.ibm.com> PR tree-optimization/81488 * gimple-ssa-strength-reduction (struct slsr_cand_d): Add visited and cached_basis fields. (MAX_SPREAD): New constant. (alloc_cand_and_find_basis): Initialize new fields. (clear_visited): New function. (create_phi_basis_1): Rename from create_phi_basis, set visited and cached_basis fields. (create_phi_basis): New wrapper function. (phi_add_costs_1): Rename from phi_add_costs, add spread parameter, set visited field, short-circuit when limits reached. (phi_add_costs): New wrapper function. (record_phi_increments_1): Rename from record_phi_increments, set visited field. (record_phi_increments): New wrapper function. (phi_incr_cost_1): Rename from phi_incr_cost, set visited field. (phi_incr_cost): New wrapper function. (all_phi_incrs_profitable_1): Rename from all_phi_incrs_profitable, set visited field. (all_phi_incrs_profitable): New wrapper function. Modified: branches/range-gen2/gcc/ChangeLog branches/range-gen2/gcc/gimple-ssa-strength-reduction.c