1
1
mirror of https://github.com/anoma/juvix.git synced 2024-11-30 05:42:26 +03:00
juvix/tests/Reg/positive/test039.jvr
Łukasz Czajka 235d88f303
Copy propagation in JuvixReg (#2828)
* Closes #1614 
* Implements the copy propagation transformation in JuvixReg and adds
tests for it.
* For this optimization to give any improvement, we need to run dead
code elimination afterwards (#2827).
2024-06-18 21:38:02 +02:00

85 lines
1.6 KiB
Plaintext

-- Copy & constant propagation
type either {
left : integer -> either;
right : bool -> either;
}
function main() : * {
tmp[0] = 7;
tmp[1] = tmp[0];
tmp[0] = tmp[1];
tmp[2] = tmp[0];
-- tmp[2] = 7
tmp[1] = tmp[0];
tmp[0] = add tmp[1] 1;
tmp[2] = add tmp[2] tmp[1];
-- tmp[2] = 14
tmp[0] = 19;
tmp[1] = tmp[0];
tmp[0] = add tmp[1] 1;
tmp[3] = add tmp[0] tmp[1];
tmp[4] = tmp[3];
tmp[2] = add tmp[4] tmp[2];
-- tmp[2] = 53
tmp[1] = eq tmp[2] 54;
tmp[0] = 4;
tmp[3] = 3;
tmp[4] = tmp[0];
tmp[5] = 4;
tmp[6] = tmp[5];
br tmp[1] {
true: {
tmp[4] = 7;
};
false: {
tmp[3] = tmp[6];
};
};
tmp[2] = add tmp[2] tmp[4];
tmp[2] = add tmp[2] tmp[3];
-- tmp[2] = 61
tmp[0] = alloc left (3);
tmp[1] = 17;
tmp[3] = tmp[1];
case[either] tmp[0] {
left: {
tmp[4] = tmp[0].left[0];
tmp[1] = tmp[4];
tmp[3] = tmp[1];
};
right: {
nop;
};
};
tmp[2] = add tmp[2] tmp[3];
-- tmp[2] = 64
tmp[0] = alloc right (true);
tmp[1] = 17;
tmp[3] = tmp[1];
case[either] tmp[0] {
left: {
tmp[1] = tmp[0].left[0];
};
right: {
br tmp[0].right[0] {
true: {
tmp[1] = add tmp[3] 1;
};
false: {
nop;
};
};
};
};
tmp[2] = add tmp[2] tmp[1];
-- tmp[2] = 82
ret tmp[2];
}