IUCompilerCourse / Essentials-of-Compilation

A book about compiling Racket and Python to x86-64 assembly
1.31k stars 141 forks source link

RCO too eager, interferes with explicate #181

Open jsiek opened 3 weeks ago

jsiek commented 3 weeks ago

For example,

print(42 if not (x == y) else 5)

compiles to more efficient code if RCO doesn't create a temporary for x == y.

elavoie commented 1 week ago

As discussed here: https://github.com/IUCompilerCourse/Essentials-of-Compilation/issues/179#issuecomment-2410329047

This can be solved by partially evaluating the not operation before the RCO pass, resulting in:

print(42 if x != y else 5)