The function rs6000_force_indexed_or_indirect_mem makes a memory
operand suitable for indexed (or indirect) addressing.  If the memory
address isn't yet valid, it loads the whole thing into a register to
make it valid.  That isn't optimal.  This changes it to load an
address that is the sum of two things into two registers instead.
This results in lower latency code, and if inside loops, a constant
term can be moved outside the loop.

Tested on powerpc64-linux {-m32,-m64} and on powerpc64le-linux (a Power9).
Committing.


Segher


2019-07-01  Segher Boessenkool  <seg...@kernel.crashing.org>

        * config/rs6000/rs6000.c (rs6000_force_indexed_or_indirect_mem):
        Load both operands of a PLUS into registers separately.

---
 gcc/config/rs6000/rs6000.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 5e80673..f59f3a9 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -32100,7 +32100,16 @@ rs6000_force_indexed_or_indirect_mem (rtx x)
          addr = reg;
        }
 
-      x = replace_equiv_address (x, force_reg (Pmode, addr));
+      if (GET_CODE (addr) == PLUS)
+       {
+         rtx op0 = XEXP (addr, 0);
+         rtx op1 = XEXP (addr, 1);
+         op0 = force_reg (Pmode, op0);
+         op1 = force_reg (Pmode, op1);
+         x = replace_equiv_address (x, gen_rtx_PLUS (Pmode, op0, op1));
+       }
+      else
+       x = replace_equiv_address (x, force_reg (Pmode, addr));
     }
 
   return x;
-- 
1.8.3.1

Reply via email to