public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* How to compress the size of a field in a structure?
@ 2024-01-13  7:45 Hanke Zhang
  2024-01-13  9:15 ` Iain Sandoe
  2024-01-15  9:16 ` Richard Biener
  0 siblings, 2 replies; 4+ messages in thread
From: Hanke Zhang @ 2024-01-13  7:45 UTC (permalink / raw)
  To: gcc

Hi, I'm attempting to compress the size of a field in a structure for
memory-friendly purposes. I created an IPA pass to achieve this, but I
ran into some issues as follows:

// original
struct Foo {
  long a1;
  int a2;
};

// modified
struct Foo_update {
  int a1;
  int a2;
};

For the example structure Foo, I use `TREE_TYPE (field) =
integer_type_node` to compress the type of a1 from `long` to `int`.

But I don't know how to update its corresponding SSA variables,
because the number of them is huge. Is there any way to do it quickly?

Thanks
Hanke Zhang

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

* Re: How to compress the size of a field in a structure?
  2024-01-13  7:45 How to compress the size of a field in a structure? Hanke Zhang
@ 2024-01-13  9:15 ` Iain Sandoe
  2024-01-14  7:43   ` Hanke Zhang
  2024-01-15  9:16 ` Richard Biener
  1 sibling, 1 reply; 4+ messages in thread
From: Iain Sandoe @ 2024-01-13  9:15 UTC (permalink / raw)
  To: Hanke Zhang; +Cc: GCC Development



> On 13 Jan 2024, at 07:45, Hanke Zhang via Gcc <gcc@gcc.gnu.org> wrote:
> 
> Hi, I'm attempting to compress the size of a field in a structure for
> memory-friendly purposes. I created an IPA pass to achieve this, but I
> ran into some issues as follows:
> 
> // original
> struct Foo {
>  long a1;
>  int a2;
> };
> 
> // modified
> struct Foo_update {
>  int a1;
>  int a2;
> };
> 
> For the example structure Foo, I use `TREE_TYPE (field) =
> integer_type_node` to compress the type of a1 from `long` to `int`.

Hmm.  I am curious about under what conditions this is expected to work.

Altering the size of the structure (or the types it contains) would break guarantees
expected by at least c-family languages   - like sizeof, alignof 
what about arrays of the type, or embedding the type in larger aggregates?

Iain

> But I don't know how to update its corresponding SSA variables,
> because the number of them is huge. Is there any way to do it quickly?
> 
> Thanks
> Hanke Zhang


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

* Re: How to compress the size of a field in a structure?
  2024-01-13  9:15 ` Iain Sandoe
@ 2024-01-14  7:43   ` Hanke Zhang
  0 siblings, 0 replies; 4+ messages in thread
From: Hanke Zhang @ 2024-01-14  7:43 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: GCC Development

Hi lain,

Thanks for your thoughtful comments and concerns. The primary goal of
compressing the structure fields is to achieve memory efficiency. I
understand your points regarding potential issues with modifying the
size and types of the structure. I guess rewriting all the
corresponding statements may help with it. If there are some more
complex situations, we will give up this optimization.

But I'm more concerned about how to accomplish this.

Thanks
Hanke Zhang

Iain Sandoe <idsandoe@googlemail.com> 于2024年1月13日周六 17:15写道:
>
>
>
> > On 13 Jan 2024, at 07:45, Hanke Zhang via Gcc <gcc@gcc.gnu.org> wrote:
> >
> > Hi, I'm attempting to compress the size of a field in a structure for
> > memory-friendly purposes. I created an IPA pass to achieve this, but I
> > ran into some issues as follows:
> >
> > // original
> > struct Foo {
> >  long a1;
> >  int a2;
> > };
> >
> > // modified
> > struct Foo_update {
> >  int a1;
> >  int a2;
> > };
> >
> > For the example structure Foo, I use `TREE_TYPE (field) =
> > integer_type_node` to compress the type of a1 from `long` to `int`.
>
> Hmm.  I am curious about under what conditions this is expected to work.
>
> Altering the size of the structure (or the types it contains) would break guarantees
> expected by at least c-family languages   - like sizeof, alignof
> what about arrays of the type, or embedding the type in larger aggregates?
>
> Iain
>
> > But I don't know how to update its corresponding SSA variables,
> > because the number of them is huge. Is there any way to do it quickly?
> >
> > Thanks
> > Hanke Zhang
>

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

* Re: How to compress the size of a field in a structure?
  2024-01-13  7:45 How to compress the size of a field in a structure? Hanke Zhang
  2024-01-13  9:15 ` Iain Sandoe
@ 2024-01-15  9:16 ` Richard Biener
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Biener @ 2024-01-15  9:16 UTC (permalink / raw)
  To: Hanke Zhang; +Cc: gcc

On Sat, Jan 13, 2024 at 8:46 AM Hanke Zhang via Gcc <gcc@gcc.gnu.org> wrote:
>
> Hi, I'm attempting to compress the size of a field in a structure for
> memory-friendly purposes. I created an IPA pass to achieve this, but I
> ran into some issues as follows:
>
> // original
> struct Foo {
>   long a1;
>   int a2;
> };
>
> // modified
> struct Foo_update {
>   int a1;
>   int a2;
> };
>
> For the example structure Foo, I use `TREE_TYPE (field) =
> integer_type_node` to compress the type of a1 from `long` to `int`.
>
> But I don't know how to update its corresponding SSA variables,
> because the number of them is huge. Is there any way to do it quickly?

There's no way to map back a structure field to all of its [implicit]
uses.  But the
set of variables to adjust should fall out trivially of the analysis phase that
determines whether the transform is valid (which is indeed the most complicated
part).

It might be possible to restrict the transform to certain objects
(rather than the "type").

There were several similar attempts on doing "struct reorg", the most recent by
people from amerecomputing IIRC.  I've always commented that trying to do
this on the types (and computing sth like "type escape") is wrong, analysis and
transform should be on individual instances of the type instead - those you can
actually analyze.

Richard.

>
> Thanks
> Hanke Zhang

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

end of thread, other threads:[~2024-01-15  9:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-13  7:45 How to compress the size of a field in a structure? Hanke Zhang
2024-01-13  9:15 ` Iain Sandoe
2024-01-14  7:43   ` Hanke Zhang
2024-01-15  9:16 ` Richard Biener

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