public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix wrong array type conversion with different storage order
@ 2022-11-22 11:05 Eric Botcazou
  2022-11-22 11:22 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Botcazou @ 2022-11-22 11:05 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 678 bytes --]

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.

-- 
Eric Botcazou

[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 856 bytes --]

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 ())

[-- Attachment #3: sso18.adb --]
[-- Type: text/x-adasrc, Size: 419 bytes --]

--  { dg-do run }
--  { dg-options "-O2" }

with System;

procedure SSO18 is

  type Arr is array (1..32) of Short_Integer;
  type Rev_Arr is array (1..32) of Short_Integer
    with Scalar_Storage_Order => System.High_Order_First;
  C : constant Arr := (others => 16);
  RA : Rev_Arr;
  A  : Arr;

begin
  RA := Rev_Arr(C);
  A := Arr (RA);
  if A /= C or else RA(1) /= 16 then
     raise Program_Error;
  end if;
end;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix wrong array type conversion with different storage order
  2022-11-22 11:05 [PATCH] Fix wrong array type conversion with different storage order Eric Botcazou
@ 2022-11-22 11:22 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2022-11-22 11:22 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-22 11:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22 11:05 [PATCH] Fix wrong array type conversion with different storage order Eric Botcazou
2022-11-22 11:22 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).