On 1/12/21 4:14 PM, Richard Biener wrote:
) On Tue, Jan 12, 2021 at 3:50 PM Martin Liška <mli...@suse.cz> wrote:
Hello.
As seen in the PR, we need to fix also virtual PHIs, otherwise
TODO_cfg will skip edges for a missing PHI argument.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
OK - doesn't this mean you can remove the
mark_virtual_operands_for_renaming (fun);
call and thus TODO_update_ssa? Btw, the pass seems
to unconditionally schedule TODO_cleanup_cfg - it would
be nice to only do that (return TODO_cleanup_cfg from
pass_if_to_switch::execute) if it did any transform.
Yes, application of all the suggesting works fine.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
Thanks,
Richard.
Thanks,
Martin
gcc/ChangeLog:
PR tree-optimization/98455
* gimple-if-to-switch.cc (condition_info::record_phi_mapping):
Record also virtual PHIs.
gcc/testsuite/ChangeLog:
PR tree-optimization/98455
* gcc.dg/tree-ssa/pr98455.c: New test.
---
gcc/gimple-if-to-switch.cc | 7 ++-----
gcc/testsuite/gcc.dg/tree-ssa/pr98455.c | 19 +++++++++++++++++++
2 files changed, 21 insertions(+), 5 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr98455.c
diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc
index 560753d0311..96213d86c28 100644
--- a/gcc/gimple-if-to-switch.cc
+++ b/gcc/gimple-if-to-switch.cc
@@ -91,11 +91,8 @@ condition_info::record_phi_mapping (edge e, mapping_vec *vec)
gsi_next (&gsi))
{
gphi *phi = gsi.phi ();
- if (!virtual_operand_p (gimple_phi_result (phi)))
- {
- tree arg = PHI_ARG_DEF_FROM_EDGE (phi, e);
- vec->safe_push (std::make_pair (phi, arg));
- }
+ tree arg = PHI_ARG_DEF_FROM_EDGE (phi, e);
+ vec->safe_push (std::make_pair (phi, arg));
}
}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr98455.c
b/gcc/testsuite/gcc.dg/tree-ssa/pr98455.c
new file mode 100644
index 00000000000..24e249f6fcb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr98455.c
@@ -0,0 +1,19 @@
+/* PR tree-optimization/98455 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fno-tree-dce --param case-values-threshold=1" } */
+
+void
+n4 (int io, int vb)
+{
+ double uc[2] = { 1.0, 2.0, };
+
+ if (io == 0)
+ uc[0] = 0.0;
+
+ for (;;)
+ if (io == 0)
+ if (vb == 0)
+ uc[0] = uc[1];
+ else if (vb == 1)
+ uc[1] = 0.0;
+}
--
2.29.2
>From 69d356dea9a202b945288f07b1a9dcc88ea98fd6 Mon Sep 17 00:00:00 2001
From: Martin Liska <mli...@suse.cz>
Date: Tue, 12 Jan 2021 13:40:44 +0100
Subject: [PATCH] if-to-switch: fix also virtual phis
gcc/ChangeLog:
PR tree-optimization/98455
* gimple-if-to-switch.cc (condition_info::record_phi_mapping):
Record also virtual PHIs.
(pass_if_to_switch::execute): Return TODO_cleanup_cfg only
conditionally.
gcc/testsuite/ChangeLog:
PR tree-optimization/98455
* gcc.dg/tree-ssa/pr98455.c: New test.
---
gcc/gimple-if-to-switch.cc | 11 ++++-------
gcc/testsuite/gcc.dg/tree-ssa/pr98455.c | 19 +++++++++++++++++++
2 files changed, 23 insertions(+), 7 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr98455.c
diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc
index 560753d0311..1712fc4c8b3 100644
--- a/gcc/gimple-if-to-switch.cc
+++ b/gcc/gimple-if-to-switch.cc
@@ -91,11 +91,8 @@ condition_info::record_phi_mapping (edge e, mapping_vec *vec)
gsi_next (&gsi))
{
gphi *phi = gsi.phi ();
- if (!virtual_operand_p (gimple_phi_result (phi)))
- {
- tree arg = PHI_ARG_DEF_FROM_EDGE (phi, e);
- vec->safe_push (std::make_pair (phi, arg));
- }
+ tree arg = PHI_ARG_DEF_FROM_EDGE (phi, e);
+ vec->safe_push (std::make_pair (phi, arg));
}
}
@@ -470,7 +467,7 @@ const pass_data pass_data_if_to_switch =
0, /* properties_provided */
0, /* properties_destroyed */
0, /* todo_flags_start */
- TODO_cleanup_cfg | TODO_update_ssa /* todo_flags_finish */
+ TODO_update_ssa /* todo_flags_finish */
};
class pass_if_to_switch : public gimple_opt_pass
@@ -575,7 +572,7 @@ pass_if_to_switch::execute (function *fun)
if (!all_candidates.is_empty ())
{
free_dominance_info (CDI_DOMINATORS);
- mark_virtual_operands_for_renaming (fun);
+ return TODO_cleanup_cfg;
}
return 0;
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr98455.c b/gcc/testsuite/gcc.dg/tree-ssa/pr98455.c
new file mode 100644
index 00000000000..24e249f6fcb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr98455.c
@@ -0,0 +1,19 @@
+/* PR tree-optimization/98455 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fno-tree-dce --param case-values-threshold=1" } */
+
+void
+n4 (int io, int vb)
+{
+ double uc[2] = { 1.0, 2.0, };
+
+ if (io == 0)
+ uc[0] = 0.0;
+
+ for (;;)
+ if (io == 0)
+ if (vb == 0)
+ uc[0] = uc[1];
+ else if (vb == 1)
+ uc[1] = 0.0;
+}
--
2.29.2