summaryrefslogtreecommitdiffstats
path: root/gcc
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2022-04-07 13:23:20 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2022-05-19 14:05:29 +0000
commit88f7b07de7579251f5134b65dad406fdfda3d057 (patch)
treef1c8accae93142fd6cbcf5b10b07e29106b9dd06 /gcc
parent[Ada] Casing style on record components (diff)
downloadgcc-88f7b07de7579251f5134b65dad406fdfda3d057.tar.gz
gcc-88f7b07de7579251f5134b65dad406fdfda3d057.tar.bz2
gcc-88f7b07de7579251f5134b65dad406fdfda3d057.tar.xz
[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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/exp_pakd.adb12
-rw-r--r--gcc/ada/exp_pakd.ads13
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
1930 -- modular case we guarantee that the unused bits are always zeroes. 1930 -- modular case we guarantee that the unused bits are always zeroes.
1931 -- We do have to compare the lengths because we could be comparing 1931 -- We do have to compare the lengths because we could be comparing
1932 -- two different subtypes of the same base type. We can only do this 1932 -- two different subtypes of the same base type. We can only do this
1933 -- if the PATs on both sides are the same. 1933 -- if the PATs on both sides are modular (in which case they are
1934 -- necessarily structurally the same -- same Modulus and so on);
1935 -- otherwise, we have a case where the right operand is not of
1936 -- compile time known size.
1937
1938 if Is_Modular_Integer_Type (PAT)
1939 and then Is_Modular_Integer_Type (Etype (R))
1940 then
1941 pragma Assert (RM_Size (Etype (R)) = RM_Size (PAT));
1942 pragma Assert (Modulus (Etype (R)) = Modulus (PAT));
1934 1943
1935 if Is_Modular_Integer_Type (PAT) and then PAT = Etype (R) then
1936 Rewrite (N, 1944 Rewrite (N,
1937 Make_And_Then (Loc, 1945 Make_And_Then (Loc,
1938 Left_Opnd => 1946 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
41 41
42 -- This packed array type has the name xxxPn, where xxx is the name 42 -- This packed array type has the name xxxPn, where xxx is the name
43 -- of the packed type, and n is the component size. The expanded 43 -- of the packed type, and n is the component size. The expanded
44 -- declaration declares a type that is one of the following: 44 -- declaration declares a type that is one of the following (sizes
45 -- below are in bytes):
45 46
46 -- For an unconstrained array with component size 1,2,4 or any other 47 -- For an unconstrained array with component size 1,2,4 or any other
47 -- odd component size. These are the cases in which we do not need 48 -- odd component size. These are the cases in which we do not need
@@ -49,10 +50,10 @@ package Exp_Pakd is
49 50
50 -- type xxxPn is new Packed_Bytes1; 51 -- type xxxPn is new Packed_Bytes1;
51 52
52 -- For an unconstrained array with component size that is divisible 53 -- For an unconstrained array with component size greater than 2, that is
53 -- by 2, but not divisible by 4 (other than 2 itself). These are the 54 -- divisible by 2, but not divisible by 4. These are the cases in which
54 -- cases in which we can generate better code if the underlying array 55 -- we can generate better code if the underlying array is 2-byte aligned
55 -- is 2-byte aligned (see System.Pack_14 in file s-pack14 for example). 56 -- (see System.Pack_14 in file s-pack14 for example).
56 57
57 -- type xxxPn is new Packed_Bytes2; 58 -- type xxxPn is new Packed_Bytes2;
58 59
@@ -942,7 +943,7 @@ package Exp_Pakd is
942 -- N is an N_Op_Eq node where the operands are packed arrays whose 943 -- N is an N_Op_Eq node where the operands are packed arrays whose
943 -- representation is an array-of-bytes type (the case where a modular 944 -- representation is an array-of-bytes type (the case where a modular
944 -- type is used for the representation does not require any special 945 -- type is used for the representation does not require any special
945 -- handling, because in the modular case, unused bits are zeroes. 946 -- handling, because in the modular case, unused bits are zeroes).
946 947
947 procedure Expand_Packed_Not (N : Node_Id); 948 procedure Expand_Packed_Not (N : Node_Id);
948 -- N is an N_Op_Not node where the operand is packed array of Boolean 949 -- N is an N_Op_Not node where the operand is packed array of Boolean