diff mbox series

[v5] Repeat jump threading after combine

Message ID 20181129065707.77458-1-iii@linux.ibm.com
State New
Headers show
Series [v5] Repeat jump threading after combine | expand

Commit Message

Ilya Leoshkevich Nov. 29, 2018, 6:57 a.m. UTC
Repost of v4: https://gcc.gnu.org/ml/gcc-patches/2018-11/msg02067.html

Bootstrapped and regtested on x86_64-redhat-linux, s390x-redhat-linux
and ppc64le-redhat-linux.

Consider the following RTL:

(insn (set (reg 65) (if_then_else (eq %cc 0) 1 0)))
(insn (parallel [(set %cc (compare (reg 65) 0)) (clobber %scratch)]))
(jump_insn (set %pc (if_then_else (ne %cc 0) (label_ref 23) %pc)))

Combine simplifies this into:

(note NOTE_INSN_DELETED)
(note NOTE_INSN_DELETED)
(jump_insn (set %pc (if_then_else (eq %cc 0) (label_ref 23) %pc)))

opening up the possibility to perform jump threading.

gcc/ChangeLog:

2018-09-19  Ilya Leoshkevich  <iii@linux.ibm.com>

	PR target/80080
	* cfgcleanup.c (class pass_postreload_jump): New pass.
	(pass_postreload_jump::execute): Likewise.
	(make_pass_postreload_jump): Likewise.
	* passes.def: Add pass_postreload_jump before
	pass_postreload_cse.
	* tree-pass.h (make_pass_postreload_jump): New pass.

gcc/testsuite/ChangeLog:

2018-09-05  Ilya Leoshkevich  <iii@linux.ibm.com>

	PR target/80080
	* gcc.target/s390/pr80080-4.c: New test.
---
 gcc/cfgcleanup.c                          | 42 +++++++++++++++++++++++
 gcc/passes.def                            |  1 +
 gcc/testsuite/gcc.target/s390/pr80080-4.c | 16 +++++++++
 gcc/tree-pass.h                           |  1 +
 4 files changed, 60 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/s390/pr80080-4.c

Comments

Jeff Law Nov. 30, 2018, 11:19 p.m. UTC | #1
On 11/28/18 11:57 PM, Ilya Leoshkevich wrote:
> Repost of v4: https://gcc.gnu.org/ml/gcc-patches/2018-11/msg02067.html
> 
> Bootstrapped and regtested on x86_64-redhat-linux, s390x-redhat-linux
> and ppc64le-redhat-linux.
> 
> Consider the following RTL:
> 
> (insn (set (reg 65) (if_then_else (eq %cc 0) 1 0)))
> (insn (parallel [(set %cc (compare (reg 65) 0)) (clobber %scratch)]))
> (jump_insn (set %pc (if_then_else (ne %cc 0) (label_ref 23) %pc)))
> 
> Combine simplifies this into:
> 
> (note NOTE_INSN_DELETED)
> (note NOTE_INSN_DELETED)
> (jump_insn (set %pc (if_then_else (eq %cc 0) (label_ref 23) %pc)))
> 
> opening up the possibility to perform jump threading.
> 
> gcc/ChangeLog:
> 
> 2018-09-19  Ilya Leoshkevich  <iii@linux.ibm.com>
> 
> 	PR target/80080
> 	* cfgcleanup.c (class pass_postreload_jump): New pass.
> 	(pass_postreload_jump::execute): Likewise.
> 	(make_pass_postreload_jump): Likewise.
> 	* passes.def: Add pass_postreload_jump before
> 	pass_postreload_cse.
> 	* tree-pass.h (make_pass_postreload_jump): New pass.
OK
jeff
diff mbox series

Patch

diff --git a/gcc/cfgcleanup.c b/gcc/cfgcleanup.c
index 4a5dc29d14f..bc4a78889db 100644
--- a/gcc/cfgcleanup.c
+++ b/gcc/cfgcleanup.c
@@ -3259,6 +3259,48 @@  make_pass_jump (gcc::context *ctxt)
 
 namespace {
 
+const pass_data pass_data_postreload_jump =
+{
+  RTL_PASS, /* type */
+  "postreload_jump", /* name */
+  OPTGROUP_NONE, /* optinfo_flags */
+  TV_JUMP, /* tv_id */
+  0, /* properties_required */
+  0, /* properties_provided */
+  0, /* properties_destroyed */
+  0, /* todo_flags_start */
+  0, /* todo_flags_finish */
+};
+
+class pass_postreload_jump : public rtl_opt_pass
+{
+public:
+  pass_postreload_jump (gcc::context *ctxt)
+    : rtl_opt_pass (pass_data_postreload_jump, ctxt)
+  {}
+
+  /* opt_pass methods: */
+  virtual unsigned int execute (function *);
+
+}; // class pass_postreload_jump
+
+unsigned int
+pass_postreload_jump::execute (function *)
+{
+  cleanup_cfg (flag_thread_jumps ? CLEANUP_THREADING : 0);
+  return 0;
+}
+
+} // anon namespace
+
+rtl_opt_pass *
+make_pass_postreload_jump (gcc::context *ctxt)
+{
+  return new pass_postreload_jump (ctxt);
+}
+
+namespace {
+
 const pass_data pass_data_jump2 =
 {
   RTL_PASS, /* type */
diff --git a/gcc/passes.def b/gcc/passes.def
index 82ad9404b9e..0079fecef32 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -458,6 +458,7 @@  along with GCC; see the file COPYING3.  If not see
       NEXT_PASS (pass_reload);
       NEXT_PASS (pass_postreload);
       PUSH_INSERT_PASSES_WITHIN (pass_postreload)
+	  NEXT_PASS (pass_postreload_jump);
 	  NEXT_PASS (pass_postreload_cse);
 	  NEXT_PASS (pass_gcse2);
 	  NEXT_PASS (pass_split_after_reload);
diff --git a/gcc/testsuite/gcc.target/s390/pr80080-4.c b/gcc/testsuite/gcc.target/s390/pr80080-4.c
new file mode 100644
index 00000000000..5fc6a558008
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/pr80080-4.c
@@ -0,0 +1,16 @@ 
+/* { dg-do compile { target { lp64 } } } */
+/* { dg-options "-march=z196 -O2" } */
+
+extern void bar(int *mem);
+
+void foo4(int *mem)
+{
+  int oldval = 0;
+  if (!__atomic_compare_exchange_n (mem, (void *) &oldval, 1,
+				    1, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED))
+    {
+      bar (mem);
+    }
+}
+
+/* { dg-final { scan-assembler {(?n)\n\tlt\t.*\n\tjne\t(\.L\d+)\n(.*\n)*\tcs\t.*\n\tber\t%r14\n\1:\n\tjg\tbar\n} } } */
diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
index 2f8779ee4b8..b20d34c15e9 100644
--- a/gcc/tree-pass.h
+++ b/gcc/tree-pass.h
@@ -579,6 +579,7 @@  extern rtl_opt_pass *make_pass_clean_state (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_branch_prob (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_value_profile_transformations (gcc::context
 							      *ctxt);
+extern rtl_opt_pass *make_pass_postreload_jump (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_postreload_cse (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_gcse2 (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_split_after_reload (gcc::context *ctxt);