mypyc / mypyc

Compile type annotated Python to fast C extensions
1.76k stars 46 forks source link

Replace registers with constants when the value is a known compile-time constant #599

Open JukkaL opened 5 years ago

JukkaL commented 5 years ago

If we generate a register that gets initialized with a constant and never gets assigned to elsewhere, we could instead replace that register in generated C with the constant value. This might help with compile speed, and it could make the generated C easier to read by humans.

The savings would be two lines of C per register we can optimize away:

JukkaL commented 5 years ago

In particular, this might help compile speed and performance when using -O0 to compile C.

JukkaL commented 4 years ago

This has been implemented for short integer constants. We could do this for other things as well.