public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-640] [Ada] Improve optimization of "=" on bit-packed arrays
Date: Thu, 19 May 2022 14:06:49 +0000 (GMT)	[thread overview]
Message-ID: <20220519140649.57AD4383D819@sourceware.org> (raw)

https://gcc.gnu.org/g:88f7b07de7579251f5134b65dad406fdfda3d057

commit r13-640-g88f7b07de7579251f5134b65dad406fdfda3d057
Author: Bob Duff <duff@adacore.com>
Date:   Thu Apr 7 13:23:20 2022 -0400

    [Ada] Improve optimization of "=" on bit-packed arrays
    
    This patch fixes a performance regression, introduced by a previous bug
    fix.  That fix had the unintended side effect of removing the
    optimization in cases where the two operands are of two different
    compiler-generated modular types.
    
    gcc/ada/
    
            * exp_pakd.adb (Expand_Packed_Eq): Replace the check for *same*
            modular type, with a check for any modular type, and assert that
            the two types have the same modulus and so on.
            * exp_pakd.ads: Minor comment improvements.

Diff:
---
 gcc/ada/exp_pakd.adb | 12 ++++++++++--
 gcc/ada/exp_pakd.ads | 13 +++++++------
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/gcc/ada/exp_pakd.adb b/gcc/ada/exp_pakd.adb
index b39b2a7136c..d4a62ace9c2 100644
--- a/gcc/ada/exp_pakd.adb
+++ b/gcc/ada/exp_pakd.adb
@@ -1930,9 +1930,17 @@ package body Exp_Pakd is
       --  modular case we guarantee that the unused bits are always zeroes.
       --  We do have to compare the lengths because we could be comparing
       --  two different subtypes of the same base type. We can only do this
-      --  if the PATs on both sides are the same.
+      --  if the PATs on both sides are modular (in which case they are
+      --  necessarily structurally the same -- same Modulus and so on);
+      --  otherwise, we have a case where the right operand is not of
+      --  compile time known size.
+
+      if Is_Modular_Integer_Type (PAT)
+        and then Is_Modular_Integer_Type (Etype (R))
+      then
+         pragma Assert (RM_Size (Etype (R)) = RM_Size (PAT));
+         pragma Assert (Modulus (Etype (R)) = Modulus (PAT));
 
-      if Is_Modular_Integer_Type (PAT) and then PAT = Etype (R) then
          Rewrite (N,
            Make_And_Then (Loc,
              Left_Opnd =>
diff --git a/gcc/ada/exp_pakd.ads b/gcc/ada/exp_pakd.ads
index f61ae089730..e80787acdd7 100644
--- a/gcc/ada/exp_pakd.ads
+++ b/gcc/ada/exp_pakd.ads
@@ -41,7 +41,8 @@ package Exp_Pakd is
 
    --  This packed array type has the name xxxPn, where xxx is the name
    --  of the packed type, and n is the component size. The expanded
-   --  declaration declares a type that is one of the following:
+   --  declaration declares a type that is one of the following (sizes
+   --  below are in bytes):
 
    --    For an unconstrained array with component size 1,2,4 or any other
    --    odd component size. These are the cases in which we do not need
@@ -49,10 +50,10 @@ package Exp_Pakd is
 
    --      type xxxPn is new Packed_Bytes1;
 
-   --    For an unconstrained array with component size that is divisible
-   --    by 2, but not divisible by 4 (other than 2 itself). These are the
-   --    cases in which we can generate better code if the underlying array
-   --    is 2-byte aligned (see System.Pack_14 in file s-pack14 for example).
+   --    For an unconstrained array with component size greater than 2, that is
+   --    divisible by 2, but not divisible by 4. These are the cases in which
+   --    we can generate better code if the underlying array is 2-byte aligned
+   --    (see System.Pack_14 in file s-pack14 for example).
 
    --      type xxxPn is new Packed_Bytes2;
 
@@ -942,7 +943,7 @@ package Exp_Pakd is
    --  N is an N_Op_Eq node where the operands are packed arrays whose
    --  representation is an array-of-bytes type (the case where a modular
    --  type is used for the representation does not require any special
-   --  handling, because in the modular case, unused bits are zeroes.
+   --  handling, because in the modular case, unused bits are zeroes).
 
    procedure Expand_Packed_Not (N : Node_Id);
    --  N is an N_Op_Not node where the operand is packed array of Boolean


                 reply	other threads:[~2022-05-19 14:06 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=20220519140649.57AD4383D819@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).