[issue4134] Peephole optimization: returning a temp

David Turner report at bugs.python.org
Thu Oct 16 21:54:10 CEST 2008


New submission from David Turner <novalis at novalis.org>:

This patch adds an optimization to the peephole optimizer for the common
case of:

def func(...):
   ...
   retval = ...
   return retval

Before the patch, the compiler would generate
STORE_FAST 3
LOAD_FAST 3
RETURN_VALUE

The store and load are pointless, as the local 3 (or whatever) is never
used again.  This patch makes the peephole optimizer optimize them out.

----------
components: None
files: peephole-return-temp.diff
keywords: patch
messages: 74853
nosy: novalis_dt
severity: normal
status: open
title: Peephole optimization: returning a temp
versions: Python 2.7
Added file: http://bugs.python.org/file11811/peephole-return-temp.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4134>
_______________________________________


More information about the Python-bugs-list mailing list