[PATCH] auto-inc-dec: Set alignment properly

Segher Boessenkool segher@kernel.crashing.org
Wed Apr 17 10:19:00 GMT 2019

When auto-inc-dec creates a new mem to compute the cost of doing some
transform, it forgets to copy over the alignment of the original mem.
This gives wrong costs, for example, for rs6000 a floating point load
or store is hugely expensive if unaligned.  This patch fixes it.

This doesn't fix any test case I'm aware of, but it is a very simple
patch.  Is it okay for trunk?


2019-04-17  Segher Boessenkool  <segher@kernel.crashing.org>

	* auto-inc-dec.c (attempt_change): Set the alignment of the
	temporary memory to that of the original.

 gcc/auto-inc-dec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/auto-inc-dec.c b/gcc/auto-inc-dec.c
index 43400cc..bdb6efa 100644
--- a/gcc/auto-inc-dec.c
+++ b/gcc/auto-inc-dec.c
@@ -471,6 +471,7 @@ attempt_change (rtx new_addr, rtx inc_reg)
   int regno;
   rtx mem = *mem_insn.mem_loc;
   machine_mode mode = GET_MODE (mem);
+  int align = MEM_ALIGN (mem);
   rtx new_mem;
   int old_cost = 0;
   int new_cost = 0;
@@ -478,6 +479,7 @@ attempt_change (rtx new_addr, rtx inc_reg)
   PUT_MODE (mem_tmp, mode);
   XEXP (mem_tmp, 0) = new_addr;
+  set_mem_align (mem_tmp, align);
   old_cost = (set_src_cost (mem, mode, speed)
 	      + set_rtx_cost (PATTERN (inc_insn.insn), speed));

More information about the Gcc-patches mailing list