From: Linus Torvalds <torvalds@osdl.org>
To: Jeff Garzik <jeff@garzik.org>
Cc: linux-sparse@vger.kernel.org
Subject: Re: linearize bug?
Date: Sun, 12 Nov 2006 20:43:42 -0800 (PST) [thread overview]
Message-ID: <Pine.LNX.4.64.0611122032340.22714@g5.osdl.org> (raw)
In-Reply-To: <45569E7C.4030706@garzik.org>
On Sat, 11 Nov 2006, Jeff Garzik wrote:
> Given the following C code:
>
> #include <stdlib.h>
>
> int foo(void)
> {
> int i;
>
> i = 42;
> i += rand();
>
> return i;
> }
>
> test-linearize seems to give me the following output, which indicates that
> pseudo %r1 is "dead" immediately before it is used:
That is normal.
"dead X" means that X is dead after the _next_ (non-deathnote)
instruction.
So every single death-note should always show up _before_ an instruction
that uses that register, or something is wrong.
This is actually very useful. It means that for a code generator that
keeps track of hardware registers, it knows that a register content can be
re-used as the _destination_ of a code sequence when it sees the
death-note.
So for example:
> foo:
> .L0x2b52beecd010:
> <entry-point>
> call.32 %r1 <- rand
> dead %r1
> add.32 %r4 <- %r1, $42
> dead %r4
> ret.32 %r4
Here, the compiler back-end might, for example, look at
call.32 %r1 <- rand
and decide to use register %eax for %r1.
Now, the "dead %r1" that follows will tell the back-end that the value in
%r1 will be used _only_ by the following instruction, and never again, so
when it sees the
add.32 %r4 <- r1, $42
the back-end can trivially decide to _reuse_ %eax for %r4 too, and
generate just a simple
addl $42,%eax
for that instruction, without worrying at all about the fact that it
over-writes the register that contains %r1.
The same thing foes for the next two instructions: "dead %r4" means that
r4 (which we hold in %eax) will be dead after the next instruction (the
return), so again it knows that it can re-use %eax for the result. Of
course, for a return that's trivial anyway, but..
My "example" back-end actually does all this. It's buggy as hell, but try
./example file.c
on your input file, and at least I get:
.globl foo
foo:
call rand # generate_call
add.32 $42,%eax # do_binop
ret # generate_ret
which actually is correct (and re-uses %eax all the time). It even gets a
few more complicated cases right, but there are certainly trivial ways to
confuse it too (it doesn't really do any stack slot allocation, so
anything that generates a spill - which it _will_ try to do - will
actually generate completely broken code that just overwrites the stack).
Linus
next prev parent reply other threads:[~2006-11-13 4:44 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-12 4:09 linearize bug? Jeff Garzik
2006-11-13 4:43 ` Linus Torvalds [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-08-27 6:29 Jeff Garzik
2011-08-27 11:34 ` Kamil Dudka
2011-08-27 15:29 ` Linus Torvalds
2011-08-27 15:37 ` Jeff Garzik
2011-08-27 15:53 ` Linus Torvalds
2011-08-27 16:54 ` Kamil Dudka
2011-08-27 17:13 ` Linus Torvalds
2011-08-27 17:27 ` Linus Torvalds
2011-08-27 19:26 ` Linus Torvalds
2011-08-27 20:03 ` Jeff Garzik
2011-08-28 6:26 ` Pekka Enberg
2011-08-27 22:07 ` Jeff Garzik
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=Pine.LNX.4.64.0611122032340.22714@g5.osdl.org \
--to=torvalds@osdl.org \
--cc=jeff@garzik.org \
--cc=linux-sparse@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).