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

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

Thread Next
Nicholas Clark
July 10, 2010 04:27
[perl #76438] peephole optimiser could prune more dead code
Message ID:
# New Ticket Created by  Nicholas Clark 
# Please include the string:  [perl #76438]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
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


$ ./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]
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
    osname=linux, osvers=, archname=x86_64-linux
    uname='linux eris #1 smp sat oct 3 10:27:42 bst 2009 x86_64 gnulinux '
    config_args='-Dusedevel=y -Dcc=ccache gcc -Dld=gcc -Ubincompat5005 -Uinstallusrbinperl -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
    cc='ccache gcc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    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/, so=so, useshrplib=false, libperl=libperl.a
  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:

Environment for perl 5.13.2:
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About