public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* working around "QImode can alias everything" missed optimizations
@ 2000-05-26 15:44 Doug Evans
  2000-05-27 15:15 ` Richard Henderson
  0 siblings, 1 reply; 5+ messages in thread
From: Doug Evans @ 2000-05-26 15:44 UTC (permalink / raw)
  To: gcc

version: current cvs sources as of around noon today
target: i386-linux

If you make `buf' in this program a short*, gcc -O2 -fomit-frame-pointer
optimizes `foo' just fine.  If `buf' is a char*, gcc does poorly
(I'm guessing because it can't know that buf may point to itself
and QImode values are allowed to alias anything).

So how do I work around this?
How do I rewrite this code so that I get something like the following?

foo:
	movl	4(%esp), %edx
	movl	(%edx), %eax
	movw	$1, (%eax)
	movw	$2, 1(%eax)
	movw	$3, 2(%eax)
	addl	$3, %eax
	movl	%eax, (%edx)
	ret

typedef struct {
    char* buf;
} tc_t;

static inline void
emit_1 (tc_t* tc, int c)
{
    *tc->buf = c;
    ++tc->buf;
}

void
foo (tc_t* p)
{
    emit_1 (p, 1);
    emit_1 (p, 2);
    emit_1 (p, 3);
}

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

* Re: working around "QImode can alias everything" missed optimizations
  2000-05-26 15:44 working around "QImode can alias everything" missed optimizations Doug Evans
@ 2000-05-27 15:15 ` Richard Henderson
  2000-05-29  2:06   ` Doug Evans
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Henderson @ 2000-05-27 15:15 UTC (permalink / raw)
  To: Doug Evans; +Cc: gcc

On Fri, May 26, 2000 at 03:43:55PM -0700, Doug Evans wrote:
> (I'm guessing because it can't know that buf may point to itself
> and QImode values are allowed to alias anything).

Yep.

> So how do I work around this?

You can't.  :-(



r~

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

* Re: working around "QImode can alias everything" missed optimizations
  2000-05-27 15:15 ` Richard Henderson
@ 2000-05-29  2:06   ` Doug Evans
  2000-05-29  8:20     ` working around "QImode can alias everything" missedoptimizations Mark Mitchell
  0 siblings, 1 reply; 5+ messages in thread
From: Doug Evans @ 2000-05-29  2:06 UTC (permalink / raw)
  To: Richard Henderson; +Cc: gcc

Richard Henderson writes:
 > On Fri, May 26, 2000 at 03:43:55PM -0700, Doug Evans wrote:
 > > (I'm guessing because it can't know that buf may point to itself
 > > and QImode values are allowed to alias anything).
 > 
 > Yep.
 > 
 > > So how do I work around this?
 > 
 > You can't.  :-(

I was afraid you were going to say that.

Any interest in fixing this [dunno how yet]?
GCC produces great code for non-QImode values (well done!).
It has to be agreed that QImode values shouldn't be penalized (right?).
[not that I would change behaviour of course, but rather that some
new way of specifying a "ya, I'm a QImode (ptr) value but, gosh darn it,
I don't alias everything" value needs to be found.  Alternatively, one
might come up with another way, but this way seems at first glance
like the right way to go.  I tried playing with `restrict' but I
don't know enough about it yet to say whether that has a chance
of working - I reread jfc's original email regarding his `restrict'
patch and he said there'd be problems with inline fns].

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

* Re: working around "QImode can alias everything" missedoptimizations
  2000-05-29  2:06   ` Doug Evans
@ 2000-05-29  8:20     ` Mark Mitchell
  2000-05-29 13:53       ` working around "QImode can alias everything" missed optimizations Toon Moene
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Mitchell @ 2000-05-29  8:20 UTC (permalink / raw)
  To: dje; +Cc: rth, gcc

>>>>> "Doug" == Doug Evans <dje@transmeta.com> writes:

    Doug> right way to go.  I tried playing with `restrict' but I
    Doug> don't know enough about it yet to say whether that has a
    Doug> chance of working - I reread jfc's original email regarding
    Doug> his `restrict' patch and he said there'd be problems with
    Doug> inline fns].

I think `restrict' will do what you want -- in theory.  Whether the
GCC implementation (which is, I believe, based more on my work that
John Carr's) will do it or not is unclear.  The current implementation
of restrict is, shall we way, limited.  Information is not propogated
around the compiler as widely as it should be.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

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

* Re: working around "QImode can alias everything" missed optimizations
  2000-05-29  8:20     ` working around "QImode can alias everything" missedoptimizations Mark Mitchell
@ 2000-05-29 13:53       ` Toon Moene
  0 siblings, 0 replies; 5+ messages in thread
From: Toon Moene @ 2000-05-29 13:53 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: dje, rth, gcc

Mark Mitchell wrote:

> I think `restrict' will do what you want -- in theory.  Whether the
> GCC implementation (which is, I believe, based more on my work that
> John Carr's) will do it or not is unclear.

The original work on alias analysis by John Carr contained an
implementation of `restrict'.  I know, because when we used his work as
an additional patch to the gcc backend (delivered "with" g77 back in
March 1997), we had to be careful to remove the C frontend stuff that
implemented `restrict' from our patch ...

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
GNU Fortran 95: http://g95.sourceforge.net/ (under construction)

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

end of thread, other threads:[~2000-05-29 13:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-26 15:44 working around "QImode can alias everything" missed optimizations Doug Evans
2000-05-27 15:15 ` Richard Henderson
2000-05-29  2:06   ` Doug Evans
2000-05-29  8:20     ` working around "QImode can alias everything" missedoptimizations Mark Mitchell
2000-05-29 13:53       ` working around "QImode can alias everything" missed optimizations Toon Moene

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