Re: PATCH [x86_64] PR20020 - 128 bit structs not targeted to TImode

2012-08-15 Thread H.J. Lu
On Tue, Aug 14, 2012 at 2:34 PM, Gary Funck  wrote:
> Attached, is an updated patch (with change logs).
>
> The test cases are now in gcc.target/i386 and the
> target selection is "dg-require-effective-target int128" only.
>
> Verified that the tests correctly detect the presence/lack
> of TImode support.
>

Here is a patch, which passed tests on Linux/x86-64/ia32 with

--enable-languages=c,c++,fortran,java,lto,objc,ada,obj-c++,go

on Linux/x32 with

--enable-languages=c,c++,fortran,java,lto,objc,obj-c++,go

I skipped Ada on x32 since Ada run-time library assumes
clock_t/time_t are long.

I added a target hook, type_blkmode_p, so that a backend
can force a type to BLKmode.  There is a macro,
MEMBER_TYPE_FORCES_BLK.  But it will also set

struct
{
  long double x;
};

to BLKmode instead of XFmode.  I think we can replace
MEMBER_TYPE_FORCES_BLK with the new type_blkmode_p
target hook.


-- 
H.J.
---
gcc/

2012-08-15  H.J. Lu  
Gary Funck 

PR target/20020
* stor-layout.c (compute_record_mode): Use BLKmode if
targetm.type_blkmode_p returns true.

* target.def (type_blkmode_p): New target hook.
* doc/tm.texi.in: Regenerated.
* doc/tm.texi.in: Likewise.

* config/i386/i386.c (ix86_type_blkmode_p): New function.
(TARGET_TYPE_BLKMODE_P): New macro.

* config/i386/i386.h (MAX_FIXED_MODE_SIZE): New macro.

gcc/testsuite/

2012-08-15  H.J. Lu  
Gary Funck 

PR target/20020
* gcc.target/i386/pr20020-1.c: New test.
* gcc.target/i386/pr20020-2.c: Likewise.
* gcc.target/i386/pr20020-3.c: Likewise.


gcc-pr20020.patch
Description: Binary data


Re: PATCH [x86_64] PR20020 - 128 bit structs not targeted to TImode

2012-08-14 Thread Gary Funck
Attached, is an updated patch (with change logs).

The test cases are now in gcc.target/i386 and the
target selection is "dg-require-effective-target int128" only.

Verified that the tests correctly detect the presence/lack
of TImode support.

- Gary
Index: gcc/config/i386/i386.h
===
--- gcc/config/i386/i386.h  (revision 190398)
+++ gcc/config/i386/i386.h  (working copy)
@@ -1816,6 +1816,10 @@ do { 
\
 #define BRANCH_COST(speed_p, predictable_p) \
   (!(speed_p) ? 2 : (predictable_p) ? 0 : ix86_branch_cost)
 
+/* An integer expression for the size in bits of the largest integer machine
+   mode that should actually be used.  We allow pairs of registers.  */
+#define MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (TARGET_64BIT ? TImode : DImode)
+
 /* Define this macro as a C expression which is nonzero if accessing
less than a word of memory (i.e. a `char' or a `short') is no
faster than accessing a word of memory, i.e., if such access
Index: gcc/ChangeLog
===
--- gcc/ChangeLog   (revision 190398)
+++ gcc/ChangeLog   (working copy)
@@ -1,3 +1,10 @@
+2012-08-14  Gary Funck 
+
+   PR target/20020
+   * config/i386/i386.h (MAX_FIXED_MODE_SIZE): Allow use of TImode
+   for use with appropriately sized structures and unions
+   on 64-bit (x86) targets.
+
 2012-08-14  Uros Bizjak  
 
* config/i386/i386.md (enabled): Add comment with explanation
Index: gcc/testsuite/gcc.target/i386/pr20020-1.c
===
--- gcc/testsuite/gcc.target/i386/pr20020-1.c   (revision 0)
+++ gcc/testsuite/gcc.target/i386/pr20020-1.c   (revision 0)
@@ -0,0 +1,23 @@
+/* Check that 128-bit struct's are represented as TImode values.  */
+/* { dg-require-effective-target int128 } */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-rtl-expand" } */
+
+struct shared_ptr_struct
+{
+  unsigned long long phase:48;
+  unsigned short thread:16;
+  void *addr;
+};
+typedef struct shared_ptr_struct sptr_t;
+
+sptr_t S;
+
+sptr_t
+sptr_result (void)
+{
+  return S;
+}
+/* { dg-final { scan-rtl-dump "\\\(set \\\(reg:TI \[0-9\]* \\\[  
\\\]\\\)" "expand" } } */
+/* { dg-final { scan-rtl-dump "\\\(set \\\(reg/i:TI 0 ax\\\)" "expand" } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */
Index: gcc/testsuite/gcc.target/i386/pr20020-2.c
===
--- gcc/testsuite/gcc.target/i386/pr20020-2.c   (revision 0)
+++ gcc/testsuite/gcc.target/i386/pr20020-2.c   (revision 0)
@@ -0,0 +1,21 @@
+/* Check that 128-bit struct's are represented as TImode values.  */
+/* { dg-require-effective-target int128 } */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-rtl-expand" } */
+
+struct shared_ptr_struct
+{
+  unsigned long long phase:48;
+  unsigned short thread:16;
+  void *addr;
+};
+typedef struct shared_ptr_struct sptr_t;
+
+void
+copy_sptr (sptr_t *dest, sptr_t src)
+{
+  *dest = src;
+}
+
+/* { dg-final { scan-rtl-dump "\\\(set \\\(reg:TI \[0-9\]*" "expand" } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */
Index: gcc/testsuite/gcc.target/i386/pr20020-3.c
===
--- gcc/testsuite/gcc.target/i386/pr20020-3.c   (revision 0)
+++ gcc/testsuite/gcc.target/i386/pr20020-3.c   (revision 0)
@@ -0,0 +1,24 @@
+/* Check that 128-bit struct's are represented as TImode values.  */
+/* { dg-require-effective-target int128 } */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-rtl-expand" } */
+
+struct shared_ptr_struct
+{
+  unsigned long long phase:48;
+  unsigned short thread:16;
+  void *addr;
+};
+typedef struct shared_ptr_struct sptr_t;
+
+sptr_t sptr_1, sptr_2;
+
+void
+copy_sptr (void)
+{
+  sptr_1 = sptr_2;  
+}
+
+/* { dg-final { scan-rtl-dump "\\\(set \\\(reg:TI \[0-9\]*" "expand" } } */
+/* { dg-final { scan-rtl-dump "\\\(set \\\(mem/c:TI" "expand" } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */
Index: gcc/testsuite/ChangeLog
===
--- gcc/testsuite/ChangeLog (revision 190398)
+++ gcc/testsuite/ChangeLog (working copy)
@@ -1,3 +1,10 @@
+2012-08-14  Gary Funck 
+
+   PR target/20020
+   * gcc.target/i386/pr20020-1.c: New.
+   * gcc.target/i386/pr20020-2.c: New.
+   * gcc.target/i386/pr20020-3.c: New.
+
 2012-08-14  Oleg Endo  
 
PR target/52933


Re: PATCH [x86_64] PR20020 - 128 bit structs not targeted to TImode

2012-08-14 Thread H.J. Lu
On Tue, Aug 14, 2012 at 9:12 AM, Gary Funck  wrote:
> On 08/14/12 15:33:10, Joseph S. Myers wrote:
>> On Tue, 14 Aug 2012, Jakub Jelinek wrote:
>>
>> > On Mon, Aug 13, 2012 at 09:20:32PM -0700, Gary Funck wrote:
>> > > --- gcc/testsuite/gcc.dg/pr20020-1.c  (revision 0)
>> > > +++ gcc/testsuite/gcc.dg/pr20020-1.c  (revision 0)
>> > > @@ -0,0 +1,25 @@
>> > > +/* Target is restricted to x86_64 type architectures,
>> > > +   to check that 128-bit struct's are represented
>> > > +   as TImode values.  */
>> > > +/* { dg-require-effective-target int128 } */
>> > > +/* { dg-do compile { target { x86_64-*-* } } } */
>> >
>> > Given this all the testcases should go into gcc/testsuite/gcc.target/i386/
>>
>> And restricting the target to x86_64-*-* is wrong anyway, since any such
>> test should also be run for i?86-*-* -m64.  Use { target { ! { ia32 } } }
>> instead if you want to disable just -m32 testing, { target lp64 } if you
>> only want -m64 testing but not -m32 or -mx32.
>
> How about:
> 1. Move the test to gcc/testsuite/gcc.target/i386/
> 2. The comment is amended to read:
>/* Check that 128-bit struct's are represented as TImode values.  */
> 3. This test is retained:
>/* { dg-require-effective-target int128 } */
> 4. This target test is removed:
>/* { dg-do compile } */
>
> It is possible that "dg-require-effective-target int128" is
> too restrictive (in the sense that some x86 target might in
> theory support TImode, but not __int128_t), but at least
> some reasonable test coverage is guaranteed.

I believe int128 requirement is correct.

-- 
H.J.


Re: PATCH [x86_64] PR20020 - 128 bit structs not targeted to TImode

2012-08-14 Thread Gary Funck
On 08/14/12 15:33:10, Joseph S. Myers wrote:
> On Tue, 14 Aug 2012, Jakub Jelinek wrote:
> 
> > On Mon, Aug 13, 2012 at 09:20:32PM -0700, Gary Funck wrote:
> > > --- gcc/testsuite/gcc.dg/pr20020-1.c  (revision 0)
> > > +++ gcc/testsuite/gcc.dg/pr20020-1.c  (revision 0)
> > > @@ -0,0 +1,25 @@
> > > +/* Target is restricted to x86_64 type architectures,
> > > +   to check that 128-bit struct's are represented
> > > +   as TImode values.  */
> > > +/* { dg-require-effective-target int128 } */
> > > +/* { dg-do compile { target { x86_64-*-* } } } */
> > 
> > Given this all the testcases should go into gcc/testsuite/gcc.target/i386/
> 
> And restricting the target to x86_64-*-* is wrong anyway, since any such 
> test should also be run for i?86-*-* -m64.  Use { target { ! { ia32 } } } 
> instead if you want to disable just -m32 testing, { target lp64 } if you 
> only want -m64 testing but not -m32 or -mx32.

How about:
1. Move the test to gcc/testsuite/gcc.target/i386/
2. The comment is amended to read:
   /* Check that 128-bit struct's are represented as TImode values.  */
3. This test is retained:
   /* { dg-require-effective-target int128 } */
4. This target test is removed:
   /* { dg-do compile } */

It is possible that "dg-require-effective-target int128" is
too restrictive (in the sense that some x86 target might in
theory support TImode, but not __int128_t), but at least
some reasonable test coverage is guaranteed.

- Gary


Re: PATCH [x86_64] PR20020 - 128 bit structs not targeted to TImode

2012-08-14 Thread Joseph S. Myers
On Tue, 14 Aug 2012, Jakub Jelinek wrote:

> On Mon, Aug 13, 2012 at 09:20:32PM -0700, Gary Funck wrote:
> > --- gcc/testsuite/gcc.dg/pr20020-1.c(revision 0)
> > +++ gcc/testsuite/gcc.dg/pr20020-1.c(revision 0)
> > @@ -0,0 +1,25 @@
> > +/* Target is restricted to x86_64 type architectures,
> > +   to check that 128-bit struct's are represented
> > +   as TImode values.  */
> > +/* { dg-require-effective-target int128 } */
> > +/* { dg-do compile { target { x86_64-*-* } } } */
> 
> Given this all the testcases should go into gcc/testsuite/gcc.target/i386/

And restricting the target to x86_64-*-* is wrong anyway, since any such 
test should also be run for i?86-*-* -m64.  Use { target { ! { ia32 } } } 
instead if you want to disable just -m32 testing, { target lp64 } if you 
only want -m64 testing but not -m32 or -mx32.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: PATCH [x86_64] PR20020 - 128 bit structs not targeted to TImode

2012-08-14 Thread Gary Funck
On 08/14/12 08:30:59, Jakub Jelinek wrote:
> On Mon, Aug 13, 2012 at 09:20:32PM -0700, Gary Funck wrote:
> > --- gcc/testsuite/gcc.dg/pr20020-1.c(revision 0)
> > +++ gcc/testsuite/gcc.dg/pr20020-1.c(revision 0)
> > @@ -0,0 +1,25 @@
> > +/* Target is restricted to x86_64 type architectures,
> > +   to check that 128-bit struct's are represented
> > +   as TImode values.  */
> > +/* { dg-require-effective-target int128 } */
> > +/* { dg-do compile { target { x86_64-*-* } } } */
> 
> Given this all the testcases should go into gcc/testsuite/gcc.target/i386/

OK.

Note: It might be possible to leave only dg-require-effective-target int128
and use this as a regression test for other targets, such as
PPC64, S390, and IA64.  However, I was uncertain if the RTL would
be similar enough, and know that in at least one case the
RTL scan would have to be adjusted.  Also, I don't have access
to a S390.  If there is interest in generalizing the test,
let me know.  Otherwise, I'll move the tests to gcc.target/i386.

- Gary


Re: PATCH [x86_64] PR20020 - 128 bit structs not targeted to TImode

2012-08-13 Thread Jakub Jelinek
On Mon, Aug 13, 2012 at 09:20:32PM -0700, Gary Funck wrote:
> --- gcc/testsuite/gcc.dg/pr20020-1.c  (revision 0)
> +++ gcc/testsuite/gcc.dg/pr20020-1.c  (revision 0)
> @@ -0,0 +1,25 @@
> +/* Target is restricted to x86_64 type architectures,
> +   to check that 128-bit struct's are represented
> +   as TImode values.  */
> +/* { dg-require-effective-target int128 } */
> +/* { dg-do compile { target { x86_64-*-* } } } */

Given this all the testcases should go into gcc/testsuite/gcc.target/i386/

Jakub


PATCH [x86_64] PR20020 - 128 bit structs not targeted to TImode

2012-08-13 Thread Gary Funck
Attached, is a patch to fix PR20020, and three test cases.
This patch improves the code generated for structs that
can be represented in a TImode value on an x86_64 target.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20020

The test cases scan the generated RTL and verify
that TImode operations are present.

Note that this patch will uncover a new test
regression, described here:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20020#c9
Index: gcc/config/i386/i386.h
===
--- gcc/config/i386/i386.h  (revision 190336)
+++ gcc/config/i386/i386.h  (working copy)
@@ -1820,6 +1820,10 @@ do { 
\
 #define BRANCH_COST(speed_p, predictable_p) \
   (!(speed_p) ? 2 : (predictable_p) ? 0 : ix86_branch_cost)
 
+/* An integer expression for the size in bits of the largest integer machine
+   mode that should actually be used.  We allow pairs of registers.  */
+#define MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (TARGET_64BIT ? TImode : DImode)
+
 /* Define this macro as a C expression which is nonzero if accessing
less than a word of memory (i.e. a `char' or a `short') is no
faster than accessing a word of memory, i.e., if such access
Index: gcc/testsuite/gcc.dg/pr20020-1.c
===
--- gcc/testsuite/gcc.dg/pr20020-1.c(revision 0)
+++ gcc/testsuite/gcc.dg/pr20020-1.c(revision 0)
@@ -0,0 +1,25 @@
+/* Target is restricted to x86_64 type architectures,
+   to check that 128-bit struct's are represented
+   as TImode values.  */
+/* { dg-require-effective-target int128 } */
+/* { dg-do compile { target { x86_64-*-* } } } */
+/* { dg-options "-O2 -fdump-rtl-expand" } */
+
+struct shared_ptr_struct
+{
+  unsigned long long phase:48;
+  unsigned short thread:16;
+  void *addr;
+};
+typedef struct shared_ptr_struct sptr_t;
+
+sptr_t S;
+
+sptr_t
+sptr_result (void)
+{
+  return S;
+}
+/* { dg-final { scan-rtl-dump "\\\(set \\\(reg:TI \[0-9\]* \\\[  
\\\]\\\)" "expand" } } */
+/* { dg-final { scan-rtl-dump "\\\(set \\\(reg/i:TI 0 ax\\\)" "expand" } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */
Index: gcc/testsuite/gcc.dg/pr20020-2.c
===
--- gcc/testsuite/gcc.dg/pr20020-2.c(revision 0)
+++ gcc/testsuite/gcc.dg/pr20020-2.c(revision 0)
@@ -0,0 +1,23 @@
+/* Target is restricted to x86_64 type architectures,
+   to check that 128-bit struct's are represented
+   as TImode values.  */
+/* { dg-require-effective-target int128 } */
+/* { dg-do compile { target { x86_64-*-* } } } */
+/* { dg-options "-O2 -fdump-rtl-expand" } */
+
+struct shared_ptr_struct
+{
+  unsigned long long phase:48;
+  unsigned short thread:16;
+  void *addr;
+};
+typedef struct shared_ptr_struct sptr_t;
+
+void
+copy_sptr (sptr_t *dest, sptr_t src)
+{
+  *dest = src;
+}
+
+/* { dg-final { scan-rtl-dump "\\\(set \\\(reg:TI \[0-9\]*" "expand" } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */
Index: gcc/testsuite/gcc.dg/pr20020-3.c
===
--- gcc/testsuite/gcc.dg/pr20020-3.c(revision 0)
+++ gcc/testsuite/gcc.dg/pr20020-3.c(revision 0)
@@ -0,0 +1,26 @@
+/* Target is restricted to x86_64 type architectures,
+   to check that 128-bit struct's are represented
+   as TImode values.  */
+/* { dg-require-effective-target int128 } */
+/* { dg-do compile { target { x86_64-*-* } } } */
+/* { dg-options "-O2 -fdump-rtl-expand" } */
+
+struct shared_ptr_struct
+{
+  unsigned long long phase:48;
+  unsigned short thread:16;
+  void *addr;
+};
+typedef struct shared_ptr_struct sptr_t;
+
+sptr_t sptr_1, sptr_2;
+
+void
+copy_sptr (void)
+{
+  sptr_1 = sptr_2;  
+}
+
+/* { dg-final { scan-rtl-dump "\\\(set \\\(reg:TI \[0-9\]*" "expand" } } */
+/* { dg-final { scan-rtl-dump "\\\(set \\\(mem/c:TI" "expand" } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */