From 4aded535ea6ad7c362ab62d99af70e53c186d582 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Thu, 12 Mar 2020 16:09:27 -0600 Subject: [PATCH] Remove no-op register to register copies in CSE just like we remove no-op memory to memory copies. PR rtl-optimization/90275 * cse.c (cse_insn): Delete no-op register moves too. PR rtl-optimization/90275 * gcc.c-torture/compile/pr90275.c: New test. --- gcc/ChangeLog | 5 ++++ gcc/cse.c | 14 +++++----- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.c-torture/compile/pr90275.c | 27 +++++++++++++++++++ 4 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr90275.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b184a1af8e9..f1a1984e8c7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2020-03-12 Richard Sandiford + + PR rtl-optimization/90275 + * cse.c (cse_insn): Delete no-op register moves too. + 2020-03-12 Darius Galis * config/rx/rx.md (CTRLREG_CPEN): Remove. diff --git a/gcc/cse.c b/gcc/cse.c index 79ee0ce80e3..08984c17040 100644 --- a/gcc/cse.c +++ b/gcc/cse.c @@ -4625,7 +4625,7 @@ cse_insn (rtx_insn *insn) for (i = 0; i < n_sets; i++) { bool repeat = false; - bool mem_noop_insn = false; + bool noop_insn = false; rtx src, dest; rtx src_folded; struct table_elt *elt = 0, *p; @@ -5324,9 +5324,11 @@ cse_insn (rtx_insn *insn) } /* Similarly, lots of targets don't allow no-op - (set (mem x) (mem x)) moves. */ + (set (mem x) (mem x)) moves. Even (set (reg x) (reg x)) + might be impossible for certain registers (like CC registers). */ else if (n_sets == 1 - && MEM_P (trial) + && !CALL_P (insn) + && (MEM_P (trial) || REG_P (trial)) && MEM_P (dest) && rtx_equal_p (trial, dest) && !side_effects_p (dest) @@ -5334,7 +5336,7 @@ cse_insn (rtx_insn *insn) || insn_nothrow_p (insn))) { SET_SRC (sets[i].rtl) = trial; - mem_noop_insn = true; + noop_insn = true; break; } @@ -5562,8 +5564,8 @@ cse_insn (rtx_insn *insn) sets[i].rtl = 0; } - /* Similarly for no-op MEM moves. */ - else if (mem_noop_insn) + /* Similarly for no-op moves. */ + else if (noop_insn) { if (cfun->can_throw_non_call_exceptions && can_throw_internal (insn)) cse_cfg_altered = true; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a5730ebbbc0..6d8eac22c31 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-03-12 Jeff Law + + PR rtl-optimization/90275 + * gcc.c-torture/compile/pr90275.c: New test. + 2020-03-12 Richard Biener PR tree-optimization/94103 diff --git a/gcc/testsuite/gcc.c-torture/compile/pr90275.c b/gcc/testsuite/gcc.c-torture/compile/pr90275.c new file mode 100644 index 00000000000..83e0df77226 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr90275.c @@ -0,0 +1,27 @@ +a, b, c; + +long long d; + +e() { + + char f; + + for (;;) { + + c = a = c ? 5 : 0; + + if (f) { + + b = a; + + f = d; + + } + + (d || b) < (a > e) ?: (b ? 0 : f) || (d -= f); + + } + +} + + -- 2.30.2