diff mbox series

[RFC] rs6000: Early remat for CR fields

Message ID fdae75d652dcf069d18c7ab67404732d801dfe1c.1541976641.git.segher@kernel.crashing.org
State New
Headers show
Series [RFC] rs6000: Early remat for CR fields | expand

Commit Message

Segher Boessenkool Nov. 11, 2018, 11:11 p.m. UTC
This implements early remat for condition codes, for rs6000.  Saving
and restoring the CR register is pretty expensive, so we want to avoid
doing it.

It is an RFC for two reasons.  Firstly, I needed to delete the
NUM_POLY_INT_COEFFS > 1 check from generic code, since that has nothing
to do with early remat, it's just for Arm SVE.  This should be moved to
the aarch64 hook implementation?

Secondly, it makes almost all (or all?) asan tests fail.  I do not know
why; everything else works fine.  This needs to be investigated,

Early remat does not handle instructions that set a condition reg as
well as another (general purpose) register.  It could, by
rematerializing the instruction as just the comparison.  I don't know
how much this would help (it would allow rematerializing Power "dot"
instructions, which are pretty frequent).


Segher

---
 gcc/config/rs6000/rs6000.c | 17 +++++++++++++++++
 gcc/early-remat.c          |  2 +-
 2 files changed, 18 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index c60e1b2..3411570 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -1589,6 +1589,9 @@  static const struct attribute_spec rs6000_attribute_table[] =
 #undef TARGET_SET_UP_BY_PROLOGUE
 #define TARGET_SET_UP_BY_PROLOGUE rs6000_set_up_by_prologue
 
+#undef TARGET_SELECT_EARLY_REMAT_MODES
+#define TARGET_SELECT_EARLY_REMAT_MODES rs6000_select_early_remat_modes
+
 #undef TARGET_SHRINK_WRAP_GET_SEPARATE_COMPONENTS
 #define TARGET_SHRINK_WRAP_GET_SEPARATE_COMPONENTS rs6000_get_separate_components
 #undef TARGET_SHRINK_WRAP_COMPONENTS_FOR_BB
@@ -26031,6 +26034,20 @@  rs6000_global_entry_point_needed_p (void)
   return cfun->machine->r2_setup_needed;
 }
 
+/* Implement TARGET_SELECT_EARLY_REMAT_MODES.  */
+
+static void
+rs6000_select_early_remat_modes (sbitmap modes)
+{
+  /* We want to rematerialize all condition codes.  */
+  for (int i = 0; i < NUM_MACHINE_MODES; ++i)
+    {
+      machine_mode mode = (machine_mode) i;
+      if (GET_MODE_CLASS (mode) == MODE_CC)
+	bitmap_set_bit (modes, i);
+    }
+}
+
 /* Implement TARGET_SHRINK_WRAP_GET_SEPARATE_COMPONENTS.  */
 static sbitmap
 rs6000_get_separate_components (void)
diff --git a/gcc/early-remat.c b/gcc/early-remat.c
index 776b2d0..b969e28 100644
--- a/gcc/early-remat.c
+++ b/gcc/early-remat.c
@@ -2588,7 +2588,7 @@  public:
   /* opt_pass methods: */
   virtual bool gate (function *)
   {
-    return optimize > 1 && NUM_POLY_INT_COEFFS > 1;
+    return optimize > 1;
   }
 
   virtual unsigned int execute (function *f)