diff --git a/src/Juvix/Compiler/Pipeline.hs b/src/Juvix/Compiler/Pipeline.hs index ff2ba45e43..8fac49cc11 100644 --- a/src/Juvix/Compiler/Pipeline.hs +++ b/src/Juvix/Compiler/Pipeline.hs @@ -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' diff --git a/src/Juvix/Compiler/Reg/Data/TransformationId.hs b/src/Juvix/Compiler/Reg/Data/TransformationId.hs index 6ec735f736..dd97c68972 100644 --- a/src/Juvix/Compiler/Reg/Data/TransformationId.hs +++ b/src/Juvix/Compiler/Reg/Data/TransformationId.hs @@ -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] diff --git a/test/Asm/Run/Positive.hs b/test/Asm/Run/Positive.hs index d735d4953b..3b0caf9a11 100644 --- a/test/Asm/Run/Positive.hs +++ b/test/Asm/Run/Positive.hs @@ -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") ] diff --git a/tests/Asm/positive/out/test039.out b/tests/Asm/positive/out/test039.out new file mode 100644 index 0000000000..b4de394767 --- /dev/null +++ b/tests/Asm/positive/out/test039.out @@ -0,0 +1 @@ +11 diff --git a/tests/Asm/positive/test039.jva b/tests/Asm/positive/test039.jva new file mode 100644 index 0000000000..315221dd3a --- /dev/null +++ b/tests/Asm/positive/test039.jva @@ -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; +}