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

--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>+FAIL: c-c++-common/unroll-1.c  -Wc++-compat   scan-rtl-dump loop2_unroll 
>"3[79]:.*: optimized: loop unrolled 2 times"


What is happening here is we have a loop followed by another loop.
Like:
```

  <bb 3> [local count: 955630224]:
  # i_18 = PHI <i_13(3), 1(2)>
  # .MEM_19 = PHI <.MEM_12(3), .MEM_9(D)(2)>
...
  if (_3 >= i_13)
    goto <bb 3>; [89.00%]
  else
    goto <bb 4>; [11.00%]

  <bb 4> [local count: 118111600]:
  # .MEM_17 = PHI <.MEM_9(D)(2), .MEM_12(3)>

  <bb 5> [local count: 1063110681]:
  # i_6 = PHI <0(4), i_11(5)>
  # .MEM_8 = PHI <.MEM_17(4), .MEM_10(5)>
..
  if (i_11 != 9)
    goto <bb 5>; [88.89%]
  else
    goto <bb 6>; [11.11%]
```

We remove the forwarder block 4 and that gives:

```

  <bb 3> [local count: 955630224]:
  # i_18 = PHI <i_13(3), 1(2)>
  # .MEM_19 = PHI <.MEM_12(3), .MEM_9(D)(2)>
...
  if (_3 >= i_13)
    goto <bb 3>; [89.00%]
  else
    goto <bb 4>; [11.00%]

  <bb 4> [local count: 1063110681]:
  # i_6 = PHI <0(3), i_11(4), 0(2)>
..
  if (i_11 != 9)
    goto <bb 4>; [88.89%]
  else
    goto <bb 5>; [11.11%]
```

And then out of ssa does not see the 2 phi entries are the same and does:
```
Inserting a value copy on edge BB2->BB4 : PART.4 = 0
Inserting a value copy on edge BB3->BB4 : PART.4 = 0
```
Creating 2 bbs with the same value instead of 1 bbs before the loop.
And RTL loop analysis does not like the 2 (same value) initializations for iv
and breaks down.

So maybe the easy fix is to check if PROP_no_crit_edges is set and reject all
forwarder block removals. Right now PROP_no_crit_edges is set by
pass_split_crit_edges which is done right before late uninitialization warning.

Reply via email to