This is actually not a LLVM issue, but more an issue of my higher language,that I’m trying to target LLVM on. I’m seeing that if I do a naive translation of my language, it generates additional load stores.
For example (in my high level language):
var1 = expression1;
var2 = expression2;
var3 = call(var1, var2);
var4 = expression3;
var5 = expression4;
var6 = call(var4, var5);
var7 = call(var6);
var8 = call(var3, var7);
This can be effectively represented in my high level language as
var8 = call(call(expression1, expression2), call(call(expression3, expression4));
When I think about it naively. I would write code that would start from var8 and traverse and try to substitute all “vars” with expressions.
I can imagine not always wanting to do this, for example if the expression is duplicated, maybe I do want to pay for the load/store. And maybe sometimes the semantics are such that I need to reuse it.
Is there a formal algorithm or classical technique that describes this?
Hayden