mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Roland Dreier <rdreier@cisco.com>
Cc: Jeff Garzik <jeff@garzik.org>,
	akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	linux-ide@vger.kernel.org, chas@cmf.nrl.navy.mil,
	rolandd@cisco.com, dwmw2@infradead.org, gregkh@suse.de
Subject: Re: [git patches 1/2] warnings: attack valid cases spotted by warnings
Date: Wed, 18 Jul 2007 11:02:46 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LFD.0.999.0707181050572.27353@woody.linux-foundation.org> (raw)
In-Reply-To: <adaodi9lika.fsf@cisco.com>



On Wed, 18 Jul 2007, Roland Dreier wrote:
> 
> BTW, I noticed one interesting thing while starting on this cleanup.
> I wanted to make sure that the generated code didn't change with the
> first step, and I actually discovered that the patch below seems to
> make the generated code *better*, maybe because some gcc alias
> analysis doesn't get as paranoid without the void *:

Absolutely.

The way to get pretty much any compiler to generate better code is:
 - code it simply
 - don't have tons of variables with overlapping lifetime
 - use limited-scope variables (ie don't have the variables at the 
   outermost scope, declare them in the smallest scope you can)

and trying to split things up into functions helps all of these. 

In fact, you can often get better code even when the functions aren't even 
inlined, because of the "simpler code" issue. Gcc sometimes tries to be 
too clever with its CSE etc, and generates really nasty complex code with 
lots of register spills, just because it keeps stuff live rather than just 
regenerating them.

So inlining a function doesn't even make it faster, all the time. You want 
to inline when 

 - the function is so small that the call is literally a big part of it, 
   and it doesn't even need more than a couple of registers, so the 
   calling convention has more register pressure than inlining the 
   function itself would have.

OR

 - the callers tend to have constant arguments that can benefit from 
   constant folding inside the function

but inlining in many other circumstances actually generates *worse* code 
and just makes debugging harder and the I$ footprint bigger.

> And here's the patch itself -- I think this is a reasonable size step
> to break things up into.  I assume that this is the basic form of the
> cleanup that you're proposing?

Yes, this looks good. Doing these kinds of things for the various other 
things is likely to make the code more readable, and as you already found 
out, the generated code doesn't tend to be worse either. It might not 
_always_ be a win size and performance-wise, but it can be, and so 
readability should generally always be the #1 goal, because quite often it 
actually does help the compiler too.

		Linus

  reply	other threads:[~2007-07-18 18:03 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-17 21:42 Jeff Garzik
2007-07-17 21:49 ` [git patches 2/2] warnings: use uninitialized_var() Jeff Garzik
2007-07-18 11:30   ` Adrian Bunk
2007-07-17 21:53 ` [git patches 1/2] warnings: attack valid cases spotted by warnings Roland Dreier
2007-07-17 22:10   ` Jeff Garzik
2007-07-17 22:17     ` Jeff Garzik
2007-07-18  2:35     ` Roland Dreier
2007-07-18  2:46       ` Roland Dreier
2007-07-18  4:00         ` Linus Torvalds
2007-07-18  4:18           ` Roland Dreier
2007-07-18  5:12             ` Linus Torvalds
2007-07-18 17:37               ` Roland Dreier
2007-07-18 18:02                 ` Linus Torvalds [this message]
2007-07-18  2:56       ` Linus Torvalds
2007-07-18  3:09         ` Roland Dreier
2007-07-18  3:29           ` Jeff Garzik
2007-07-17 22:19   ` Andrew Morton
2007-07-17 22:25     ` Linus Torvalds
2007-07-18  2:46 ` Greg KH
2007-07-18 20:03   ` Jeff Garzik
2007-07-18 22:07     ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.0.999.0707181050572.27353@woody.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=chas@cmf.nrl.navy.mil \
    --cc=dwmw2@infradead.org \
    --cc=gregkh@suse.de \
    --cc=jeff@garzik.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdreier@cisco.com \
    --cc=rolandd@cisco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®