public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [jbaron@redhat.com: [PATCH 0/3] tracepoints: delay argument  evaluation]
@ 2009-05-20 14:39 Jason Baron
  2009-05-20 15:03 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Baron @ 2009-05-20 14:39 UTC (permalink / raw)
  To: gcc

hi,

While working on some Linux kernel code, I've found that functions that
are declared as 'static inline' are having their arguments evaluated
well before they are used. For example I have a function:

static inline void trace(arg1, arg2)
{
	if (unlikely(enabled)) {
		<use the arguments>
	}
}

If i call 'trace(ptr->arg1, ptr->arg2)', then the pointers are
dereferenced before the 'if' is executed. Is there any way to delay the
argument evaluation until they are used? Am I missing a compiler option?
I am used gcc 4.3.0.

thanks,

-Jason

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

* Re: [jbaron@redhat.com: [PATCH 0/3] tracepoints: delay argument  evaluation]
  2009-05-20 14:39 [jbaron@redhat.com: [PATCH 0/3] tracepoints: delay argument evaluation] Jason Baron
@ 2009-05-20 15:03 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2009-05-20 15:03 UTC (permalink / raw)
  To: Jason Baron; +Cc: gcc

Jason Baron <jbaron@redhat.com> writes:

> While working on some Linux kernel code, I've found that functions that
> are declared as 'static inline' are having their arguments evaluated
> well before they are used. For example I have a function:
>
> static inline void trace(arg1, arg2)
> {
> 	if (unlikely(enabled)) {
> 		<use the arguments>
> 	}
> }
>
> If i call 'trace(ptr->arg1, ptr->arg2)', then the pointers are
> dereferenced before the 'if' is executed. Is there any way to delay the
> argument evaluation until they are used? Am I missing a compiler option?
> I am used gcc 4.3.0.

This question is appropriate for gcc-help@gcc.gnu.org, not
gcc@gcc.gnu.org.  Please take any followups to gcc-help.

The short answer is no, there are no such compiler options.  From the
compiler's perspective, ptr->arg1 is evaluated before the function call,
so even the fact that the arguments are only used in an unlikely branch
isn't going to help.  What you want is for the compiler to sink the load
into the only place where the result of the load is used.  That seems
like a reasonable optimization, at least when the result is only used in
an unlikely branch.  I recommend that you open a enhancement request at
http://gcc.gnu.org/bugzilla with a complete standalone test case.

Ian

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

end of thread, other threads:[~2009-05-20 14:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-20 14:39 [jbaron@redhat.com: [PATCH 0/3] tracepoints: delay argument evaluation] Jason Baron
2009-05-20 15:03 ` Ian Lance Taylor

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