From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 0BED43858422 for ; Thu, 29 Sep 2022 09:10:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0BED43858422 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-x430.google.com with SMTP id bq9so1151359wrb.4 for ; Thu, 29 Sep 2022 02:10:55 -0700 (PDT) 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:cc :to:from:from:to:cc:subject:date; bh=EIM140XcDlRCSyPZ9ob5Kse4RAuELJeBcKNg6lZCr+I=; b=fPDKTPZAZSolcaCMF9fc2b7euKbVqaYeODQvq1eTELb5PH9oHDlc+AkPdF5A518WRH UaD22fOHC/6Q3rQHKj1Djx548oeB5NaqkhkemdUe7BBBUIWN58e9xnUtSTOdrOx3P0dy gR/mUWWvEGoZFBgnpnm0WC+gyxqzDKCqUkXGojJOoWeaEskXSAcbgvtD04t9msgNqIel 3q2OFMY1tUjdUBtfT3qkNjFTKdEc04fXEBxkkxQWLnxujsAt8IQbSNMeSdX5zajW+ZtT 3iR5wvzNHmnjRltRaw8FFGoowHhm1kOYuIcsfdZROfGKfrzDngd/EG+h9o/AAvPil18M tFIQ== 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:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=EIM140XcDlRCSyPZ9ob5Kse4RAuELJeBcKNg6lZCr+I=; b=SeIkJp1inrK4+9QWHKomAWfQX8yaWtTJBB9G7ujdiDM0D0jx6fuYFXvlYIjhpQeHK2 kjdT5O1LaPZyw5mZHQuOZh9wPUYdK3GKMgV7ks0CFC3UBsJ3TsBuPr6eUSdD6eR1XzUH fP+MVPFAAGFT/JUK8oEVEBo60thQcnxS6hEyNQsekllR9EkJM+bSYpIfLe5RtU41u00G LWGGHNr/hSPjTjZ2X8jJ6L7YY8fQDHICePeBW9Pa7JXAM9oGNyLOPDRM3ii3JpGYl7R9 YfD8WmjuHqAuDUBYaG6DHdLK9UsIFL8fMf30vD2/UZNVx+388HUQW2bFFExXgN/6mhnk fucg== X-Gm-Message-State: ACrzQf0bZnEmlwDmTULsyWVz1h0H+MgGRd9h8C6apo8BdMNA76MeIayk rU8MSRnMohHorGR5CoIcJTvVOguQFFC9sg== X-Google-Smtp-Source: AMsMyM6N6VTVe1WxE9U6fPrAP4DGDhse+Cb6xhPsDatjdwxekG+CIZMAABkCm9MusGsFbpI+3qWkbA== X-Received: by 2002:a5d:47a1:0:b0:22a:2979:4899 with SMTP id 1-20020a5d47a1000000b0022a29794899mr1352803wrb.349.1664442654808; Thu, 29 Sep 2022 02:10:54 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id 189-20020a1c19c6000000b003b5054c6f87sm3804302wmz.21.2022.09.29.02.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 02:10:54 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [COMMITED] ada: Improve efficiency of slice-of-component assignment Date: Thu, 29 Sep 2022 11:10:50 +0200 Message-Id: <20220929091050.359634-1-poulhies@adacore.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.1 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: From: Bob Duff This patch improves the efficiency of slice assignment when the left- or right-hand side is a slice of a component or a slice of a slice. Previously, the optimization was disabled in these cases, just in case there might be a volatile or independent component lurking. Now we explicitly check all the relevant subcomponents of the prefix. The previous version said (in exp_ch5.adb): -- ...We could -- complicate this code by actually looking for such volatile and -- independent components. and that's exactly what we are doing here. gcc/ada/ * exp_ch5.adb (Expand_Assign_Array_Loop_Or_Bitfield): Make the checks for volatile and independent objects more precise. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch5.adb | 95 +++++++++++++++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 24 deletions(-) diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb index 2e14c97632a..209741c82cf 100644 --- a/gcc/ada/exp_ch5.adb +++ b/gcc/ada/exp_ch5.adb @@ -1594,35 +1594,86 @@ package body Exp_Ch5 is Rev : Boolean) return Node_Id is + function Volatile_Or_Independent + (Exp : Node_Id; Typ : Entity_Id) return Boolean; + -- Exp is an expression of type Typ, or if there is no expression + -- involved, Exp is Empty. True if there are any volatile or independent + -- objects that should disable the optimization. We check the object + -- itself, all subcomponents, and if Exp is a slice of a component or + -- slice, we check the prefix and its type. + -- + -- We disable the optimization when there are relevant volatile or + -- independent objects, because Copy_Bitfield can read and write bits + -- that are not part of the objects being copied. + + ----------------------------- + -- Volatile_Or_Independent -- + ----------------------------- + + function Volatile_Or_Independent + (Exp : Node_Id; Typ : Entity_Id) return Boolean + is + begin + -- Initially, Exp is the left- or right-hand side. In recursive + -- calls, Exp is Empty if we're just checking a component type, and + -- Exp is the prefix if we're checking the prefix of a slice. + + if Present (Exp) + and then (Is_Volatile_Object_Ref (Exp) + or else Is_Independent_Object (Exp)) + then + return True; + end if; + + if Has_Volatile_Components (Typ) + or else Has_Independent_Components (Typ) + then + return True; + end if; + + if Is_Array_Type (Typ) then + return Volatile_Or_Independent (Empty, Component_Type (Typ)); + elsif Is_Record_Type (Typ) then + declare + Comp : Entity_Id := First_Component (Typ); + begin + while Present (Comp) loop + if Volatile_Or_Independent (Empty, Comp) then + return True; + end if; + + Next_Component (Comp); + end loop; + end; + end if; + + if Nkind (Exp) = N_Slice + and then Nkind (Prefix (Exp)) in + N_Selected_Component | N_Indexed_Component | N_Slice + then + if Volatile_Or_Independent (Prefix (Exp), Etype (Prefix (Exp))) + then + return True; + end if; + end if; + + return False; + end Volatile_Or_Independent; + L : constant Node_Id := Name (N); R : constant Node_Id := Expression (N); -- Left- and right-hand sides of the assignment statement Slices : constant Boolean := Nkind (L) = N_Slice or else Nkind (R) = N_Slice; - L_Prefix_Comp : constant Boolean := - -- True if the left-hand side is a slice of a component or slice - Nkind (L) = N_Slice - and then Nkind (Prefix (L)) in - N_Selected_Component | N_Indexed_Component | N_Slice; - R_Prefix_Comp : constant Boolean := - -- Likewise for the right-hand side - Nkind (R) = N_Slice - and then Nkind (Prefix (R)) in - N_Selected_Component | N_Indexed_Component | N_Slice; + + -- Start of processing for Expand_Assign_Array_Loop_Or_Bitfield begin -- Determine whether Copy_Bitfield or Fast_Copy_Bitfield is appropriate -- (will work, and will be more efficient than component-by-component -- copy). Copy_Bitfield doesn't work for reversed storage orders. It is - -- efficient for slices of bit-packed arrays. Copy_Bitfield can read and - -- write bits that are not part of the objects being copied, so we don't - -- want to use it if there are volatile or independent components. If - -- the Prefix of the slice is a component or slice, then it might be a - -- part of an object with some other volatile or independent components, - -- so we disable the optimization in that case as well. We could - -- complicate this code by actually looking for such volatile and - -- independent components. + -- efficient for slices of bit-packed arrays. if Is_Bit_Packed_Array (L_Type) and then Is_Bit_Packed_Array (R_Type) @@ -1630,12 +1681,8 @@ package body Exp_Ch5 is and then not Reverse_Storage_Order (R_Type) and then Ndim = 1 and then Slices - and then not Has_Volatile_Component (L_Type) - and then not Has_Volatile_Component (R_Type) - and then not Has_Independent_Components (L_Type) - and then not Has_Independent_Components (R_Type) - and then not L_Prefix_Comp - and then not R_Prefix_Comp + and then not Volatile_Or_Independent (L, L_Type) + and then not Volatile_Or_Independent (R, R_Type) then -- Here if Copy_Bitfield can work (except for the Rev test below). -- Determine whether to call Fast_Copy_Bitfield instead. If we -- 2.25.1