public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Strange RTL
       [not found] <Pine.GSO.4.31.0208011252280.11137-100000@ux13.cso.uiuc.edu>
@ 2002-08-02  8:35 ` Chris Lattner
  0 siblings, 0 replies; 3+ messages in thread
From: Chris Lattner @ 2002-08-02  8:35 UTC (permalink / raw)
  To: Michael Matz; +Cc: gcc


> > The RTL generated for the assignment is the following (this is from the
> > .00.rtl dump, Pmode=PDI):
> >
> > (insn 10 5 15 (set (subreg:PDI (reg/v:DI 107) 0)
> >         (const_int 123 [0x7b])) -1 (nil)
> >     (nil))
> >
> > So, my question is: why does the subreg come into play here?
>
> Well, the union/struct is small enough, so only a pseudo is allocated for
> it (of DImode size) as backing storage.  Because it's a union, it could
> contain other members (which ultimately could result also in different
> modes for that pseudo, think about a float also being member).  But the
> pseudo itself only has one mode, DImode in this case.  To access the real

The reason that I bring this up is that it only happens in a few cases,
such as the case above (which did originally have other members, but
probably did still fit in 64-bits).  I just need to teach my code
generator to handle subregs on the destination side of a set expression.

The really ugly part of this, however is that the above set turns into the
following RTL when converted to SSA:

(insn 10 24 15 (sequence[
            (set (reg/v:DI 107)
                (reg:DI 109))
            (set (subreg:PDI (reg/v:DI 107) 0)
                (const_int 123 [0x7b]))
        ] ) -1 (nil)
    (nil))

Of course this basically breaks the single assignment property of SSA, and
means I'll have to introduce special hacks to handle this. :(

So my currently plan is to add code to specifically match this case.
Is anyone aware of a simpler way to stop this code from being generated in
the first place though?  Where would I look to implement the optimization
of not generating these in the first place?

Thanks for the help!

-Chris

http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/


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

* Re: Strange RTL
  2002-07-31 16:31 Chris Lattner
@ 2002-08-01  5:02 ` Michael Matz
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Matz @ 2002-08-01  5:02 UTC (permalink / raw)
  To: Chris Lattner; +Cc: gcc

Hi,

On Wed, 31 Jul 2002, Chris Lattner wrote:

> union X { void *B; };
> union X foo() {
>         union X A;
>         A.B = (void*)123;   /* Interesting part */
>         return A;
> }
>
> The RTL generated for the assignment is the following (this is from the
> .00.rtl dump, Pmode=PDI):
>
> (insn 10 5 15 (set (subreg:PDI (reg/v:DI 107) 0)
>         (const_int 123 [0x7b])) -1 (nil)
>     (nil))
>
> So, my question is: why does the subreg come into play here?

Well, the union/struct is small enough, so only a pseudo is allocated for
it (of DImode size) as backing storage.  Because it's a union, it could
contain other members (which ultimately could result also in different
modes for that pseudo, think about a float also being member).  But the
pseudo itself only has one mode, DImode in this case.  To access the real
member it needs to be converted to the correct mode (PDImode in this case,
if a float would be there, and you would access it, it would be DFmode).
Conversion in RTL is done with subregs.  To use PDImode for this pseudo
from the beginning would be a pure optimization, based on the fact that
this union only contains one member of pointer mode.  I guess this
optimization simply isn't implemented, as a union of only one member
doesn't seem very usefull.

> If I change the union to 'struct' (which should cause identical output
> in this case), then I get this output:
>
> (insn 10 5 15 (set (reg/v:PDI 107)
>         (const_int 123 [0x7b])) -1 (nil)
>     (nil))

Sure.  Because here the "type" of the backing storage is definitive, as it
can't overlap with any other members.


Ciao,
Michael.

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

* Strange RTL
@ 2002-07-31 16:31 Chris Lattner
  2002-08-01  5:02 ` Michael Matz
  0 siblings, 1 reply; 3+ messages in thread
From: Chris Lattner @ 2002-07-31 16:31 UTC (permalink / raw)
  To: gcc


Hi all,

I'm seeing some confusing (to me :) RTL being generated from a simple
testcase, and was wondering if someone might be able to help me decode it,
and preferably help me stop it from being constructed.  :)

Here's the C code in question:

union X { void *B; };
union X foo() {
        union X A;
        A.B = (void*)123;   /* Interesting part */
        return A;
}

The RTL generated for the assignment is the following (this is from the
.00.rtl dump, Pmode=PDI):

(insn 10 5 15 (set (subreg:PDI (reg/v:DI 107) 0)
        (const_int 123 [0x7b])) -1 (nil)
    (nil))

So, my question is: why does the subreg come into play here?  If I change
the union to 'struct' (which should cause identical output in this case),
then I get this output:

(insn 10 5 15 (set (reg/v:PDI 107)
        (const_int 123 [0x7b])) -1 (nil)
    (nil))

... which makes more sense to me.  Is there any way that I can get the
union case to generate code that doesn't use a subreg like that?

Thanks,

-Chris

http://llvm.cs.uiuc.edu/

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

end of thread, other threads:[~2002-08-02 15:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <Pine.GSO.4.31.0208011252280.11137-100000@ux13.cso.uiuc.edu>
2002-08-02  8:35 ` Strange RTL Chris Lattner
2002-07-31 16:31 Chris Lattner
2002-08-01  5:02 ` Michael Matz

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