From patchwork Wed Nov 10 08:58:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 47367 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 11732385801F for ; Wed, 10 Nov 2021 09:02:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11732385801F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636534921; bh=HXuxet1eYTrgriHcK6Dec3NPmzMmbw17tPL/O5CF+iU=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=SUdemPkE3E5XP+yFiOeCcjhANqrR6iG4rJqpnHd15BCmN+bcdhr5FIdQHoBVEs8nO u9lC5Pq4F7Bha99HZgrWY7VYTPiap0qK++S83OmkqI1XQn8FN5p6fYCHs0fF1iVBt1 w9mK+JSHPixzTawavoz9/hnWMYj9JFr7UILm2Ty4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by sourceware.org (Postfix) with ESMTPS id 262E7385801F for ; Wed, 10 Nov 2021 08:58:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 262E7385801F Received: by mail-lf1-x12d.google.com with SMTP id y26so4258311lfa.11 for ; Wed, 10 Nov 2021 00:58:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=HXuxet1eYTrgriHcK6Dec3NPmzMmbw17tPL/O5CF+iU=; b=fjUcf0FfwXqSKXktezCCBxnPWyVOzyR+QQuJ2dkud2r2ZiZTy81r/l5geM/0jzGOv9 R7GTYvzIC8Iwjjo0tKW7aPm5urSQV4LFxZvGZS/ddovEYetgR88Ieuf+ZT4JqvnJgisG ATvo2W+kHjx6ybRLesUX8S5Jv9IY4nWgpuu6/GfDDQ8zFOYWnzndGrdBO6zxp5IUc8ZK DBN4AHfOkgaySkbjkkx4nCuAyykizSGjWXuFOph9jNYPjaCqhJ1yuYCGHZRxeIybiR7o HWGMOI94zNAkHCEgQE6wm4L/rGexQmivFgf+7RQ2FY8lOnjSTUF8TntBQcCTv2lW8Hnh ooxw== X-Gm-Message-State: AOAM532BzE7ocmq1lpU5EqXjYUKQDufaf1WH/G8bIPunbCkyFDq9UjHJ zkQEmojbBke7V9nk03Yr7l8/oWTqsRk2Mcnc X-Google-Smtp-Source: ABdhPJydMaa6wATfNZ7uY9wcNSxmtIWFvv9HZuKcmUo0EyNcCpRgYD5IA1w+AuPm5n/ks1Gkkv/mhg== X-Received: by 2002:a05:6512:3b0b:: with SMTP id f11mr13576614lfv.374.1636534710000; Wed, 10 Nov 2021 00:58:30 -0800 (PST) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id y11sm636068ljh.54.2021.11.10.00.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Nov 2021 00:58:29 -0800 (PST) Date: Wed, 10 Nov 2021 08:58:28 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Extend optimized equality of 2-element arrays Message-ID: <20211110085828.GA2811025@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.0 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Piotr Trojanek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Array equality is typically expanded into a loop, but for small arrays such loops are inefficient (and the code generator might fail to turn them into linear code, especially when the array contains records). We optimize equality of 2-element arrays into an AND THEN expression, but only for array types whose bounds are given by a range expression. Now we do this for all 2-element arrays with compile-time known bounds, regardless of how their bounds are given, e.g. for array types declared like: type A1 is array (Integer range 1 .. 2) of ...; type A2 is array (Boolean) of ...; Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch4.adb (Expand_Array_Equality): Remove check of the array bound being an N_Range node; use Type_High_Bound/Type_Low_Bound, which handle all kinds of array bounds. diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -1988,14 +1988,16 @@ package body Exp_Ch4 is and then Ltyp = Rtyp and then Is_Constrained (Ltyp) and then Number_Dimensions (Ltyp) = 1 - and then Nkind (First_Idx) = N_Range - and then Compile_Time_Known_Value (Low_Bound (First_Idx)) - and then Compile_Time_Known_Value (High_Bound (First_Idx)) - and then Expr_Value (High_Bound (First_Idx)) = - Expr_Value (Low_Bound (First_Idx)) + 1 + and then Compile_Time_Known_Bounds (Ltyp) + and then Expr_Value (Type_High_Bound (Etype (First_Idx))) = + Expr_Value (Type_Low_Bound (Etype (First_Idx))) + 1 then declare Ctyp : constant Entity_Id := Component_Type (Ltyp); + Low_B : constant Node_Id := + Type_Low_Bound (Etype (First_Idx)); + High_B : constant Node_Id := + Type_High_Bound (Etype (First_Idx)); L, R : Node_Id; TestL, TestH : Node_Id; @@ -2003,28 +2005,24 @@ package body Exp_Ch4 is L := Make_Indexed_Component (Loc, Prefix => New_Copy_Tree (New_Lhs), - Expressions => - New_List (New_Copy_Tree (Low_Bound (First_Idx)))); + Expressions => New_List (New_Copy_Tree (Low_B))); R := Make_Indexed_Component (Loc, Prefix => New_Copy_Tree (New_Rhs), - Expressions => - New_List (New_Copy_Tree (Low_Bound (First_Idx)))); + Expressions => New_List (New_Copy_Tree (Low_B))); TestL := Expand_Composite_Equality (Nod, Ctyp, L, R, Bodies); L := Make_Indexed_Component (Loc, Prefix => New_Lhs, - Expressions => - New_List (New_Copy_Tree (High_Bound (First_Idx)))); + Expressions => New_List (New_Copy_Tree (High_B))); R := Make_Indexed_Component (Loc, Prefix => New_Rhs, - Expressions => - New_List (New_Copy_Tree (High_Bound (First_Idx)))); + Expressions => New_List (New_Copy_Tree (High_B))); TestH := Expand_Composite_Equality (Nod, Ctyp, L, R, Bodies);