leonhd / unladen-swallow

Automatically exported from code.google.com/p/unladen-swallow
Other
1 stars 1 forks source link

Improve type-check propagation #132

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Take the code

"""
def add(a, b):
   c = a + b
   d = a + b
   return c + d

def main():
   for _ in xrange(12000):
       add(1, 1)
"""

that is, we forcibly specialize add() on ints. We currently do six 
typechecks in that function to make sure a, b, c and d are all ints. a and b 
are checked twice each, once per addition, even though they could not 
possibly have changed types between those two statements.

High priority:
- Eliminate the second pair of typechecks for a and b (the ones on "d = a + 
b"); the type information from "c = a + b" should propagate.

Lower priority:
- Eliminate the typechecks in "c + d".
- Eliminate "d = a + b" statement in favor of "d = c".

Original issue reported on code.google.com by collinw on 28 Jan 2010 at 10:15

GoogleCodeExporter commented 8 years ago
I've attached the LLVM IR for the function above. Grepping for @PyInt_Type will 
highlight the typechecks.

Original comment by collinw on 28 Jan 2010 at 10:17

Attachments: