develooper Front page | perl.perl5.porters | Postings from July 2010

RE: [perl #76438] peephole optimiser could prune more dead code

Thread Previous | Thread Next
From:
Jan Dubois
Date:
July 20, 2010 14:41
Subject:
RE: [perl #76438] peephole optimiser could prune more dead code
Message ID:
010501cb2854$52e7d4c0$f8b77e40$@activestate.com
On Tue, 20 Jul 2010, Nicholas Clark wrote:
> I read $a . $a as equivalent to $x . $y, where it happens that $x and $y
> alias the same value. $a was *written* twice by the programmer, so as there
> are two references to it, it gets accessed *exactly* twice.

In that case I think you'll find plenty of places where it is accessed
more often than you expect. E.g. ++$a might access $a once if it is
just SV_pIOK, or twice if it is just SV_pNOK, because sv_inc() will first
try to see if it can't convert the NV to an IV, triggering an additional
FETCH call:

    flags = SvFLAGS(sv);
    if ((flags & (SVp_NOK|SVp_IOK)) == SVp_NOK) {
	/* It's (privately or publicly) a float, but not tested as an
	   integer, so test it to see. */
	(void) SvIV(sv);
	flags = SvFLAGS(sv);
    }

It is easy to guarantee that each tied variable is fetched at least once
for each time it is mentioned in the source code, but it is extremely
hard to guarantee that it isn't called more often: Any innocent looking
SvIV(), SvNV() or SvPV() call anywhere in the core may trigger an
additional call to FETCH a tied variable.

I prefer to view this as an inefficiency, not as a bug, because I think
FETCH should be side-effect free.

Cheers,
-Jan


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About