dynamobi/dynamobi — Issue #845: [FRG-25] Case statement too eagerly optimizes common sub-expressions
Author: dynamobi-build
Created: 2011-12-30 03:52:23+00:00
State: open
Labels: Fennel Calc Codegen, FRG

[reporter="jpham", created="Mon, 23 Jan 2006 15:25:27 -0500 (GMT-05:00)"]
When it is translating a program, the translator avoids translating the

same expression twice. (via implementNode()) For example, if you do:

values 5*10, 5*10;

It only codes 5*10 once. This is usually the right thing. However, it

has implications for conditional code. Consider the expression:

if ($0) {

5*10;

} else {

5*10+2;

}

The common sub-expression would undefined for the "else" clause. In Rex,

this is represented as:

Case($0, 5*10, 5*10+2)

This gets translated to roughly the following Fennel calculator code:

0: if not $0 jump 4

1: L0 = 5*10

2: L1 = L0

3: jump 5

4: L1 = L0 + 2

5: return L1

I am putting in some code to scope the conditional value expressions.

It would be good to have someone double check it and make

sure it was ok.