develooper Front page | perl.perl5.porters | Postings from March 2023

Disabling the peephole optimiser

Thread Next
Paul "LeoNerd" Evans
March 5, 2023 22:22
Disabling the peephole optimiser
Message ID:
Usually RPEEP and friends does a great job. Sometimes, however, it gets
in the way.

Sometimes if I want to understand how a piece of code compiles, I look
at the output of `perl -MO=Concise ...` and look at the optree. The
output is a fully-optimised one though, and optimisations like
multideref and multiconcat can make the output very nontrivially
different from what I had expected to see.

  $ perl -MO=Concise -e 'my $z = $x->{key}[123]'
  6  <@> leave[1 ref] vKP/REFC ->(end)
  1     <0> enter v ->2
  2     <;> nextstate(main 1 -e:1) v:{ ->3
  5     <2> sassign vKS/2 ->6
  -        <1> ex-aelem sK/2 ->4
  3           <+> multideref($x->{"key"}[123]) sK ->4
  -              <0> ex-gv s ->3
  4        <0> padsv[$z:1,2] sRM*/LVINTRO ->5
  -e syntax OK

I had expected to see a nested tree of aelem and helem in here but
those got eaten and turned into multideref.

In theory it'd be lovely if we had some pragma module (or maybe part of
the 'less' module) to turn off these optimisations. Sure the code would
run slower and worse, but I'm only doing it to better understand the
output tree.

Problem is you can't conditionally not call RPEEP, because some of the
things it does are not just optimisations but actual required
transformations of the tree that are *necessary*.

In the gap between now and when 5.39.0 opens for development, there
seems to be plenty of time for someone to do a bit of research into how
easily such a feature might be added, and what in RPEEP needs
detangling for this to happen.

Does anyone fancy taking a look at that?

Paul "LeoNerd" Evans      |  |

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