Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve simplification of arithmetic #11

Open
emilaxelsson opened this issue Oct 19, 2012 · 0 comments
Open

Improve simplification of arithmetic #11

emilaxelsson opened this issue Oct 19, 2012 · 0 comments

Comments

@emilaxelsson
Copy link
Member

The current implementation is quite incomplete and it only deals with merging literals, so it can't cancel out variables; e.g.

(x+x)-x  ===>  x

It would be better to optimize a whole arithmetic expression at once. Gather all variables in one list, all literals in one list and all non-arithmetic sub-terms in one list. Then make a new optimized expression by combining the three lists.

However, doing this compositionally will probably lead to a lot of re-traversals of the same sub-terms, so the optimization framework will probably have to be modified so that arithmetic optimization only happens at feasible places (i.e. arithmetic sub-terms whose parents are not arithmetic expressions).

We should also think about how to deal with examples like this one (reported by Gergely):

> icompile (\(n::Data Word8) -> (n-2)+1)
...
void test(uint8_t v0, uint8_t * out)
{
    (* out) = (v0 + 255);
}

The result is correct, but not ideal from a readability point of view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant