public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [x86 testsuite] preserve full register across main
@ 2019-08-23 19:23 Alexandre Oliva
  2019-08-24 19:02 ` Uros Bizjak
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Oliva @ 2019-08-23 19:23 UTC (permalink / raw)
  To: gcc-patches; +Cc: Rainer Orth, Mike Stump, Jan Hubicka, Uros Bizjak

This test uses a call-saved register as a global variable.  It
attempts to preserve its value across main, but only the lower int
part is preserved, which is not good enough for x86_64, when the
runtime that calls main() happens to hold something in the chosen
register that is not a zero-extension from the 32-bit value, and
rightfully expects the full register to remain unchanged when main()
returns.

Tested on x86_64-linux-gnu, both -m64 and -m32.  Ok to install?


for  gcc/testsuite/ChangeLog

	* gcc.target/i386/20020616-1.c: Preserve full register across
	main.
---
 gcc/testsuite/gcc.target/i386/20020616-1.c |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.target/i386/20020616-1.c b/gcc/testsuite/gcc.target/i386/20020616-1.c
index 5641826b4837..3b8cf8e41783 100644
--- a/gcc/testsuite/gcc.target/i386/20020616-1.c
+++ b/gcc/testsuite/gcc.target/i386/20020616-1.c
@@ -2,12 +2,16 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
+/* We need this type to be as wide as the register chosen below, so
+   that, when we preserve it across main, we preserve all of it.  */
+typedef long reg_type;
+
 #if !__PIC__
-register int k asm("%ebx");
+register reg_type k asm("%ebx");
 #elif __amd64
-register int k asm("%r12");
+register reg_type k asm("%r12");
 #else
-register int k asm("%esi");
+register reg_type k asm("%esi");
 #endif
 
 void __attribute__((noinline))
@@ -18,7 +22,7 @@ foo()
 
 void test()
 {
-  int i;
+  reg_type i;
   for (i = 0; i < 10; i += k)
     {
       k = 0;
@@ -28,7 +32,7 @@ void test()
 
 int main()
 {
-  int old = k;
+  reg_type old = k;
   test();
   k = old;
   return 0;

-- 
Alexandre Oliva, freedom fighter  he/him   https://FSFLA.org/blogs/lxo
Be the change, be Free!                 FSF Latin America board member
GNU Toolchain Engineer                        Free Software Evangelist
Hay que enGNUrecerse, pero sin perder la terGNUra jamás - Che GNUevara

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [x86 testsuite] preserve full register across main
  2019-08-23 19:23 [x86 testsuite] preserve full register across main Alexandre Oliva
@ 2019-08-24 19:02 ` Uros Bizjak
  2019-09-03  5:36   ` Alexandre Oliva
  0 siblings, 1 reply; 3+ messages in thread
From: Uros Bizjak @ 2019-08-24 19:02 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc-patches, Rainer Orth, Mike Stump, Jan Hubicka

On Friday, August 23, 2019, Alexandre Oliva <oliva@adacore.com> wrote:
> This test uses a call-saved register as a global variable.  It
> attempts to preserve its value across main, but only the lower int
> part is preserved, which is not good enough for x86_64, when the
> runtime that calls main() happens to hold something in the chosen
> register that is not a zero-extension from the 32-bit value, and
> rightfully expects the full register to remain unchanged when main()
> returns.
>
> Tested on x86_64-linux-gnu, both -m64 and -m32.  Ok to install?
>
>
> for  gcc/testsuite/ChangeLog
>
>         * gcc.target/i386/20020616-1.c: Preserve full register across
>         main.
> ---
>  gcc/testsuite/gcc.target/i386/20020616-1.c |   14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/gcc/testsuite/gcc.target/i386/20020616-1.c
b/gcc/testsuite/gcc.target/i386/20020616-1.c
> index 5641826b4837..3b8cf8e41783 100644
> --- a/gcc/testsuite/gcc.target/i386/20020616-1.c
> +++ b/gcc/testsuite/gcc.target/i386/20020616-1.c
> @@ -2,12 +2,16 @@
>  /* { dg-do run } */
>  /* { dg-options "-O2" } */
>
> +/* We need this type to be as wide as the register chosen below, so
> +   that, when we preserve it across main, we preserve all of it.  */
> +typedef long reg_type;

Can __attribute__ ((mode (__word__))) be used here?

Otherwise OK.

Thanks,
Uros.

>  #if !__PIC__
> -register int k asm("%ebx");
> +register reg_type k asm("%ebx");
>  #elif __amd64
> -register int k asm("%r12");
> +register reg_type k asm("%r12");
>  #else
> -register int k asm("%esi");
> +register reg_type k asm("%esi");
>  #endif
>
>  void __attribute__((noinline))
> @@ -18,7 +22,7 @@ foo()
>
>  void test()
>  {
> -  int i;
> +  reg_type i;
>    for (i = 0; i < 10; i += k)
>      {
>        k = 0;
> @@ -28,7 +32,7 @@ void test()
>
>  int main()
>  {
> -  int old = k;
> +  reg_type old = k;
>    test();
>    k = old;
>    return 0;
>
> --
> Alexandre Oliva, freedom fighter  he/him   https://FSFLA.org/blogs/lxo
> Be the change, be Free!                 FSF Latin America board member
> GNU Toolchain Engineer                        Free Software Evangelist
> Hay que enGNUrecerse, pero sin perder la terGNUra jamás - Che GNUevara
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [x86 testsuite] preserve full register across main
  2019-08-24 19:02 ` Uros Bizjak
@ 2019-09-03  5:36   ` Alexandre Oliva
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Oliva @ 2019-09-03  5:36 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: gcc-patches, Rainer Orth, Mike Stump, Jan Hubicka

On Aug 24, 2019, Uros Bizjak <ubizjak@gmail.com> wrote:

> Can __attribute__ ((mode (__word__))) be used here?

Oh, nice, yes, thanks!

> Otherwise OK.

Here's what I'm installing.


for  gcc/testsuite/ChangeLog

	* gcc.target/i386/20020616-1.c: Preserve full register across
	main.
---
 gcc/testsuite/gcc.target/i386/20020616-1.c |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.target/i386/20020616-1.c b/gcc/testsuite/gcc.target/i386/20020616-1.c
index 5641826b4837c..48dea27956ce2 100644
--- a/gcc/testsuite/gcc.target/i386/20020616-1.c
+++ b/gcc/testsuite/gcc.target/i386/20020616-1.c
@@ -2,12 +2,16 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
+/* We need this type to be as wide as the register chosen below, so
+   that, when we preserve it across main, we preserve all of it.  */
+typedef int __attribute__ ((mode (__word__))) reg_type;
+
 #if !__PIC__
-register int k asm("%ebx");
+register reg_type k asm("%ebx");
 #elif __amd64
-register int k asm("%r12");
+register reg_type k asm("%r12");
 #else
-register int k asm("%esi");
+register reg_type k asm("%esi");
 #endif
 
 void __attribute__((noinline))
@@ -18,7 +22,7 @@ foo()
 
 void test()
 {
-  int i;
+  reg_type i;
   for (i = 0; i < 10; i += k)
     {
       k = 0;
@@ -28,7 +32,7 @@ void test()
 
 int main()
 {
-  int old = k;
+  reg_type old = k;
   test();
   k = old;
   return 0;


-- 
Alexandre Oliva, freedom fighter  he/him   https://FSFLA.org/blogs/lxo
Be the change, be Free!       FSF.org & FSF Latin America board member
GNU Toolchain Engineer                        Free Software Evangelist
Hay que enGNUrecerse, pero sin perder la terGNUra jamás - Che GNUevara

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-09-03  5:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-23 19:23 [x86 testsuite] preserve full register across main Alexandre Oliva
2019-08-24 19:02 ` Uros Bizjak
2019-09-03  5:36   ` Alexandre Oliva

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).