Skip to content

Commit

Permalink
fix copy propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz authored and paulcadman committed Jun 20, 2024
1 parent 9e6e8d8 commit d33d969
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/Juvix/Compiler/Pipeline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -378,5 +378,6 @@ asmToMiniC' = mapError (JuvixError @Asm.AsmError) . Asm.toReg' >=> regToMiniC' .

regToMiniC' :: (Member (Reader Asm.Options) r) => Reg.InfoTable -> Sem r C.MiniCResult
regToMiniC' tab = do
tab' <- Reg.toC tab
e <- ask
return $ C.fromReg (e ^. Asm.optLimits) tab
return $ C.fromReg (e ^. Asm.optLimits) tab'
6 changes: 2 additions & 4 deletions src/Juvix/Compiler/Reg/Data/TransformationId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ data PipelineId

type TransformationLikeId = TransformationLikeId' TransformationId PipelineId

-- Note: this works only because for now we mark all variables as live. Liveness
-- information needs to be re-computed after copy propagation.
toCTransformations :: [TransformationId]
toCTransformations = [Cleanup, CopyPropagation]
toCTransformations = [Cleanup]

toRustTransformations :: [TransformationId]
toRustTransformations = [Cleanup, CopyPropagation]
toRustTransformations = [Cleanup]

toCasmTransformations :: [TransformationId]
toCasmTransformations = [Cleanup, CopyPropagation, SSA]
Expand Down
7 changes: 6 additions & 1 deletion test/Asm/Run/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,10 @@ tests =
"Test038: Apply & argsnum"
$(mkRelDir ".")
$(mkRelFile "test038.jva")
$(mkRelFile "out/test038.out")
$(mkRelFile "out/test038.out"),
PosTest
"Test039: Copy propagation"
$(mkRelDir ".")
$(mkRelFile "test039.jva")
$(mkRelFile "out/test039.out")
]
1 change: 1 addition & 0 deletions tests/Asm/positive/out/test039.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11
42 changes: 42 additions & 0 deletions tests/Asm/positive/test039.jva
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-- Copy propagation

-- This test will fail with the native/WASM backend if copy propagation is
-- performed on JuvixReg without adjusting the live variables.

function f(integer) {
push arg[0];
push 0;
eq;
br {
true: {
push 3;
push 4;
tsave {
tsave {
push tmp[1];
call f;
push tmp[0];
add;
ret;
};
};
};
false: {
push arg[0];
push arg[0];
push arg[0];
push arg[0];
add;
sub;
add;
push 1;
add;
ret;
};
};
}

function main() {
push 0;
tcall f;
}

0 comments on commit d33d969

Please sign in to comment.