Fix wrong array type conversion with different storage order

Message ID 4442231.LvFx2qVVIh@fomalhaut
State Accepted
Headers
Series Fix wrong array type conversion with different storage order |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Eric Botcazou Nov. 22, 2022, 11:05 a.m. UTC
  Hi,

when two arrays of scalars have a different storage order in Ada, the
front-end makes sure that the conversion is performed component-wise
so that each component can be reversed.  So it's a little bit counter
productive that the ldist pass performs the opposite transformation
and synthesizes a memcpy/memmove in this case.

Tested on x86-64/Linux, OK for the mainline?


2022-11-22  Eric Botcazou  <ebotcazou@adacore.com>

	* tree-loop-distribution.cc (loop_distribution::classify_builtin_ldst):
	Bail out if source and destination do not have the same storage order.


2022-11-22  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/sso18.adb: New test.
  

Comments

Richard Biener Nov. 22, 2022, 11:22 a.m. UTC | #1
On Tue, Nov 22, 2022 at 12:06 PM Eric Botcazou via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Hi,
>
> when two arrays of scalars have a different storage order in Ada, the
> front-end makes sure that the conversion is performed component-wise
> so that each component can be reversed.  So it's a little bit counter
> productive that the ldist pass performs the opposite transformation
> and synthesizes a memcpy/memmove in this case.
>
> Tested on x86-64/Linux, OK for the mainline?

OK for trunk and branches.

Richard.

>
> 2022-11-22  Eric Botcazou  <ebotcazou@adacore.com>
>
>         * tree-loop-distribution.cc (loop_distribution::classify_builtin_ldst):
>         Bail out if source and destination do not have the same storage order.
>
>
> 2022-11-22  Eric Botcazou  <ebotcazou@adacore.com>
>
>         * gnat.dg/sso18.adb: New test.
>
> --
> Eric Botcazou
  

Patch

diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc
index ed3dd73e1a9..15ae2410861 100644
--- a/gcc/tree-loop-distribution.cc
+++ b/gcc/tree-loop-distribution.cc
@@ -1790,10 +1790,15 @@  loop_distribution::classify_builtin_ldst (loop_p loop, struct graph *rdg,
   if (res != 2)
     return;
 
-  /* They much have the same access size.  */
+  /* They must have the same access size.  */
   if (!operand_equal_p (size, src_size, 0))
     return;
 
+  /* They must have the same storage order.  */
+  if (reverse_storage_order_for_component_p (DR_REF (dst_dr))
+      != reverse_storage_order_for_component_p (DR_REF (src_dr)))
+    return;
+
   /* Load and store in loop nest must access memory in the same way, i.e,
      their must have the same steps in each loop of the nest.  */
   if (dst_steps.length () != src_steps.length ())