From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1285) id 234FB385B1BD; Fri, 25 Nov 2022 10:05:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 234FB385B1BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669370735; bh=oO0HkSDKybIWuU6jQDjYPgMFDhA9He2rFK+mzsLNpiY=; h=From:To:Subject:Date:From; b=Eac7loxUCo/qCRil6zwcB3KL9EF94w0HiZQ6jzUujzEtqrgZYxkk08o1f46koB1Dz lwpDNXd+udrTU1RD3KZmTWLHr+fofpXsgbfslXYMYY3niLcAkCJIJDz6wMdhxxXI6N RUs3sC5QHqLbg9O8jJKgWLezyrl6a4vitlhjC92w= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Eric Botcazou To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10391] Fix wrong array type conversion with different storage orde X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 6635f128ea8688f513a7c2a14003b1ab37359a5c X-Git-Newrev: 066e5d93a216f881b6a413f1581d0cc8ef120249 Message-Id: <20221125100535.234FB385B1BD@sourceware.org> Date: Fri, 25 Nov 2022 10:05:35 +0000 (GMT) List-Id: https://gcc.gnu.org/g:066e5d93a216f881b6a413f1581d0cc8ef120249 commit r11-10391-g066e5d93a216f881b6a413f1581d0cc8ef120249 Author: Eric Botcazou Date: Tue Nov 22 19:03:49 2022 +0100 Fix wrong array type conversion with different storage orde 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. gcc/ * tree-loop-distribution.c (loop_distribution::classify_builtin_ldst): Bail out if source and destination do not have the same storage order. gcc/testsuite/ * gnat.dg/sso18.adb: New test. Diff: --- gcc/testsuite/gnat.dg/sso18.adb | 21 +++++++++++++++++++++ gcc/tree-loop-distribution.c | 7 ++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gnat.dg/sso18.adb b/gcc/testsuite/gnat.dg/sso18.adb new file mode 100644 index 00000000000..7496e965fd3 --- /dev/null +++ b/gcc/testsuite/gnat.dg/sso18.adb @@ -0,0 +1,21 @@ +-- { 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; diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c index 65aa1df4aba..7568384e286 100644 --- a/gcc/tree-loop-distribution.c +++ b/gcc/tree-loop-distribution.c @@ -1757,10 +1757,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 ())