Let’s say I have a programming language where I can write:
x = f(g(1), h(1)) in this case the directed acyclic graph will show the dependencies of calculation like in a spreadsheet (assuming non recursive expressions):
1
| \
g h
\ /
f
This is a simple example but it turns interesting trying to “compress” more complex expressions within a DAG. The goal here is optimizing the number of recalculations based on the dependencies.
What algorithms and papers are available for dealing with this problem?
A bit more specific, it’s Local Common Subexpression Elimination. An algorithm is given in Dragon Book, “6.1.2 The Value-Number Method for Constructing DAG’s”