https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123298

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
+Value numbering stmt = if (g_64_23(D) <= 5)
+marking outgoing edge 7 -> 4 executable
+marking outgoing edge 7 -> 8 executable
+Looking for changed values of backedge 7->4 destination PHIs
+Setting value number of g_258_4 to g_258_4 (changed)
+Iterating to 2 BB4
+Processing block 2: BB4
+Value numbering stmt = g_258_4 = PHI <g_258_5(7), g_258_19(D)(3)>
+Setting value number of g_258_4 to g_258_4
+Making available beyond BB4 g_258_4 for value g_258_4
+Value numbering stmt = BS_VAR_1_6 = PHI <BS_VAR_1_7(7), 10(3)>
+Setting value number of BS_VAR_1_6 to BS_VAR_1_6 (changed)
...

+Value numbering stmt = _1 = BS_VAR_5[1];
+Setting value number of _1 to 28

this should now have discovered the BS_VAR_5[1] store on the backedge.

+Processing block 3: BB6
+Value numbering stmt = _2 = BS_VAR_1_6 <= 4;
+Setting value number of _2 to _2 (changed)
+Making available beyond BB6 _2 for value _2
+Value numbering stmt = _3 = (int) _2;
+Setting value number of _3 to _3 (changed)
+Making available beyond BB6 _3 for value _3
+Value numbering stmt = BS_VAR_5[_3] = 0;

that's now correct, but

+Looking for changed values of backedge 7->4 destination PHIs
+Setting value number of g_258_4 to g_258_4
+Setting value number of BS_VAR_1_6 to BS_VAR_1_6
+Setting value number of .MEM_10 to .MEM_10
+Processing block 5: BB5

so (correctly) no change detected and no re-iteration.

The above is from FRE1.

Ah, so when iterating back we wipe hashtables, etc., but we do _not_
wipe value numbers.  But in vn_reference_lookup_3 we try to disambiguate
by valueization, but we may not do that after we walked a backedge
because of that.  But the check is

                                   /* Do not valueize when walking over
                                      backedges.  */
                                   dominated_by_p
                                     (CDI_DOMINATORS,
                                      gimple_bb (SSA_NAME_DEF_STMT (arg1)),
                                      phi_bb)

which in this case (irreducible loop) isn't conservatively correct.  What
matters in the end is RPO order, but that's not trivially available here.
When iterating FRE currently doesn't mark irreducible regions either.
The easiest might be to add another callback to
get_continuation_for_phi that specifies whether an edge is a backedge
and make VN provide a hook using the RPO order.

Reply via email to