https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118922
--- Comment #27 from GCC Commits ---
The releases/gcc-13 branch has been updated by Andrew Pinski
:
https://gcc.gnu.org/g:7b9a1f91efe34051bc512def7ef883f62cf698fd
commit r13-9528-g7b9a1f91efe34051bc512def7ef883f62cf698fd
Author: Andrew Pinski
Date: Sat Mar 8 22:43:54 2025 -0800
phiopt: Fix value_replacement for middle bb having phi nodes [PR118922]
After r12-5300-gf98f373dd822b3, value_replacement would be able to look at
the
following cfg structure:
```
[local count: 1014686024]:
if (h_6 != 0)
goto ; [94.50%]
else
goto ; [5.50%]
[local count: 114863530]:
# h_6 = PHI <0(4), 1(5)>
[local count: 1073741824]:
# f_8 = PHI <0(5), h_6(6)>
_9 = f_8 ^ 1;
a.0_10 = a;
_11 = _9 + a.0_10;
if (_11 != -117)
goto ; [94.50%]
else
goto ; [5.50%]
```
value_replacement would incorrectly think the middle bb (6) was empty and
so it decides
to remove condition in bb5 and replacing it with 0 as the function thought
it was `h_6 ? 0 : h_6`.
But since the there is an incoming phi node to bb6 defining h_6 that is
incorrect.
The fix is to check if there is phi nodes in the middle bb and set
empty_or_with_defined_p to false.
This was not needed before r12-5300-gf98f373dd822b3 because the phi would
have been dead otherwise due to
other checks.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/118922
gcc/ChangeLog:
* tree-ssa-phiopt.cc (value_replacement): Set
empty_or_with_defined_p
to false when there is phi nodes for the middle bb.
gcc/testsuite/ChangeLog:
* gcc.dg/torture/pr118922-1.c: New test.
Signed-off-by: Andrew Pinski
(cherry picked from commit 7232c005afb5002cdfd0a2dbd0e8b8f2d80250ce)