The following valid code causes an ICE when compiled with the current gcc trunk at -O2 and above on x86_64-linux-gnu in both 32- and 64-bit modes. $ gcc-trunk --version gcc-trunk (GCC) 8.0.0 20170426 (experimental) [trunk revision 247284] Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ gcc-trunk -O2 abc.c abc.c: In function ‘fn1’: abc.c:2:6: internal compiler error: in chrec_fold_plus_poly_poly, at tree-chrec.c:152 void fn1() { ^~~ 0x1373a17 chrec_fold_plus_poly_poly ../../gcc/gcc/tree-chrec.c:152 0x1373a17 chrec_fold_plus_1 ../../gcc/gcc/tree-chrec.c:285 0xc744fb interpret_rhs_expr ../../gcc/gcc/tree-scalar-evolution.c:1839 0xc7117c interpret_gimple_assign ../../gcc/gcc/tree-scalar-evolution.c:2008 0xc7117c analyze_scalar_evolution_1 ../../gcc/gcc/tree-scalar-evolution.c:2092 0xc71a5e analyze_scalar_evolution(loop*, tree_node*) ../../gcc/gcc/tree-scalar-evolution.c:2147 0xc74c4a interpret_rhs_expr ../../gcc/gcc/tree-scalar-evolution.c:1935 0xc7117c interpret_gimple_assign ../../gcc/gcc/tree-scalar-evolution.c:2008 0xc7117c analyze_scalar_evolution_1 ../../gcc/gcc/tree-scalar-evolution.c:2092 0xc71a5e analyze_scalar_evolution(loop*, tree_node*) ../../gcc/gcc/tree-scalar-evolution.c:2147 0xcfc269 infer_loop_bounds_from_signedness ../../gcc/gcc/tree-ssa-loop-niter.c:3412 0xcfc269 infer_loop_bounds_from_undefined ../../gcc/gcc/tree-ssa-loop-niter.c:3469 0xcfc269 estimate_numbers_of_iterations_loop ../../gcc/gcc/tree-ssa-loop-niter.c:3852 0xcfce13 estimate_numbers_of_iterations() ../../gcc/gcc/tree-ssa-loop-niter.c:4065 0xcd4479 tree_unroll_loops_completely(bool, bool) ../../gcc/gcc/tree-ssa-loop-ivcanon.c:1369 0xcd4b35 execute ../../gcc/gcc/tree-ssa-loop-ivcanon.c:1586 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions. $ cat abc.c char a, b; void fn1() { char c, e; short d; if (0) { for (; d;) { l1: for (c = 7; a; c++) ; e = 6; for (; b; e++) ; } c -= e; } if (d == 7) goto l1; a = c; }
Confirmed. Works with GCC 4.8. Mine.
Hmm, SCEV analysis relies on loop-closed SSA form to handle expressions in outer loops that use inner loop final values. Otherwise we miss to do the required compute_overall_effects_of_inner_loop which is triggered by exit PHIs being present. That means effectively everyone doing niter analysis needs loop-closed SSA form :/ Or we make SCEV analysis more resistant, in this case instead of asserting return chrec_dont_know. Testing patch.
Fixed on trunk sofar.
Author: rguenth Date: Thu Apr 27 11:42:57 2017 New Revision: 247322 URL: https://gcc.gnu.org/viewcvs?rev=247322&root=gcc&view=rev Log: 2017-04-27 Richard Biener <rguenther@suse.de> PR middle-end/80539 * tree-chrec.c (chrec_fold_plus_poly_poly): Deal with not being in loop-closed SSA form conservatively. (chrec_fold_multiply_poly_poly): Likewise. * gcc.dg/torture/pr80539.c: New testcase. Added: trunk/gcc/testsuite/gcc.dg/torture/pr80539.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-chrec.c
Author: rguenth Date: Wed May 3 11:22:34 2017 New Revision: 247545 URL: https://gcc.gnu.org/viewcvs?rev=247545&root=gcc&view=rev Log: 2017-05-03 Richard Biener <rguenther@suse.de> Backport from mainline 2017-04-20 Richard Biener <rguenther@suse.de> PR tree-optimization/80453 * tree-ssa-sccvn.h (struct vn_phi_s): Add cclhs and ccrhs members. * tree-ssa-sccvn.c (cond_stmts_equal_p): Use recorded lhs and rhs from the conditions. (vn_phi_eq): Pass them down. (vn_phi_lookup): Record them. (vn_phi_insert): Likewise. 2017-04-25 Richard Biener <rguenther@suse.de> PR tree-optimization/80492 * alias.c (compare_base_decls): Handle registers with asm specification conservatively. * gcc.dg/pr80492.c: New testcase. 2017-04-27 Richard Biener <rguenther@suse.de> PR middle-end/80539 * tree-chrec.c (chrec_fold_plus_poly_poly): Deal with not being in loop-closed SSA form conservatively. (chrec_fold_multiply_poly_poly): Likewise. * gcc.dg/torture/pr80539.c: New testcase. Added: branches/gcc-7-branch/gcc/testsuite/gcc.dg/pr80492.c branches/gcc-7-branch/gcc/testsuite/gcc.dg/torture/pr80539.c Modified: branches/gcc-7-branch/gcc/ChangeLog branches/gcc-7-branch/gcc/alias.c branches/gcc-7-branch/gcc/testsuite/ChangeLog branches/gcc-7-branch/gcc/tree-chrec.c branches/gcc-7-branch/gcc/tree-ssa-sccvn.c branches/gcc-7-branch/gcc/tree-ssa-sccvn.h
Author: rguenth Date: Tue May 9 12:27:24 2017 New Revision: 247790 URL: https://gcc.gnu.org/viewcvs?rev=247790&root=gcc&view=rev Log: 2017-05-09 Richard Biener <rguenther@suse.de> Backport from mainline 2017-03-28 Richard Biener <rguenther@suse.de> PR middle-end/80222 * gimple-fold.c (gimple_fold_indirect_ref): Do not touch TYPE_REF_CAN_ALIAS_ALL references. * fold-const.c (fold_indirect_ref_1): Likewise. * g++.dg/pr80222.C: New testcase. 2017-04-06 Richard Biener <rguenther@suse.de> PR tree-optimization/80262 * tree-sra.c (build_ref_for_offset): Preserve address-space information. * tree-ssa-sccvn.c (vn_reference_maybe_forwprop_address): Drop useless address-space information on MEM_REF offsets. * gcc.target/i386/pr80262.c: New testcase. 2017-04-03 Richard Biener <rguenther@suse.de> PR tree-optimization/80275 * fold-const.c (split_address_to_core_and_offset): Handle POINTER_PLUS_EXPR. * g++.dg/opt/pr80275.C: New testcase. 2017-04-06 Richard Biener <rguenther@suse.de> PR tree-optimization/80334 * tree-ssa-loop-ivopts.c (rewrite_use_address): Properly preserve alignment of accesses. * g++.dg/torture/pr80334.C: New testcase. 2017-04-10 Richard Biener <rguenther@suse.de> PR middle-end/80362 * fold-const.c (fold_binary_loc): Look at unstripped ops when looking for NEGATE_EXPR in -A / -B to A / B folding. * gcc.dg/torture/pr80362.c: New testcase. 2017-04-25 Richard Biener <rguenther@suse.de> PR tree-optimization/80492 * alias.c (compare_base_decls): Handle registers with asm specification conservatively. * gcc.dg/pr80492.c: New testcase. 2017-04-27 Richard Biener <rguenther@suse.de> PR middle-end/80539 * tree-chrec.c (chrec_fold_plus_poly_poly): Deal with not being in loop-closed SSA form conservatively. (chrec_fold_multiply_poly_poly): Likewise. * gcc.dg/torture/pr80539.c: New testcase. Added: branches/gcc-6-branch/gcc/testsuite/g++.dg/opt/pr80275.C branches/gcc-6-branch/gcc/testsuite/g++.dg/pr80222.C branches/gcc-6-branch/gcc/testsuite/g++.dg/torture/pr80334.C branches/gcc-6-branch/gcc/testsuite/gcc.dg/pr80492.c branches/gcc-6-branch/gcc/testsuite/gcc.dg/torture/pr80362.c branches/gcc-6-branch/gcc/testsuite/gcc.dg/torture/pr80539.c branches/gcc-6-branch/gcc/testsuite/gcc.target/i386/pr80262.c Modified: branches/gcc-6-branch/gcc/ChangeLog branches/gcc-6-branch/gcc/alias.c branches/gcc-6-branch/gcc/fold-const.c branches/gcc-6-branch/gcc/gimple-fold.c branches/gcc-6-branch/gcc/testsuite/ChangeLog branches/gcc-6-branch/gcc/tree-chrec.c branches/gcc-6-branch/gcc/tree-sra.c branches/gcc-6-branch/gcc/tree-ssa-loop-ivopts.c branches/gcc-6-branch/gcc/tree-ssa-sccvn.c
Fixed.
Author: rguenth Date: Wed May 10 07:53:45 2017 New Revision: 247827 URL: https://gcc.gnu.org/viewcvs?rev=247827&root=gcc&view=rev Log: 2017-05-10 Richard Biener <rguenther@suse.de> Backport from mainline 2017-03-21 Richard Biener <rguenther@suse.de> PR tree-optimization/80122 * tree-inline.c (copy_bb): Do not expans va-arg packs or va_arg_pack_len when the inlined call stmt requires pack expansion itself. * tree-inline.h (struct copy_body_data): Make call_stmt a gcall *. * gcc.dg/torture/pr80122.c: New testcase. 2017-03-28 Richard Biener <rguenther@suse.de> PR middle-end/80222 * gimple-fold.c (gimple_fold_indirect_ref): Do not touch TYPE_REF_CAN_ALIAS_ALL references. * fold-const.c (fold_indirect_ref_1): Likewise. * g++.dg/pr80222.C: New testcase. 2017-04-06 Richard Biener <rguenther@suse.de> PR tree-optimization/80334 * tree-ssa-loop-ivopts.c (rewrite_use_address): Properly preserve alignment of accesses. * g++.dg/torture/pr80334.C: New testcase. 2017-04-27 Richard Biener <rguenther@suse.de> PR middle-end/80539 * tree-chrec.c (chrec_fold_plus_poly_poly): Deal with not being in loop-closed SSA form conservatively. (chrec_fold_multiply_poly_poly): Likewise. * gcc.dg/torture/pr80539.c: New testcase. Added: branches/gcc-5-branch/gcc/testsuite/g++.dg/pr80222.C branches/gcc-5-branch/gcc/testsuite/g++.dg/torture/pr80334.C branches/gcc-5-branch/gcc/testsuite/gcc.dg/torture/pr80122.c branches/gcc-5-branch/gcc/testsuite/gcc.dg/torture/pr80539.c Modified: branches/gcc-5-branch/gcc/ChangeLog branches/gcc-5-branch/gcc/fold-const.c branches/gcc-5-branch/gcc/gimple-fold.c branches/gcc-5-branch/gcc/testsuite/ChangeLog branches/gcc-5-branch/gcc/tree-chrec.c branches/gcc-5-branch/gcc/tree-inline.c branches/gcc-5-branch/gcc/tree-inline.h branches/gcc-5-branch/gcc/tree-ssa-loop-ivopts.c