From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Piotr Trojanek <trojanek@adacore.com>
Subject: [Ada] Extend optimized equality of 2-element arrays
Date: Wed, 10 Nov 2021 08:58:28 +0000 [thread overview]
Message-ID: <20211110085828.GA2811025@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 825 bytes --]
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.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2496 bytes --]
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);
reply other threads:[~2021-11-10 8:58 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211110085828.GA2811025@adacore.com \
--to=derodat@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=trojanek@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).