public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Possible CSE quirk involving SUBREG on the i386
@ 1998-06-29 22:34 John Wehle
  1998-06-30  4:50 ` Jeffrey A Law
  1999-03-09  1:09 ` Jeffrey A Law
  0 siblings, 2 replies; 20+ messages in thread
From: John Wehle @ 1998-06-29 22:34 UTC (permalink / raw)
  To: egcs

Compiling:

  unsigned short c;

  int
  func(unsigned short a)
    {
    unsigned short b;
 
    b = a;
    c = b;

    return b;
    }

for the i386 using egcs current with -O -S yields:

_func:
	pushl %ebp
	movl %esp,%ebp
	movl 8(%ebp),%eax
	movl %eax,%edx
	movw %ax,_c
	movzwl %dx,%eax
	leave
	ret

Which is interesting since I expected:

_func:
	pushl %ebp
	movl %esp,%ebp
	movl 8(%ebp),%eax
	movw %ax,_c
	movzwl %ax,%eax
	leave
	ret

The use of %edx seems wasteful.

-- John
-------------------------------------------------------------------------
|   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john@feith.com  |
|    John Wehle    |     Fax: 1-215-540-5495  |                         |
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: Possible CSE quirk involving SUBREG on the i386
@ 1998-06-30 14:46 John Wehle
  1998-06-30 14:08 ` Jeffrey A Law
  0 siblings, 1 reply; 20+ messages in thread
From: John Wehle @ 1998-06-30 14:46 UTC (permalink / raw)
  To: law; +Cc: egcs

> I'm not sure this is really a CSE issue.  Though it might be a combine
> issue.

The reason that I mention CSE is prior to it we have:

(insn 6 4 7 (set (reg/v:HI 21)
        (subreg:HI (reg:SI 22) 0)) -1 (nil)
    (nil))

(insn 13 10 16 (set (reg/v:HI 23)
        (reg/v:HI 21)) -1 (nil)
    (nil))

(insn 16 13 18 (set (mem:HI (symbol_ref:SI ("c")))
        (reg/v:HI 23)) -1 (nil)
    (nil))

(insn 18 16 20 (set (reg:SI 24)
        (zero_extend:SI (reg/v:HI 23))) -1 (nil)
    (nil))

and after it we have:

(insn 6 4 7 (set (reg/v:HI 21)
        (subreg:HI (reg:SI 22) 0)) 57 {movhi+1} (nil)
    (nil))

(insn 16 10 18 (set (mem:HI (symbol_ref:SI ("c")))
        (subreg:HI (reg:SI 22) 0)) 57 {movhi+1} (nil)
    (nil))

(insn 18 16 20 (set (reg:SI 24)
        (zero_extend:SI (reg/v:HI 21))) 85 {zero_extendhisi2} (nil)
    (nil))

It appears that CSE changed (reg/v:HI 23) in insn 16 to
(subreg:HI (reg:SI 22) 0) yet it did not perform this
same substitution in insn 18.  I would have expected
the same substitution in both places.

-- John
-------------------------------------------------------------------------
|   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john@feith.com  |
|    John Wehle    |     Fax: 1-215-540-5495  |                         |
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: Possible CSE quirk involving SUBREG on the i386
@ 1998-07-01 20:15 John Wehle
  1998-07-01 20:15 ` Richard Henderson
  1998-07-01 20:15 ` Jeffrey A Law
  0 siblings, 2 replies; 20+ messages in thread
From: John Wehle @ 1998-07-01 20:15 UTC (permalink / raw)
  To: rth; +Cc: egcs, law

> Ho hum.  The explanation is simple here -- MODES_TIEABLE_P.
> 
> I believe that we can do slightly better for this; while only
> the first four int regs can hold QImode values, all of them 
> can hold HImode values.
> 
> This happens to cure this exact problem, but the same problem
> will occur with unsigned char, and I don't see that we can do
> anything about it.

Why is there a requirement that MODES_TIEABLE_P be symmetrical?
On the i386 a QI mode register is accessible in SI mode so I
would think that adding:

  ((MODE1) == QImode && (MODE2) == SImode)

to MODES_TIEABLE_P would be useful.  BTW, this change solves
the unsigned char problem and survives a bootstrap.  I realize
that we need to avoid trying to use %esi and %edi in a situation
which requires QImode access ... though this seems like a register
allocation issue which could be handled separate from CSE and
COMBINE.  What are the thoughts on refining the definition of
MODES_TIEABLE_P so that it can be asymmetric and change:

  MODES_TIEABLE_P (X, Y)

to:

  MODES_TIEABLE_P (X, Y) && MODES_TIEABLE_P (Y, X)

where necessary to prevent the wrong kind of register from
being allocated?

I known ... things aren't that simple :-) though I welcome
being enlightened as to the complexities.

-- John
-------------------------------------------------------------------------
|   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john@feith.com  |
|    John Wehle    |     Fax: 1-215-540-5495  |                         |
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: Possible CSE quirk involving SUBREG on the i386
@ 1998-07-02  0:53 John Wehle
  1998-07-07  5:29 ` Jeffrey A Law
  0 siblings, 1 reply; 20+ messages in thread
From: John Wehle @ 1998-07-02  0:53 UTC (permalink / raw)
  To: law; +Cc: rth, egcs

>   > Why is there a requirement that MODES_TIEABLE_P be symmetrical?
> I believe it is related to HARD_REGNO_MODE_OK.  See MODES_TIEABLE_P
> in the manual.

I did. :-)

> Basically local-alloc will try to tie two registers together if
> MODES_TIEABLE_P is nonzero for two pseudos.

I noticed that. :-)

> If we tie the pseudos together, they will be allocated into the
> same hard reg -- and if HARD_REGNO_MODE_OK was nonzero for one
> of them, then we lose.

Right, which is why I'm proposing that combine_regs in local-alloc.c
be changed from using:

  || !MODES_TIEABLE_P (GET_MODE (usedreg), GET_MODE (setreg))

to:

  || !MODES_TIEABLE_P (GET_MODE (usedreg), GET_MODE (setreg))
  || !MODES_TIEABLE_P (GET_MODE (setreg), GET_MODE (usedreg))

and then update the manual to allow MODES_TIEABLE_P to be asymmetric.
This allows combine to handle zero extending a QImode register in an
optimal fashion on the i386.  Any reason I shouldn't go ahead and submit
a patch for this?

-- John
-------------------------------------------------------------------------
|   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john@feith.com  |
|    John Wehle    |     Fax: 1-215-540-5495  |                         |
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: Possible CSE quirk involving SUBREG on the i386
@ 1998-07-10 20:04 John Wehle
  0 siblings, 0 replies; 20+ messages in thread
From: John Wehle @ 1998-07-10 20:04 UTC (permalink / raw)
  To: law; +Cc: rth, egcs

> Based on the comments in combine.c, I think at one time MODES_TIEABLE_P
> did have to be symmetric because of the reload issue.  I'm starting to
> think we can relax this now.
> 
> The last issue is register allocation -- I get the impression from reading
> the code in cse, combine & regclass that this change may make register 
> allocation worse in some cases.  So we need to have some guess about the
> benefit vs the cost.

Yep, I got the same impression though sometimes it's hard to guess without
trying it.

> I propose we table this until after egcs-1.1.  Or better yet, instead of
> tabling it, we just install your patch in the mainline sources after egcs-1.1
> branches.

Okay, I'll see about throwing together a patch.

> That gives us plenty of time to study what actually happens instead of
> doing something rather risky at this stage.

Sounds reasonable to me.

-- John
-------------------------------------------------------------------------
|   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john@feith.com  |
|    John Wehle    |     Fax: 1-215-540-5495  |                         |
-------------------------------------------------------------------------


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

end of thread, other threads:[~1999-03-31 23:46 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-29 22:34 Possible CSE quirk involving SUBREG on the i386 John Wehle
1998-06-30  4:50 ` Jeffrey A Law
1998-06-30 15:15   ` Richard Henderson
1998-07-01  0:54     ` David S. Miller
1998-07-01  0:54       ` Richard Henderson
1998-07-01  3:42       ` Jeffrey A Law
1998-07-01  0:54         ` David S. Miller
1998-07-01  0:54           ` Jeffrey A Law
1999-03-09  1:09 ` Jeffrey A Law
1999-03-31 23:46   ` Jeffrey A Law
1998-06-30 14:46 John Wehle
1998-06-30 14:08 ` Jeffrey A Law
1998-07-01  6:44   ` Richard Henderson
1998-07-01 22:54     ` Jeffrey A Law
1998-07-01 20:15 John Wehle
1998-07-01 20:15 ` Richard Henderson
1998-07-01 20:15 ` Jeffrey A Law
1998-07-02  0:53 John Wehle
1998-07-07  5:29 ` Jeffrey A Law
1998-07-10 20:04 John Wehle

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