* [PATCH] DWARF: space-optimize loc. descr. for integer literals on 32-bit targets
@ 2016-08-18 9:33 Pierre-Marie de Rodat
2016-08-18 11:21 ` Trevor Saunders
0 siblings, 1 reply; 8+ messages in thread
From: Pierre-Marie de Rodat @ 2016-08-18 9:33 UTC (permalink / raw)
To: gcc-patches; +Cc: Pierre-Marie de Rodat
Hello,
This enhances location description generation so that the generated
opcodes for integer literals are as space-efficient when HOST_WIDE_INT
is 64-bits large than when it's 32-bits large. In particular, this
reduces the size of the opcodes generated to produce big unsigned
literals using small literal integers instead.
Bootstrapped and regtested on x86-linux (no regression). I also checked
that the new testcase fails with mainline. Ok to commit? Thank you in
advance!
gcc/
* dwarf2out.c (int_loc_descriptor): Generate opcodes for another
equivalent 32-bit constant (modulo 2**32) when that yields
smaller instructions.
(size_of_int_loc_descriptor): Update accordingly.
---
gcc/dwarf2out.c | 31 ++++++++++++++++++++++++++-----
gcc/testsuite/gnat.dg/debug8.adb | 29 +++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 5 deletions(-)
create mode 100644 gcc/testsuite/gnat.dg/debug8.adb
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 0fdab9a..f175ea1 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -11954,20 +11954,36 @@ int_loc_descriptor (HOST_WIDE_INT i)
/* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
while DW_OP_const4u is 5 bytes. */
return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
+
+ else if (HOST_BITS_PER_WIDE_INT > 32
+ && DWARF2_ADDR_SIZE == 4 && i > 0x7fffffff
+ && size_of_int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i)
+ <= 4)
+ {
+ /* As i >= 2**31, the double cast above will yield a negative number.
+ Since wrapping is defined in DWARF expressions we can output big
+ positive integers as small negative ones, regardless of the size
+ of host wide ints.
+
+ Here, since the evaluator will handle 32-bit values and since i >=
+ 2**31, we know it's going to be interpreted as a negative literal:
+ store it this way if we can do better than 5 bytes this way. */
+ return int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i);
+ }
else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
op = DW_OP_const4u;
+
+ /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
+ least 6 bytes: see if we can do better before falling back to it. */
else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
&& clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
- /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
- while DW_OP_constu of constant >= 0x100000000 takes at least
- 6 bytes. */
+ /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes. */
return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
&& clz + 16 + (size_of_uleb128 (i) > 5 ? 255 : 31)
>= HOST_BITS_PER_WIDE_INT)
/* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
- DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
- while DW_OP_constu takes in this case at least 6 bytes. */
+ DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes. */
return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 16);
else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
&& clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
@@ -12192,6 +12208,11 @@ size_of_int_loc_descriptor (HOST_WIDE_INT i)
&& clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
- clz - 8);
+ else if (HOST_BITS_PER_WIDE_INT > 32
+ && DWARF2_ADDR_SIZE == 4 && i > 0x7fffffff
+ && size_of_int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i)
+ <= 4)
+ return size_of_int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i);
else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
return 5;
s = size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
diff --git a/gcc/testsuite/gnat.dg/debug8.adb b/gcc/testsuite/gnat.dg/debug8.adb
new file mode 100644
index 0000000..fabcc22
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/debug8.adb
@@ -0,0 +1,29 @@
+-- { dg-do compile }
+-- { dg-options "-cargs -g -fgnat-encodings=minimal -dA" }
+-- { dg-final { scan-assembler-not "DW_OP_const4u" } }
+-- { dg-final { scan-assembler-not "DW_OP_const8u" } }
+
+-- The DW_AT_byte_size attribute DWARF expression for the
+-- DW_TAG_structure_type DIE that describes Rec_Type contains the -4u literal.
+-- Check that it is not created using an inefficient encoding (DW_OP_const1s
+-- is expected).
+
+procedure Debug8 is
+
+ type Rec_Type (I : Integer) is record
+ B : Boolean;
+ case I is
+ when 0 =>
+ null;
+ when 1 .. 10 =>
+ C : Character;
+ when others =>
+ N : Natural;
+ end case;
+ end record;
+
+ R : access Rec_Type := null;
+
+begin
+ null;
+end Debug8;
--
2.9.3
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] DWARF: space-optimize loc. descr. for integer literals on 32-bit targets
2016-08-18 9:33 [PATCH] DWARF: space-optimize loc. descr. for integer literals on 32-bit targets Pierre-Marie de Rodat
@ 2016-08-18 11:21 ` Trevor Saunders
2016-08-18 14:02 ` Pierre-Marie de Rodat
0 siblings, 1 reply; 8+ messages in thread
From: Trevor Saunders @ 2016-08-18 11:21 UTC (permalink / raw)
To: Pierre-Marie de Rodat; +Cc: gcc-patches
On Thu, Aug 18, 2016 at 11:33:06AM +0200, Pierre-Marie de Rodat wrote:
> Hello,
>
> This enhances location description generation so that the generated
> opcodes for integer literals are as space-efficient when HOST_WIDE_INT
> is 64-bits large than when it's 32-bits large. In particular, this
> reduces the size of the opcodes generated to produce big unsigned
> literals using small literal integers instead.
>
> Bootstrapped and regtested on x86-linux (no regression). I also checked
> that the new testcase fails with mainline. Ok to commit? Thank you in
> advance!
>
> gcc/
>
> * dwarf2out.c (int_loc_descriptor): Generate opcodes for another
> equivalent 32-bit constant (modulo 2**32) when that yields
> smaller instructions.
> (size_of_int_loc_descriptor): Update accordingly.
> ---
> gcc/dwarf2out.c | 31 ++++++++++++++++++++++++++-----
> gcc/testsuite/gnat.dg/debug8.adb | 29 +++++++++++++++++++++++++++++
> 2 files changed, 55 insertions(+), 5 deletions(-)
> create mode 100644 gcc/testsuite/gnat.dg/debug8.adb
>
> diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
> index 0fdab9a..f175ea1 100644
> --- a/gcc/dwarf2out.c
> +++ b/gcc/dwarf2out.c
> @@ -11954,20 +11954,36 @@ int_loc_descriptor (HOST_WIDE_INT i)
> /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
> while DW_OP_const4u is 5 bytes. */
> return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
> +
> + else if (HOST_BITS_PER_WIDE_INT > 32
HOST_BITS_PER_WIDE_INT is now always 64, so you don't need that check.
Trev
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] DWARF: space-optimize loc. descr. for integer literals on 32-bit targets
2016-08-18 11:21 ` Trevor Saunders
@ 2016-08-18 14:02 ` Pierre-Marie de Rodat
2016-08-31 11:42 ` [PATCH, PING] " Pierre-Marie de Rodat
0 siblings, 1 reply; 8+ messages in thread
From: Pierre-Marie de Rodat @ 2016-08-18 14:02 UTC (permalink / raw)
To: Trevor Saunders; +Cc: gcc-patches
On 08/18/2016 01:29 PM, Trevor Saunders wrote:
> HOST_BITS_PER_WIDE_INT is now always 64, so you don't need that check.
Good point, thank you! Iâll adapt the patch.
--
Pierre-Marie de Rodat
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH, PING] DWARF: space-optimize loc. descr. for integer literals on 32-bit targets
2016-08-18 14:02 ` Pierre-Marie de Rodat
@ 2016-08-31 11:42 ` Pierre-Marie de Rodat
2016-09-27 14:09 ` [PATCH, PING*2] " Pierre-Marie de Rodat
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Pierre-Marie de Rodat @ 2016-08-31 11:42 UTC (permalink / raw)
To: gcc-patches; +Cc: Trevor Saunders
[-- Attachment #1: Type: text/plain, Size: 190 bytes --]
Hello,
Ping for the patch submitted at
<https://gcc.gnu.org/ml/gcc-patches/2016-08/msg01314.html>. Also, hereâs
the update that Trevor suggested.
Thanks!
--
Pierre-Marie de Rodat
[-- Attachment #2: 0001-DWARF-space-optimize-loc.-descr.-for-integer-literal.patch --]
[-- Type: text/x-diff, Size: 4831 bytes --]
From da6753ad98127778e8923db63ce51b52a853ed17 Mon Sep 17 00:00:00 2001
From: Pierre-Marie de Rodat <derodat@adacore.com>
Date: Fri, 24 Jul 2015 15:48:33 +0200
Subject: [PATCH] DWARF: space-optimize loc. descr. for integer literals on
32-bit targets
This enhances location description generation so that the generated
opcodes for integer literals are as space-efficient when HOST_WIDE_INT
is 64-bits large than when it's 32-bits large. In particular, this
reduces the size of the opcodes generated to produce big unsigned
literals using small literal integers instead.
gcc/
* dwarf2out.c (int_loc_descriptor): Generate opcodes for another
equivalent 32-bit constant (modulo 2**32) when that yields
smaller instructions.
(size_of_int_loc_descriptor): Update accordingly.
---
gcc/dwarf2out.c | 29 ++++++++++++++++++++++++-----
gcc/testsuite/gnat.dg/debug8.adb | 29 +++++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 5 deletions(-)
create mode 100644 gcc/testsuite/gnat.dg/debug8.adb
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 0fdab9a..2591f89 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -11954,20 +11954,35 @@ int_loc_descriptor (HOST_WIDE_INT i)
/* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
while DW_OP_const4u is 5 bytes. */
return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
+
+ else if (DWARF2_ADDR_SIZE == 4 && i > 0x7fffffff
+ && size_of_int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i)
+ <= 4)
+ {
+ /* As i >= 2**31, the double cast above will yield a negative number.
+ Since wrapping is defined in DWARF expressions we can output big
+ positive integers as small negative ones, regardless of the size
+ of host wide ints.
+
+ Here, since the evaluator will handle 32-bit values and since i >=
+ 2**31, we know it's going to be interpreted as a negative literal:
+ store it this way if we can do better than 5 bytes this way. */
+ return int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i);
+ }
else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
op = DW_OP_const4u;
+
+ /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
+ least 6 bytes: see if we can do better before falling back to it. */
else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
&& clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
- /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
- while DW_OP_constu of constant >= 0x100000000 takes at least
- 6 bytes. */
+ /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes. */
return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
&& clz + 16 + (size_of_uleb128 (i) > 5 ? 255 : 31)
>= HOST_BITS_PER_WIDE_INT)
/* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
- DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
- while DW_OP_constu takes in this case at least 6 bytes. */
+ DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes. */
return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 16);
else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
&& clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
@@ -12192,6 +12207,10 @@ size_of_int_loc_descriptor (HOST_WIDE_INT i)
&& clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
- clz - 8);
+ else if (DWARF2_ADDR_SIZE == 4 && i > 0x7fffffff
+ && size_of_int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i)
+ <= 4)
+ return size_of_int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i);
else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
return 5;
s = size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
diff --git a/gcc/testsuite/gnat.dg/debug8.adb b/gcc/testsuite/gnat.dg/debug8.adb
new file mode 100644
index 0000000..fabcc22
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/debug8.adb
@@ -0,0 +1,29 @@
+-- { dg-do compile }
+-- { dg-options "-cargs -g -fgnat-encodings=minimal -dA" }
+-- { dg-final { scan-assembler-not "DW_OP_const4u" } }
+-- { dg-final { scan-assembler-not "DW_OP_const8u" } }
+
+-- The DW_AT_byte_size attribute DWARF expression for the
+-- DW_TAG_structure_type DIE that describes Rec_Type contains the -4u literal.
+-- Check that it is not created using an inefficient encoding (DW_OP_const1s
+-- is expected).
+
+procedure Debug8 is
+
+ type Rec_Type (I : Integer) is record
+ B : Boolean;
+ case I is
+ when 0 =>
+ null;
+ when 1 .. 10 =>
+ C : Character;
+ when others =>
+ N : Natural;
+ end case;
+ end record;
+
+ R : access Rec_Type := null;
+
+begin
+ null;
+end Debug8;
--
1.8.2.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH, PING*2] DWARF: space-optimize loc. descr. for integer literals on 32-bit targets
2016-08-31 11:42 ` [PATCH, PING] " Pierre-Marie de Rodat
@ 2016-09-27 14:09 ` Pierre-Marie de Rodat
2016-10-11 15:52 ` [PATCH, PING*3] " Pierre-Marie de Rodat
2016-10-12 8:14 ` [PATCH, PING] " Richard Biener
2 siblings, 0 replies; 8+ messages in thread
From: Pierre-Marie de Rodat @ 2016-09-27 14:09 UTC (permalink / raw)
To: gcc-patches; +Cc: Trevor Saunders
Hello,
Ping for the patch submitted at
<https://gcc.gnu.org/ml/gcc-patches/2016-08/msg02117.html>. Thanks!
--
Pierre-Marie de Rodat
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH, PING*3] DWARF: space-optimize loc. descr. for integer literals on 32-bit targets
2016-08-31 11:42 ` [PATCH, PING] " Pierre-Marie de Rodat
2016-09-27 14:09 ` [PATCH, PING*2] " Pierre-Marie de Rodat
@ 2016-10-11 15:52 ` Pierre-Marie de Rodat
2016-10-12 8:14 ` [PATCH, PING] " Richard Biener
2 siblings, 0 replies; 8+ messages in thread
From: Pierre-Marie de Rodat @ 2016-10-11 15:52 UTC (permalink / raw)
To: gcc-patches; +Cc: Trevor Saunders
Hello,
Ping for the patch submitted at
<https://gcc.gnu.org/ml/gcc-patches/2016-08/msg02117.html>. Thanks!
--
Pierre-Marie de Rodat
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH, PING] DWARF: space-optimize loc. descr. for integer literals on 32-bit targets
2016-08-31 11:42 ` [PATCH, PING] " Pierre-Marie de Rodat
2016-09-27 14:09 ` [PATCH, PING*2] " Pierre-Marie de Rodat
2016-10-11 15:52 ` [PATCH, PING*3] " Pierre-Marie de Rodat
@ 2016-10-12 8:14 ` Richard Biener
2016-10-12 8:39 ` Pierre-Marie de Rodat
2 siblings, 1 reply; 8+ messages in thread
From: Richard Biener @ 2016-10-12 8:14 UTC (permalink / raw)
To: Pierre-Marie de Rodat; +Cc: GCC Patches, Trevor Saunders
On Wed, Aug 31, 2016 at 1:41 PM, Pierre-Marie de Rodat
<derodat@adacore.com> wrote:
> Hello,
>
> Ping for the patch submitted at
> <https://gcc.gnu.org/ml/gcc-patches/2016-08/msg01314.html>. Also, here’s the
> update that Trevor suggested.
Ok.
Thanks,
Richard.
> Thanks!
>
> --
> Pierre-Marie de Rodat
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH, PING] DWARF: space-optimize loc. descr. for integer literals on 32-bit targets
2016-10-12 8:14 ` [PATCH, PING] " Richard Biener
@ 2016-10-12 8:39 ` Pierre-Marie de Rodat
0 siblings, 0 replies; 8+ messages in thread
From: Pierre-Marie de Rodat @ 2016-10-12 8:39 UTC (permalink / raw)
To: Richard Biener; +Cc: GCC Patches, Trevor Saunders
On 10/12/2016 10:13 AM, Richard Biener wrote:
> Ok.
>
> Thanks,
Committed. Thank you!
--
Pierre-Marie de Rodat
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-10-12 8:39 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-18 9:33 [PATCH] DWARF: space-optimize loc. descr. for integer literals on 32-bit targets Pierre-Marie de Rodat
2016-08-18 11:21 ` Trevor Saunders
2016-08-18 14:02 ` Pierre-Marie de Rodat
2016-08-31 11:42 ` [PATCH, PING] " Pierre-Marie de Rodat
2016-09-27 14:09 ` [PATCH, PING*2] " Pierre-Marie de Rodat
2016-10-11 15:52 ` [PATCH, PING*3] " Pierre-Marie de Rodat
2016-10-12 8:14 ` [PATCH, PING] " Richard Biener
2016-10-12 8:39 ` Pierre-Marie de Rodat
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).