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

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

Thread Next
From:
Nicholas Clark
Date:
July 10, 2010 04:27
Subject:
[perl #76438] peephole optimiser could prune more dead code
Message ID:
rt-3.6.HEAD-11314-1278690961-740.76438-75-0@perl.org
# 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;


Wishlist, because I've no idea how much real world perl code ends up with
constructions like this, and would benefit.

Nicholas Clark

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=wishlist
---
Site configuration information for perl 5.13.2:

Configured by nick at Fri Jul  9 10:52:23 BST 2010.

Summary of my perl5 (revision 5 version 13 subversion 2) configuration:
  Derived from: a2d3de138935fbe8f4190ee9176b8fdd812a91d5
  Platform:
    osname=linux, osvers=2.6.18.8-xenu, archname=x86_64-linux
    uname='linux eris 2.6.18.8-xenu #1 smp sat oct 3 10:27:42 bst 2009 x86_64 gnulinux '
    config_args='-Dusedevel=y -Dcc=ccache gcc -Dld=gcc -Ubincompat5005 -Uinstallusrbinperl -Dcf_email=nick@ccl4.org -Dperladmin=nick@ccl4.org -Dinc_version_list=  -Dinc_version_list_init=0 -Doptimize=-Os -Uusethreads -Duse64bitall -Uusemymalloc -Duseperlio -Dprefix=~/Sandpit/snap5.9.x-v5.13.2-220-ga2d3de1 -Uusevendorprefix -Uvendorprefix=~/Sandpit/snap5.9.x-v5.13.2-220-ga2d3de1 -Dinstallman1dir=none -Dinstallman3dir=none -Uuserelocatableinc -Accccflags=-DPERL_OLD_COPY_ON_WRITE -de'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='ccache gcc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-Os',
    cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.3.2', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64
    libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.7.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.7'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -Os -L/usr/local/lib -fstack-protector'

Locally applied patches:
    

---
@INC for perl 5.13.2:
    lib
    /home/nick/Sandpit/snap5.9.x-v5.13.2-220-ga2d3de1/lib/perl5/site_perl/5.13.2/x86_64-linux
    /home/nick/Sandpit/snap5.9.x-v5.13.2-220-ga2d3de1/lib/perl5/site_perl/5.13.2
    /home/nick/Sandpit/snap5.9.x-v5.13.2-220-ga2d3de1/lib/perl5/5.13.2/x86_64-linux
    /home/nick/Sandpit/snap5.9.x-v5.13.2-220-ga2d3de1/lib/perl5/5.13.2
    .

---
Environment for perl 5.13.2:
    HOME=/home/nick
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/nick/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/local/sbin:/sbin:/usr/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


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