From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 4F9DF3858D20 for ; Tue, 22 Nov 2022 11:05:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4F9DF3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x435.google.com with SMTP id n3so7594968wrp.5 for ; Tue, 22 Nov 2022 03:05:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=qwLH/pssA/TjD9TEOgGCoVLY3HR1bIIyatpuLTQmh0U=; b=aUaOelmOnZ9VOFvvzaDMgoNUyI4LEflipB3Ps+6HbwvfmdhbqvSJAO6QZV+W4vnEno +RVD8EXF10ycGBYhxPTNckUEsEdXK/annbOPJSEv9owVGEXHy1+3WsekksUisxxmwkdF 5ad3oLTl9VT6eCNNILNkAMxbIJIrr2wZw3thJLSQ7wWBsfoQPmc56Z6fIj7L9Jt1ZQp5 jZROvM2Q2JtttuitmxEik/IRwCmV60wUC58yLKA0IG47zkjaqaqmE6LUB/WtDwFTl3pb gAkk34h8PtH/NN6N+x+RbYkPgN4Hbl+ClqbyrYv7kqXBFO8Lb3yK9yd7ALaIwEosYpDY dTuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qwLH/pssA/TjD9TEOgGCoVLY3HR1bIIyatpuLTQmh0U=; b=tXn8KGFqoCGgzkkz9brCq9h4RLDucVpq9D5aHkc8JNpBRq8/hNIAKKD2C3qpAa/Uoc HOsxO6kaf3euJ6Vb4uYgBInVhbWjz2WL199EdshEu2QrqIjcKrN+MWe+DeT5gqivLytR oQp2daZ1UlE3NzlSKwxaS2Eh1U0+WKUXjGL+9P4dYelfFCn/Ef/NVU3QayeC7BfLA0Vp qjleAaW+ok6BbMlcHIhnE+zPZW60FAWitqdIsoHmWEPuCBReRT0DbcQVLGPW2dWgr3D+ pihxwidAVqVCi0//Yq8Snxt/kWJi30OQf3sTzh1ph4rO2FswdDjayNOu308Owby+I1f6 3Rhw== X-Gm-Message-State: ANoB5plHzOi0p72pcR620U9yt0O3QLGt1IFGF7u0Xw4Q21FajCuf5Uxt /odXNW7TXt9CJiub+tWvnDvfrNupKWGCRw== X-Google-Smtp-Source: AA0mqf5ZfIhaHE25pqEgz3SPyYPjHckxNEWgl4tnIOIezIpkfh6ZSUbO+GqOu53ogLxPYKdP/gnm6A== X-Received: by 2002:a5d:48cf:0:b0:236:4983:285f with SMTP id p15-20020a5d48cf000000b002364983285fmr13835897wrs.576.1669115117642; Tue, 22 Nov 2022 03:05:17 -0800 (PST) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id c12-20020adffb4c000000b0022a3a887ceasm13683157wrs.49.2022.11.22.03.05.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 03:05:16 -0800 (PST) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix wrong array type conversion with different storage order Date: Tue, 22 Nov 2022 12:05:16 +0100 Message-ID: <4442231.LvFx2qVVIh@fomalhaut> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart2261709.ElGaqSPkdT" Content-Transfer-Encoding: 7Bit X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This is a multi-part message in MIME format. --nextPart2261709.ElGaqSPkdT Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" 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 * 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 * gnat.dg/sso18.adb: New test. -- Eric Botcazou --nextPart2261709.ElGaqSPkdT Content-Disposition: attachment; filename="p.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="p.diff" 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 ()) --nextPart2261709.ElGaqSPkdT Content-Disposition: attachment; filename="sso18.adb" Content-Transfer-Encoding: 7Bit Content-Type: text/x-adasrc; charset="UTF-8"; name="sso18.adb" -- { 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; --nextPart2261709.ElGaqSPkdT--