diff mbox

Fix PR rtl-optimization/78355

Message ID 2037118.9NJdoatkLr@polaris
State New
Headers show

Commit Message

Eric Botcazou Nov. 17, 2016, 4:17 p.m. UTC
As diagnosed by the submitter, LRA can generate unaligned accesses when 
SLOW_UNALIGNED_ACCESS is 1, for example when STRICT_ALIGNMENT is 1, because 
simplify_operand_subreg can wrongly reject aligned accesses when reloading 
SUBREGs of MEMs in favor of unaligned ones.  The fix is to add the missing 
guard on the alignment before invoking SLOW_UNALIGNED_ACCESS (as in every 
other use of SLOW_UNALIGNED_ACCESS in the compiler).

Tested on arm-eabi, approved by Vladimir, applied on the mainline.


2016-11-17  Pip Cet  <pipcet@gmail.com>
            Eric Botcazou  <ebotcazou@adacore.com>

	PR rtl-optimization/78355
	* doc/tm.texi.in (SLOW_UNALIGNED_ACCESS): Document that the macro
	only needs to deal with unaligned accesses.
	* doc/tm.texi: Regenerate.
	* lra-constraints.c (simplify_operand_subreg): Only invoke
	SLOW_UNALIGNED_ACCESS on innermode if the MEM is not aligned enough.

-- 
Eric Botcazou
diff mbox

Patch

Index: doc/tm.texi.in
===================================================================
--- doc/tm.texi.in	(revision 242377)
+++ doc/tm.texi.in	(working copy)
@@ -4654,7 +4654,8 @@  other fields in the same word of the str
 Define this macro to be the value 1 if memory accesses described by the
 @var{mode} and @var{alignment} parameters have a cost many times greater
 than aligned accesses, for example if they are emulated in a trap
-handler.
+handler.  This macro is invoked only for unaligned accesses, i.e. when
+@code{@var{alignment} < GET_MODE_ALIGNMENT (@var{mode})}.
 
 When this macro is nonzero, the compiler will act as if
 @code{STRICT_ALIGNMENT} were nonzero when generating code for block
Index: lra-constraints.c
===================================================================
--- lra-constraints.c	(revision 242377)
+++ lra-constraints.c	(working copy)
@@ -1486,9 +1486,10 @@  simplify_operand_subreg (int nop, machin
 	     equivalences in function lra_constraints) and because for spilled
 	     pseudos we allocate stack memory enough for the biggest
 	     corresponding paradoxical subreg.  */
-	  if (!SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (reg))
-	      || SLOW_UNALIGNED_ACCESS (innermode, MEM_ALIGN (reg))
-	      || MEM_ALIGN (reg) >= GET_MODE_ALIGNMENT (mode))
+	  if (!(MEM_ALIGN (reg) < GET_MODE_ALIGNMENT (mode)
+		&& SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (reg)))
+	      || (MEM_ALIGN (reg) < GET_MODE_ALIGNMENT (innermode)
+		  && SLOW_UNALIGNED_ACCESS (innermode, MEM_ALIGN (reg))))
 	    return true;
 
 	  /* INNERMODE is fast, MODE slow.  Reload the mem in INNERMODE.  */