[Bug middle-end/117243] [12/13/14 regression] program crash under -O3 optimization or higher since r12-5300-gf98f373dd822b3

2025-04-14 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117243

--- Comment #20 from GCC Commits  ---
The releases/gcc-14 branch has been updated by Andrew Pinski
:

https://gcc.gnu.org/g:6f0d80202b62ae48381d9ec7488522199cb7922a

commit r14-11614-g6f0d80202b62ae48381d9ec7488522199cb7922a
Author: Andrew Pinski 
Date:   Mon Dec 2 08:35:23 2024 -0800

phiopt: Reset the number of iterations information of a loop when changing
an exit from the loop [PR117243]

After r12-5300-gf98f373dd822b3, phiopt could get the following bb
structure:
  |
middle-bb -|
  ||
  |   ||   |
phi<1, 2>  |   |
cond   |   |
  ||   |
  |+---|

Which was considered 2 loops. The inner loop had esimtate of upper_bound to
be 8,
due to the original `for (b = 0; b <= 7; b++)`. The outer loop was already
an
infinite one.
So phiopt would come along and change the condition to be unconditionally
true,
we change the inner loop to being an infinite one but don't reset the
estimate
on the loop and cleanup cfg comes along and changes it into one loop but
also
does not reset the estimate of the loop. Then the loop unrolling uses the
old estimate
and decides to add an unreachable there.o
So the fix is when phiopt changes an exit to a loop, reset the estimates,
similar to
how cleanupcfg does it when merging some basic blocks.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/117243
PR tree-optimization/116749

gcc/ChangeLog:

* tree-ssa-phiopt.cc (replace_phi_edge_with_variable): Reset loop
estimates if the cond_block was an exit to a loop.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr117243-1.c: New test.
* gcc.dg/torture/pr117243-2.c: New test.

Signed-off-by: Andrew Pinski 
(cherry picked from commit b7c69cc072ef0da36439ebc55c513b48e68391b7)

[Bug middle-end/117243] [12/13/14 regression] program crash under -O3 optimization or higher since r12-5300-gf98f373dd822b3

2024-12-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117243

Andrew Pinski  changed:

   What|Removed |Added

  Known to fail|14.2.1, 15.0|14.2.0
  Known to work||15.0
Summary|[12/13/14/15 regression]|[12/13/14 regression]
   |program crash under -O3 |program crash under -O3
   |optimization or higher  |optimization or higher
   |since   |since
   |r12-5300-gf98f373dd822b3|r12-5300-gf98f373dd822b3

--- Comment #19 from Andrew Pinski  ---
Fixed on the trunk so far.