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:
Joshua ben Jore
Date:
July 10, 2010 06:47
Subject:
Re: [perl #76438] peephole optimiser could prune more dead code
Message ID:
AANLkTimDWjreTeh1Xpjoxj-IuGsFVxcuURwQeDY0dj4G@mail.gmail.com
On Fri, Jul 9, 2010 at 8:56 AM, Nicholas Clark
<perlbug-followup@perl.org> wrote:
> # New Ticket Created by  Nicholas Clark
> # Please include the string:  [perl #76438]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=76438 >
>
>
>
> This is a bug report for perl from nick@ccl4.org,
> generated with the help of perlbug 1.39 running under perl 5.13.2.
>
>
> -----------------------------------------------------------------
> [Please describe your issue here]
>
> $ ./perl -Ilib -MO=Deparse -e 'if ("Pie" eq "Good") {print}'
> '???';
> -e syntax OK
>
> but
>
> $ ./perl -Ilib -MO=Deparse -e 'if ($a && "Pie" eq "Good") {print}'
> if ($a and !1) {
>    print $_;
> }
> -e syntax OK
>
> which demonstrates that "Pie" eq "Good" is constant folded, but that the
> optree for the block still exists.
>
> The peephole optimiser is correct not to optimise this to nothing, as it
> can't know that $a is neither tied nor overloaded, so cannot assume that
> the lookup of $a has no side effects.
>
> However, it can know that the conditional to the if block is always false,
> and so could optimise away the ops for the block, freeing up their memory.
> Hence the code should become
>
>    $a and !1;
>
> or even the perl equivalent of
>
>    (void) (bool) $a;

Well actually, the 'bool' call was in scalar context, not void.

Josh

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