https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124891
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Seems we change a stmt (SSA_NAME replaced with INTEGER_CST 1) in:
#0 set_ssa_use_from_ptr (use=0x7fffe96026f0, val=<integer_cst 0x7fffe981f318>)
at ../../gcc/ssa-iterators.h:333
#1 0x0000000001160f66 in replace_exp (op_p=0x7fffe96026f0, val=<integer_cst
0x7fffe981f318>) at ../../gcc/tree-ssa-propagate.cc:1154
#2 0x0000000001161058 in propagate_value (op_p=0x7fffe96026f0,
val=<integer_cst 0x7fffe981f318>) at ../../gcc/tree-ssa-propagate.cc:1177
#3 0x000000000115f546 in substitute_and_fold_engine::replace_uses_in
(this=0x7fffffffd340, stmt=<gimple_assign 0x7fffe9616c00>) at
../../gcc/tree-ssa-propagate.cc:589
#4 0x0000000001160159 in substitute_and_fold_dom_walker::before_dom_children
(this=0x7fffffffd2a0, bb=<basic_block 0x7fffe9616ba0 (24)>) at
../../gcc/tree-ssa-propagate.cc:855
#5 0x0000000002a2a6e7 in dom_walker::walk (this=0x7fffffffd2a0,
bb=<basic_block 0x7fffe9616ba0 (24)>) at ../../gcc/domwalk.cc:311
#6 0x000000000116083e in substitute_and_fold_engine::substitute_and_fold
(this=0x7fffffffd340, block=<basic_block 0x7fffe9616ba0 (24)>) at
../../gcc/tree-ssa-propagate.cc:1003
#7 0x0000000002a6c398 in (anonymous
namespace)::loop_versioning::implement_versioning_decisions
(this=0x7fffffffd3d0) at ../../gcc/gimple-loop-versioning.cc:1760
#8 0x0000000002a6c44a in (anonymous namespace)::loop_versioning::run
(this=0x7fffffffd3d0) at ../../gcc/gimple-loop-versioning.cc:1774
#9 0x0000000002a6c515 in (anonymous namespace)::pass_loop_versioning::execute
(this=0x4a1d560, fn=0x7ffff7fba1a0) at ../../gcc/gimple-loop-versioning.cc:1816
#10 0x0000000000d313cc in execute_one_pass (pass=<opt_pass* 0x4a1d560
"lversion"(175)>) at ../../gcc/passes.cc:2656
without update_stmt? and then ICE because
2881 /* Avoid expanding to expressions that contain SSA names that need
2882 to take part in abnormal coalescing. */
2883 ssa_op_iter iter;
2884 FOR_EACH_SSA_TREE_OPERAND (e, stmt, iter, SSA_OP_USE)
2885 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (e))
2886 return expr;
sees INTEGER_CST:
#0 internal_error (gmsgid=0x3c38860 "tree check: %s, have %s in %s, at %s:%d")
at ../../gcc/diagnostic-global-context.cc:778
#1 0x0000000001335f45 in tree_check_failed (node=<integer_cst 0x7fffe981f318>,
file=0x3bf7010 "../../gcc/tree-ssa-loop-niter.cc", line=2885,
function=0x3bf738b "expand_simple_operations") at ../../gcc/tree.cc:9219
#2 0x000000000040c216 in tree_check (__t=<integer_cst 0x7fffe981f318>,
__f=0x3bf7010 "../../gcc/tree-ssa-loop-niter.cc", __l=2885, __g=0x3bf738b
"expand_simple_operations",
__c=SSA_NAME) at ../../gcc/tree.h:3780
#3 0x0000000001103d14 in expand_simple_operations (expr=<ssa_name
0x7fffe9617268 51>, stop=<tree 0x0>, cache=...) at
../../gcc/tree-ssa-loop-niter.cc:2885
#4 0x00000000011043cd in expand_simple_operations (expr=<ssa_name
0x7fffe9617268 51>, stop=<tree 0x0>) at ../../gcc/tree-ssa-loop-niter.cc:2949
#5 0x00000000010fa093 in refine_value_range_using_guard (type=<integer_type
0x7fffe981d5e8 int>, var=<ssa_name 0x7fffe96173c8 55>, c0=<ssa_name
0x7fffe9617268 51>, cmp=GT_EXPR,
c1=<ssa_name 0x7fffe96173c8 55>, below=0x7fffffff6da0, up=0x7fffffff6d90)
at ../../gcc/tree-ssa-loop-niter.cc:196
#6 0x00000000010fb26a in determine_value_range (loop=0x7fffe9805c80,
type=<integer_type 0x7fffe981d5e8 int>, var=<ssa_name 0x7fffe96173c8 55>,
off=0x7fffffff7200,
min=0x7fffffff71d0, max=0x7fffffff71c0) at
../../gcc/tree-ssa-loop-niter.cc:466
#7 0x00000000010fc032 in bound_difference (loop=0x7fffe9805c80, x=<minus_expr
0x7fffe961f258>, y=<ssa_name 0x7fffe96173c8 55>, bnds=0x7fffffff72f0)
at ../../gcc/tree-ssa-loop-niter.cc:759
#8 0x0000000001100902 in number_of_iterations_cond (loop=0x7fffe9805c80,
type=<integer_type 0x7fffe981d5e8 int>, iv0=0x7fffffff74c0, code=LT_EXPR,
iv1=0x7fffffff74e0,
niter=0x7fffffff7650, only_exit=true, every_iteration=true) at
../../gcc/tree-ssa-loop-niter.cc:1929
#9 0x0000000001105476 in number_of_iterations_exit_assumptions
(loop=0x7fffe9805c80, exit=<edge 0x7fffe960a578 (26 -> 27)>,
niter=0x7fffffff7650, at_stmt=0x7fffffff75d8,
every_iteration=true, body=0x4bbccc0) at
../../gcc/tree-ssa-loop-niter.cc:3309
#10 0x00000000011057c6 in number_of_iterations_exit (loop=0x7fffe9805c80,
exit=<edge 0x7fffe960a578 (26 -> 27)>, niter=0x7fffffff7650, warn=false,
every_iteration=true, body=0x0)
at ../../gcc/tree-ssa-loop-niter.cc:3374
#11 0x000000000102d477 in number_of_latch_executions (loop=0x7fffe9805c80) at
../../gcc/tree-scalar-evolution.cc:2908
#12 0x0000000001027308 in compute_overall_effect_of_inner_loop
(loop=0x7fffe9805c80, evolution_fn=<polynomial_chrec 0x7fffe961f230>) at
../../gcc/tree-scalar-evolution.cc:462
#13 0x000000000102b8cc in analyze_scalar_evolution_1 (loop=0x7fffe961e190,
var=<ssa_name 0x7fffe99ff160 14>) at ../../gcc/tree-scalar-evolution.cc:2031
#14 0x000000000102bb3f in analyze_scalar_evolution (loop=0x7fffe961e190,
var=<ssa_name 0x7fffe99ff160 14>) at ../../gcc/tree-scalar-evolution.cc:2109
#15 0x0000000001029e58 in interpret_condition_phi (loop=0x7fffe961e190,
condition_phi=0x7fffe9614800) at ../../gcc/tree-scalar-evolution.cc:1667
#16 0x000000000102b98d in analyze_scalar_evolution_1 (loop=0x7fffe961e190,
var=<ssa_name 0x7fffe9617580 60>) at ../../gcc/tree-scalar-evolution.cc:2047
#17 0x000000000102bb3f in analyze_scalar_evolution (loop=0x7fffe961e190,
var=<ssa_name 0x7fffe9617580 60>) at ../../gcc/tree-scalar-evolution.cc:2109
#18 0x00000000013e7250 in get_scev_info (r=..., name=<ssa_name 0x7fffe9617580
60>, stmt=<gimple_phi 0x7fffe9614800>, l=0x7fffe961e190, init=@0x7fffffff8448:
<tree 0x138fcfd>,
step=@0x7fffffff8440: <tree 0x7fffffff8490>, dir=@0x7fffffff843c:
EV_DIR_GROWS) at ../../gcc/vr-values.cc:211
#19 0x00000000013e7982 in range_of_var_in_loop (v=..., name=<ssa_name
0x7fffe9617580 60>, l=0x7fffe961e190, stmt=<gimple_phi 0x7fffe9614800>,
query=0x4bc4e40)
at ../../gcc/vr-values.cc:304
#20 0x00000000009af556 in fold_using_range::range_of_ssa_name_with_loop_info
(this=0x7fffffff8edf, r=..., name=<ssa_name 0x7fffe9617580 60>,
l=0x7fffe961e190, phi=0x7fffe9614800,
src=...) at ../../gcc/gimple-range-fold.cc:1484
#21 0x00000000009ae016 in fold_using_range::range_of_phi (this=0x7fffffff8edf,
r=..., phi=0x7fffe9614800, src=...) at ../../gcc/gimple-range-fold.cc:1231
#22 0x00000000009ab72b in fold_using_range::fold_stmt (this=0x7fffffff8edf,
r=..., s=<gimple_phi 0x7fffe9614800>, src=..., name=<ssa_name 0x7fffe9617580
60>)
at ../../gcc/gimple-range-fold.cc:683
#23 0x000000000099ec53 in gimple_ranger::fold_range_internal (this=0x4bc4e40,
r=..., s=<gimple_phi 0x7fffe9614800>, name=<ssa_name 0x7fffe9617580 60>)
at ../../gcc/gimple-range.cc:282
#24 0x000000000099f297 in gimple_ranger::prefill_stmt_dependencies
(this=0x4bc4e40, ssa=<ssa_name 0x7fffe96173c8 55>) at
../../gcc/gimple-range.cc:423
#25 0x000000000099ef2e in gimple_ranger::range_of_stmt (this=0x4bc4e40, r=...,
s=<gimple_phi 0x7fffe99cdd00>, name=<ssa_name 0x7fffe96173c8 55>) at
../../gcc/gimple-range.cc:339
#26 0x000000000099e058 in gimple_ranger::range_of_expr (this=0x4bc4e40, r=...,
expr=<ssa_name 0x7fffe96173c8 55>, stmt=<gimple 0x0>) at
../../gcc/gimple-range.cc:112
#27 0x00000000012147d5 in ssa_name_has_boolean_range (op=<ssa_name
0x7fffe96173c8 55>, stmt=<gimple 0x0>) at ../../gcc/tree-ssanames.cc:645
#28 0x0000000001c16f20 in gimple_simplify_MINUS_EXPR (res_op=0x7fffffffcdb0,
seq=0x7fffffffcf98, valueize=0x97bc62 <follow_single_use_edges(tree_node*)>,
code=...,
type=<integer_type 0x7fffe981d5e8 int>, _p0=<integer_cst 0x7fffe981f318>,
_p1=<ssa_name 0x7fffe96173c8 55>) at gimple-match-10.cc:14307
--Type <RET> for more, q to quit, c to continue without paging--
#29 0x0000000001bb7fcd in gimple_simplify (res_op=0x7fffffffcdb0,
seq=0x7fffffffcf98, valueize=0x97bc62 <follow_single_use_edges(tree_node*)>,
code=...,
type=<integer_type 0x7fffe981d5e8 int>, _p0=<integer_cst 0x7fffe981f318>,
_p1=<ssa_name 0x7fffe96173c8 55>) at gimple-match-9.cc:24510
#30 0x0000000001c4ec06 in gimple_resimplify2 (seq=0x7fffffffcf98,
res_op=0x7fffffffcf20, valueize=0x97bc62 <follow_single_use_edges(tree_node*)>)
at ../../gcc/gimple-match-exports.cc:1027
#31 0x0000000001c4c431 in gimple_match_op::resimplify (this=0x7fffffffcf20,
seq=0x7fffffffcf98, valueize=0x97bc62 <follow_single_use_edges(tree_node*)>)
at ../../gcc/gimple-match-exports.cc:113
#32 0x0000000001c4e384 in gimple_simplify (stmt=<gimple_assign 0x7fffe9616c00>,
res_op=0x7fffffffcf20, seq=0x7fffffffcf98, valueize=0x97bc62
<follow_single_use_edges(tree_node*)>,
top_valueize=0x97bc62 <follow_single_use_edges(tree_node*)>) at
../../gcc/gimple-match-exports.cc:894
#33 0x000000000097b5a2 in fold_stmt_1 (gsi=0x7fffffffd170, inplace=false,
valueize=0x97bc62 <follow_single_use_edges(tree_node*)>, dce_worklist=0x0) at
../../gcc/gimple-fold.cc:6852
#34 0x000000000097bd15 in fold_stmt (gsi=0x7fffffffd170, valueize=0x97bc62
<follow_single_use_edges(tree_node*)>, dce_bitmap=0x0) at
../../gcc/gimple-fold.cc:7019
#35 0x00000000011601bc in substitute_and_fold_dom_walker::before_dom_children
(this=0x7fffffffd2a0, bb=<basic_block 0x7fffe9616ba0 (24)>) at
../../gcc/tree-ssa-propagate.cc:863
#36 0x0000000002a2a6e7 in dom_walker::walk (this=0x7fffffffd2a0,
bb=<basic_block 0x7fffe9616ba0 (24)>) at ../../gcc/domwalk.cc:311
#37 0x000000000116083e in substitute_and_fold_engine::substitute_and_fold
(this=0x7fffffffd340, block=<basic_block 0x7fffe9616ba0 (24)>) at
../../gcc/tree-ssa-propagate.cc:1003
#38 0x0000000002a6c398 in (anonymous
namespace)::loop_versioning::implement_versioning_decisions
(this=0x7fffffffd3d0) at ../../gcc/gimple-loop-versioning.cc:1760
#39 0x0000000002a6c44a in (anonymous namespace)::loop_versioning::run
(this=0x7fffffffd3d0) at ../../gcc/gimple-loop-versioning.cc:1774
#40 0x0000000002a6c515 in (anonymous namespace)::pass_loop_versioning::execute
(this=0x4a1d560, fn=0x7ffff7fba1a0) at ../../gcc/gimple-loop-versioning.cc:1816
#41 0x0000000000d313cc in execute_one_pass (pass=<opt_pass* 0x4a1d560
"lversion"(175)>) at ../../gcc/passes.cc:2656
That is fold_stmt on the same stmt.
This is in
/* Replace real uses in the statement. */
did_replace |= substitute_and_fold_engine->replace_uses_in (stmt);
gimple_stmt_iterator prev_gsi = i;
gsi_prev (&prev_gsi);
/* If we made a replacement, fold the statement. */
if (did_replace)
{
fold_stmt (&i, follow_single_use_edges);
stmt = gsi_stmt (i);
gimple_set_modified (stmt, true);
}
/* Also fold if we want to fold all statements. */
else if (substitute_and_fold_engine->fold_all_stmts
&& fold_stmt (&i, follow_single_use_edges))
{
did_replace = true;
stmt = gsi_stmt (i);
gimple_set_modified (stmt, true);
}
/* Some statements may be simplified using propagator
specific information. Do this before propagating
into the stmt to not disturb pass specific information. */
update_stmt_if_modified (stmt);
Shouldn't we update_stmt (stmt); before fold_stmt in the did_replace case?