So it turns out I thought we would always get a virtual phi when there was a
store
in front of the load. This is correct for all normal code except if heading into
an infinite loop where there are no stores/loads. Since this is leading to
an infinite loop, rejecting this case does not change performance at all.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/125923
gcc/ChangeLog:
* tree-ssa-phiopt.cc (factor_out_conditional_load): Change
assert of the vuse being the same to rejecting if they are
different without a virtual phi.
gcc/testsuite/ChangeLog:
* gcc.dg/torture/pr125923-1.c: New test.
Signed-off-by: Andrew Pinski <[email protected]>
---
gcc/testsuite/gcc.dg/torture/pr125923-1.c | 12 ++++++++++++
gcc/tree-ssa-phiopt.cc | 7 +++++--
2 files changed, 17 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/torture/pr125923-1.c
diff --git a/gcc/testsuite/gcc.dg/torture/pr125923-1.c
b/gcc/testsuite/gcc.dg/torture/pr125923-1.c
new file mode 100644
index 00000000000..1edce7d388f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr125923-1.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fno-tree-dce" } */
+/* PR tree-optimization/125923 */
+
+int a, b, c, d;
+void e() {
+ d = a && d;
+ if (b)
+ b = 0;
+ while (!a || b)
+ c ^= 1;
+}
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index c73a81c4166..7a623fc4c0c 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -3713,8 +3713,11 @@ factor_out_conditional_load (edge e0, edge e1,
basic_block merge, gphi *phi,
|| gimple_vuse (load1) != gimple_phi_arg_def (vphi, e1->dest_idx))
return false;
}
- else
- gcc_assert (gimple_vuse (load0) == gimple_vuse (load1));
+ /* Sometimes due to not removing dead statements,
+ a virtual phi does not show up going into an infinite loop
+ so just reject that case. */
+ else if (gimple_vuse (load0) != gimple_vuse (load1))
+ return false;
tree ref0 = gimple_assign_rhs1 (load0);
tree ref1 = gimple_assign_rhs1 (load1);
--
2.43.0