diff --git a/dag_in_context/src/optimizations/memory.egg b/dag_in_context/src/optimizations/memory.egg index cc1f85e7..c0092dfc 100644 --- a/dag_in_context/src/optimizations/memory.egg +++ b/dag_in_context/src/optimizations/memory.egg @@ -240,7 +240,8 @@ (rule ((PointsToCells (Get x i) ap)) ((PointsToCells x ap)) :ruleset memory-helpers) -(rule ((PointsToCells (Concat x y) ap)) +(rule ((PointsToCells (Concat x y) ap) + (= x (Single x-inner))) ((PointsToCells x ap) (PointsToCells y ap)) :ruleset memory-helpers) @@ -254,6 +255,7 @@ (UnwrapTuplePointsTo (PointsToCells x aps)) (UnwrapTuplePointsTo (PointsToCells y aps)))) :when ((= concat-x-y (Concat x y)) + (= x (Single x-inner)) (HasType concat-x-y ty) (PointerishType ty)) :ruleset memory-helpers) diff --git a/dag_in_context/src/type_analysis.egg b/dag_in_context/src/type_analysis.egg index 0b4d8e1a..db998463 100644 --- a/dag_in_context/src/type_analysis.egg +++ b/dag_in_context/src/type_analysis.egg @@ -5,20 +5,21 @@ (rewrite (TLConcat (TNil) r) r :ruleset type-helpers) (rewrite (TLConcat (TCons hd tl) r) (TCons hd (TLConcat tl r)) + :subsume :ruleset type-helpers) (function TypeList-length (TypeList) i64 :unextractable) (function TypeList-ith (TypeList i64) BaseType :unextractable) -(function TypeList-suffix (TypeList i64) TypeList :unextractable) -(rule ((TupleT tylist)) ((union (TypeList-suffix tylist 0) tylist)) :ruleset type-helpers) - -(rule ((= (TypeList-suffix top n) (TCons hd tl))) - ((union (TypeList-ith top n) hd) - (union (TypeList-suffix top (+ n 1)) tl)) :ruleset type-helpers) - -(rule ((= (TypeList-suffix list n) (TNil))) - ((set (TypeList-length list) n)) :ruleset type-helpers) +;; Don't match on TypeList-ith because it is now lazily instantiated! +(rule () ((set (TypeList-length (TNil)) 0)) :ruleset type-helpers) +(rule ((= lst (TCons hd tl)) + (= len (TypeList-length tl))) + ((set (TypeList-length lst) (+ 1 len))) :ruleset type-helpers) +(rewrite (TypeList-ith (TCons hd tl) 0) hd :ruleset type-helpers) +(rewrite (TypeList-ith (TCons hd tl) i) (TypeList-ith tl (- i 1)) + :when ((> i 0)) + :ruleset type-helpers) (rule ((TypeList-ith list i) (= (TypeList-length list) n) @@ -372,13 +373,13 @@ :ruleset type-analysis) (rule ( - (= lhs (Concat e1 e2)) - (HasType e1 (TupleT tylist1)) + (= lhs (Concat (Single e1) e2)) + (HasType e1 (Base t1)) (HasType e2 (TupleT tylist2)) ) ; TLConcat needs to compute immediately, so we need to saturate type-helpers ; rules between every iter of type-analysis rules. - ((HasType lhs (TupleT (TLConcat tylist1 tylist2)))) + ((HasType lhs (TupleT (TCons t1 tylist2)))) :ruleset type-analysis) ; ================================= diff --git a/dag_in_context/src/utility/add_context.egg b/dag_in_context/src/utility/add_context.egg index ff601a7b..2a9aaa4d 100644 --- a/dag_in_context/src/utility/add_context.egg +++ b/dag_in_context/src/utility/add_context.egg @@ -63,9 +63,9 @@ (rewrite (AddContext ctx (Single c1)) (Single (AddContext ctx c1)) :ruleset context) -(rewrite (AddContext ctx (Concat c1 c2)) +(rewrite (AddContext ctx (Concat (Single c1) c2)) (Concat - (AddContext ctx c1) + (Single (AddContext ctx c1)) (AddContext ctx c2)) :ruleset context) diff --git a/dag_in_context/src/utility/canonicalize.egg b/dag_in_context/src/utility/canonicalize.egg index cd56a260..7f894ca5 100644 --- a/dag_in_context/src/utility/canonicalize.egg +++ b/dag_in_context/src/utility/canonicalize.egg @@ -41,13 +41,16 @@ ; Make Concats right-deep (rewrite (Concat (Concat a b) c) (Concat a (Concat b c)) + :subsume :ruleset always-run) ; Simplify Concat's with empty (rewrite (Concat (Empty ty ctx) x) x + :subsume :ruleset always-run) (rewrite (Concat x (Empty ty ctx)) x + :subsume :ruleset always-run) ; Make a tuple that is a sub-range of another tuple @@ -56,36 +59,29 @@ (rewrite (SubTuple expr x 0) (Empty ty ctx) + :subsume :when ((HasArgType expr ty) (ContextOf expr ctx)) :ruleset always-run) (rewrite (SubTuple expr x 1) (Single (Get expr x)) + :subsume :ruleset always-run) (rewrite (SubTuple expr a b) (Concat (Single (Get expr a)) (SubTuple expr (+ a 1) (- b 1))) + :subsume :when ((> b 1)) :ruleset always-run) -; Also figure out what existing expressions are subtuples of other things -; this helps remove concat layers -(rule ((Get expr i)) - ((union (Single (Get expr i)) - (SubTuple expr i 1))) +; ;; This rule makes sure every tuple can be +; ;; normalized as a list of (Concat (Single e1) (Concat (Single e2) ...)) +(rewrite e (SubTuple e 0 len) + :when ((tuples-to-generate-get-for e) + (HasType e (TupleT t)) + (= len (TypeList-length t))) :ruleset always-run) -(rewrite (Concat (SubTuple expr a b) - (SubTuple expr (+ a b) c)) - (SubTuple expr a (+ b c)) - :ruleset always-run) -;; a subtuple which is the entire tuple is the tuple itself -;; this removes unecessary layers of concat -(rewrite (SubTuple expr 0 len) - expr - :when ((= len (tuple-length expr))) - :ruleset always-run) - ; Helper functions to remove one element from a tuple or type list ; tuple idx (function TupleRemoveAt (Expr i64) Expr :unextractable) diff --git a/dag_in_context/src/utility/debug-helper.egg b/dag_in_context/src/utility/debug-helper.egg index 4093e3d7..8d4119a7 100644 --- a/dag_in_context/src/utility/debug-helper.egg +++ b/dag_in_context/src/utility/debug-helper.egg @@ -31,10 +31,6 @@ ((delete (BinaryOpIsPure e))) :ruleset debug-deletes) -(rule ((TypeList-suffix e a)) - ((delete (TypeList-suffix e a))) - :ruleset debug-deletes) - (rule ((ContextOf e a)) ((delete (ContextOf e a))) :ruleset debug-deletes) diff --git a/dag_in_context/src/utility/drop_at.egg b/dag_in_context/src/utility/drop_at.egg index 69992490..7eb926bc 100644 --- a/dag_in_context/src/utility/drop_at.egg +++ b/dag_in_context/src/utility/drop_at.egg @@ -89,7 +89,9 @@ :ruleset drop) (rule ((= lhs (DropAtInternal newty newctx idx (Concat c1 c2))) - (ExprIsResolved (Concat c1 c2))) + (ExprIsResolved (Concat c1 c2)) + ;; canonicalize Concat to be right deep + (= c1 (Single c1-inner))) ((DelayedDropUnion lhs (Concat (DropAtInternal newty newctx idx c1) (DropAtInternal newty newctx idx c2)))) diff --git a/dag_in_context/src/utility/subst.egg b/dag_in_context/src/utility/subst.egg index 78dbe92b..cfae4d08 100644 --- a/dag_in_context/src/utility/subst.egg +++ b/dag_in_context/src/utility/subst.egg @@ -106,7 +106,8 @@ ((DelayedSubstUnion lhs (Single (Subst assum to c1)))) :ruleset subst) -(rule ((= e (Concat c1 c2)) +(rule ((= c1 (Single c1-inner)) + (= e (Concat c1 c2)) (= lhs (Subst assum to e)) (ExprIsResolved e)) ((DelayedSubstUnion lhs diff --git a/dag_in_context/src/utility/util.egg b/dag_in_context/src/utility/util.egg index 711b0461..452c960f 100644 --- a/dag_in_context/src/utility/util.egg +++ b/dag_in_context/src/utility/util.egg @@ -25,34 +25,72 @@ (= len (TypeList-length tl))) ((set (tuple-length expr) len)) :ruleset always-run) +(relation tuples-to-generate-get-for (Expr)) +(relation tuples-to-generate-get-for-list (ListExpr)) + +(rule ((= e (DoWhile inputs pred_out))) + ((tuples-to-generate-get-for e) + (tuples-to-generate-get-for inputs) + (tuples-to-generate-get-for pred_out)) + :ruleset always-run) +(rule ((= e (If cond inputs thn els))) + ((tuples-to-generate-get-for e) + (tuples-to-generate-get-for inputs) + (tuples-to-generate-get-for thn) + (tuples-to-generate-get-for els)) + :ruleset always-run) +(rule ((= e (Switch pred inputs branch))) + ((tuples-to-generate-get-for e) + (tuples-to-generate-get-for-list branch) + (tuples-to-generate-get-for inputs)) + :ruleset always-run) +(rule ((tuples-to-generate-get-for-list (Cons hd tl))) + ((tuples-to-generate-get-for hd) + (tuples-to-generate-get-for-list tl)) + :ruleset always-run) +(rule ((= e (Arg t a))) + ((tuples-to-generate-get-for e)) + :ruleset always-run) + + ;; Create a Get for every index, and rewrite it to see through Concat -(rule ((Single expr)) ((union (Get (Single expr) 0) expr)) :ruleset always-run) +; (rule ((Single expr)) ((union (Get (Single expr) 0) expr)) :ruleset always-run) ;; initial get -(rule ((> (tuple-length tuple) 0)) +(rule ((> (tuple-length tuple) 0) + (tuples-to-generate-get-for tuple)) ((Get tuple 0)) :ruleset always-run) ;; next get (rule ((= len (tuple-length tuple)) (= ith (Get tuple i)) (< (+ i 1) len) + (tuples-to-generate-get-for tuple) ) ((Get tuple (+ 1 i))) :ruleset always-run) -;; descend left -(rule ((Get (Concat expr1 expr2) i) - (= (tuple-length expr1) len1) - (< i len1)) - ((union (Get (Concat expr1 expr2) i) - (Get expr1 i))) - :ruleset always-run) -;; descend right -(rule ((Get (Concat expr1 expr2) i) - (= (tuple-length expr1) len1) - (>= i len1)) - ((union (Get (Concat expr1 expr2) i) - (Get expr2 (- i len1)))) - :ruleset always-run) +(function List-suffix (Expr i64) Expr) +(rule ((Get x i)) + ((union (List-suffix x 0) x)) + :ruleset always-run) +(rule ((= (List-suffix x n) (Concat (Single hd) tl))) + ((union (List-suffix x (+ n 1)) tl)) + :ruleset always-run) +(rule ((= lhs (Get x i)) + (= (List-suffix x i) (Concat (Single e) rest))) + ((union lhs e)) + :ruleset always-run) +(rule ((= lhs (Get x i)) + (= (List-suffix x i) (Single e))) + ((union lhs e)) + :ruleset always-run) +; ;; descend left +; (rewrite (Get (Concat (Single expr1) expr2) 0) expr1 +; :ruleset always-run) +; ;; descend right +; (rewrite (Get (Concat (Single expr1) expr2) i) (Get expr2 (- i 1)) +; :when ((> i 0)) +; :ruleset always-run) ;; A temporary context. diff --git a/dag_in_context/src/utility/util.rs b/dag_in_context/src/utility/util.rs index a3f4ea20..a440c204 100644 --- a/dag_in_context/src/utility/util.rs +++ b/dag_in_context/src/utility/util.rs @@ -78,6 +78,14 @@ fn test_tuple_ith() -> crate::Result { (Concat (Single (Const (Int 0) {emptyt} {ctx})) (Single (Const (Int 1) {emptyt} {ctx}))) (Concat (Single (Const (Int 2) {emptyt} {ctx})) (Single (Const (Int 3) {emptyt} {ctx}))))) + ;; Gets of tup and tup2 are only generated when tup and tup2 are in critical positions + ;; like inputs to a DoWhile, + (let tup_type (TupleT (TCons (IntT) (TCons (IntT) (TCons (IntT) (TCons (IntT) (TNil))))))) + (let body (Concat (Const (Bool true) tup_type (TmpCtx)) (Arg tup_type (TmpCtx)))) + (let loop (DoWhile tup body)) + (union (TmpCtx) (InLoop tup body)) + (delete (TmpCtx)) + ;; with print (let tup2 (Concat (Concat @@ -85,6 +93,13 @@ fn test_tuple_ith() -> crate::Result { (Concat (Single (Const (Int 1) {emptyt} {ctx})) (Single (Const (Int 2) {emptyt} {ctx})))) (Single (Const (Int 3) {emptyt} {ctx})))) + + (let tup2_type (TupleT (TCons (StateT) (TCons (IntT) (TCons (IntT) (TCons (IntT) (TNil))))))) + (let body2 (Concat (Const (Bool true) tup2_type (TmpCtx)) (Arg tup2_type (TmpCtx)))) + (let loop2 (DoWhile tup2 body2)) + (union (TmpCtx) (InLoop tup2 body2)) + (delete (TmpCtx)) + " ); diff --git a/tests/snapshots/files__block-diamond-optimize-sequential.snap b/tests/snapshots/files__block-diamond-optimize-sequential.snap index 646549c4..76b2474d 100644 --- a/tests/snapshots/files__block-diamond-optimize-sequential.snap +++ b/tests/snapshots/files__block-diamond-optimize-sequential.snap @@ -8,31 +8,22 @@ expression: visualization.result c2_: int = const 1; c3_: int = const 2; v4_: bool = lt v0 c3_; - c5_: int = const 0; - c6_: int = const 5; - v7_: int = id c2_; + c5_: int = const 4; + v6_: int = select v4_ c5_ c2_; + v7_: int = id v6_; v8_: int = id c2_; - v9_: int = id c3_; - br v4_ .b10_ .b11_; + br v4_ .b9_ .b10_; +.b9_: + v11_: int = add c2_ v7_; + print v11_; + ret; + jmp .b12_; .b10_: - c12_: int = const 4; - v7_: int = id c12_; + v13_: int = add c3_ v6_; + v7_: int = id v13_; v8_: int = id c2_; - v9_: int = id c3_; - v13_: int = id v7_; - v14_: int = id v8_; - v15_: int = add c2_ v13_; - print v15_; - ret; - jmp .b16_; -.b11_: - v13_: int = id v7_; - v14_: int = id v8_; - v17_: int = add v7_ v9_; - v13_: int = id v17_; - v14_: int = id v8_; - v15_: int = add c2_ v13_; - print v15_; + v11_: int = add c2_ v7_; + print v11_; ret; -.b16_: +.b12_: } diff --git a/tests/snapshots/files__block-diamond-optimize.snap b/tests/snapshots/files__block-diamond-optimize.snap index 646549c4..76b2474d 100644 --- a/tests/snapshots/files__block-diamond-optimize.snap +++ b/tests/snapshots/files__block-diamond-optimize.snap @@ -8,31 +8,22 @@ expression: visualization.result c2_: int = const 1; c3_: int = const 2; v4_: bool = lt v0 c3_; - c5_: int = const 0; - c6_: int = const 5; - v7_: int = id c2_; + c5_: int = const 4; + v6_: int = select v4_ c5_ c2_; + v7_: int = id v6_; v8_: int = id c2_; - v9_: int = id c3_; - br v4_ .b10_ .b11_; + br v4_ .b9_ .b10_; +.b9_: + v11_: int = add c2_ v7_; + print v11_; + ret; + jmp .b12_; .b10_: - c12_: int = const 4; - v7_: int = id c12_; + v13_: int = add c3_ v6_; + v7_: int = id v13_; v8_: int = id c2_; - v9_: int = id c3_; - v13_: int = id v7_; - v14_: int = id v8_; - v15_: int = add c2_ v13_; - print v15_; - ret; - jmp .b16_; -.b11_: - v13_: int = id v7_; - v14_: int = id v8_; - v17_: int = add v7_ v9_; - v13_: int = id v17_; - v14_: int = id v8_; - v15_: int = add c2_ v13_; - print v15_; + v11_: int = add c2_ v7_; + print v11_; ret; -.b16_: +.b12_: } diff --git a/tests/snapshots/files__collatz_redundant_computation-optimize-sequential.snap b/tests/snapshots/files__collatz_redundant_computation-optimize-sequential.snap index 421ae7f0..fb29cb36 100644 --- a/tests/snapshots/files__collatz_redundant_computation-optimize-sequential.snap +++ b/tests/snapshots/files__collatz_redundant_computation-optimize-sequential.snap @@ -19,7 +19,7 @@ expression: visualization.result v13_: bool = eq v7_ v8_; v14_: int = id v6_; v15_: int = id v7_; - v16_: int = id v8_; + v16_: int = id v7_; v17_: int = id v9_; v18_: int = id v10_; v19_: int = id v11_; diff --git a/tests/snapshots/files__collatz_redundant_computation-optimize.snap b/tests/snapshots/files__collatz_redundant_computation-optimize.snap index 421ae7f0..fb29cb36 100644 --- a/tests/snapshots/files__collatz_redundant_computation-optimize.snap +++ b/tests/snapshots/files__collatz_redundant_computation-optimize.snap @@ -19,7 +19,7 @@ expression: visualization.result v13_: bool = eq v7_ v8_; v14_: int = id v6_; v15_: int = id v7_; - v16_: int = id v8_; + v16_: int = id v7_; v17_: int = id v9_; v18_: int = id v10_; v19_: int = id v11_; diff --git a/tests/snapshots/files__fib_recursive-optimize-sequential.snap b/tests/snapshots/files__fib_recursive-optimize-sequential.snap index 9b65eca3..3d068075 100644 --- a/tests/snapshots/files__fib_recursive-optimize-sequential.snap +++ b/tests/snapshots/files__fib_recursive-optimize-sequential.snap @@ -18,37 +18,37 @@ expression: visualization.result br v9_ .b10_ .b11_; .b10_: v12_: bool = eq c2_ c2_; - v13_: int = id c4_; + v13_: int = id v0; br v12_ .b14_ .b15_; .b14_: - v16_: int = id c4_; + v16_: int = id v0; v5_: int = id v16_; ret v5_; jmp .b8_; .b15_: - v17_: bool = eq c2_ c4_; + v17_: bool = eq c2_ v0; br v17_ .b18_ .b19_; .b18_: v20_: bool = eq c2_ c2_; - v21_: int = id c4_; + v21_: int = id c2_; br v20_ .b22_ .b23_; .b22_: - v24_: int = id c4_; + v24_: int = id c2_; v13_: int = id v24_; - v16_: int = id c4_; + v16_: int = id v0; v5_: int = id v16_; ret v5_; jmp .b8_; .b23_: - v25_: bool = eq c2_ c4_; + v25_: bool = eq c2_ c2_; br v25_ .b26_ .b27_; .b26_: v28_: int = call @fac c2_; - v29_: int = id c4_; + v29_: int = id c2_; v21_: int = id v29_; - v24_: int = id c4_; + v24_: int = id c2_; v13_: int = id v24_; - v16_: int = id c4_; + v16_: int = id v0; v5_: int = id v16_; ret v5_; jmp .b8_; @@ -60,19 +60,19 @@ expression: visualization.result v34_: int = add v31_ v33_; v29_: int = id v34_; v21_: int = id v29_; - v24_: int = id c4_; + v24_: int = id c2_; v13_: int = id v24_; - v16_: int = id c4_; + v16_: int = id v0; v5_: int = id v16_; ret v5_; jmp .b8_; .b19_: c35_: int = const -1; v36_: bool = eq c2_ c35_; - v37_: int = id c4_; + v37_: int = id v0; br v36_ .b38_ .b39_; .b39_: - v40_: bool = eq c35_ c4_; + v40_: bool = eq c35_ v0; br v40_ .b41_ .b42_; .b41_: v43_: int = call @fac c2_; @@ -81,18 +81,18 @@ expression: visualization.result .b38_: c45_: int = const -2; v46_: bool = eq c2_ c45_; - v47_: int = id c4_; + v47_: int = id v0; br v46_ .b48_ .b49_; .b48_: v50_: int = add v37_ v47_; v24_: int = id v50_; v13_: int = id v24_; - v16_: int = id c4_; + v16_: int = id v0; v5_: int = id v16_; ret v5_; jmp .b8_; .b49_: - v51_: bool = eq c45_ c4_; + v51_: bool = eq c45_ v0; br v51_ .b52_ .b53_; .b52_: v54_: int = call @fac c2_; @@ -101,7 +101,7 @@ expression: visualization.result v50_: int = add v37_ v47_; v24_: int = id v50_; v13_: int = id v24_; - v16_: int = id c4_; + v16_: int = id v0; v5_: int = id v16_; ret v5_; jmp .b8_; @@ -116,7 +116,7 @@ expression: visualization.result v50_: int = add v37_ v47_; v24_: int = id v50_; v13_: int = id v24_; - v16_: int = id c4_; + v16_: int = id v0; v5_: int = id v16_; ret v5_; jmp .b8_; @@ -139,10 +139,10 @@ expression: visualization.result br v71_ .b72_ .b73_; .b72_: v74_: bool = eq c2_ c2_; - v75_: int = id c4_; + v75_: int = id v66_; br v74_ .b76_ .b77_; .b76_: - v78_: int = id c4_; + v78_: int = id v66_; v68_: int = id v78_; .b69_: v79_: int = sub v66_ c4_; @@ -160,10 +160,10 @@ expression: visualization.result br v85_ .b86_ .b87_; .b86_: v88_: bool = eq c2_ c2_; - v89_: int = id c4_; + v89_: int = id v79_; br v88_ .b90_ .b91_; .b90_: - v92_: int = id c4_; + v92_: int = id v79_; v81_: int = id v92_; v84_: int = add v68_ v81_; v16_: int = id v84_; @@ -171,13 +171,13 @@ expression: visualization.result ret v5_; jmp .b8_; .b91_: - v93_: bool = eq c2_ c4_; + v93_: bool = eq c2_ v79_; br v93_ .b94_ .b95_; .b94_: v96_: int = call @fac c2_; - v97_: int = id c4_; + v97_: int = id c2_; v89_: int = id v97_; - v92_: int = id c4_; + v92_: int = id v79_; v81_: int = id v92_; v84_: int = add v68_ v81_; v16_: int = id v84_; @@ -192,7 +192,7 @@ expression: visualization.result v102_: int = add v101_ v99_; v97_: int = id v102_; v89_: int = id v97_; - v92_: int = id c4_; + v92_: int = id v79_; v81_: int = id v92_; v84_: int = add v68_ v81_; v16_: int = id v84_; @@ -209,7 +209,7 @@ expression: visualization.result br v108_ .b109_ .b110_; .b109_: v111_: int = call @fac c2_; - v112_: int = id c4_; + v112_: int = id v103_; v105_: int = id v112_; .b106_: v113_: int = sub v103_ c4_; @@ -230,7 +230,7 @@ expression: visualization.result br v119_ .b120_ .b121_; .b120_: v122_: int = call @fac c2_; - v123_: int = id c4_; + v123_: int = id v113_; v115_: int = id v123_; v118_: int = add v105_ v115_; v92_: int = id v118_; @@ -266,13 +266,13 @@ expression: visualization.result v105_: int = id v112_; jmp .b106_; .b77_: - v134_: bool = eq c2_ c4_; + v134_: bool = eq c2_ v66_; br v134_ .b135_ .b136_; .b135_: v137_: int = call @fac c2_; - v138_: int = id c4_; + v138_: int = id c2_; v75_: int = id v138_; - v78_: int = id c4_; + v78_: int = id v66_; v68_: int = id v78_; jmp .b69_; .b136_: @@ -283,7 +283,7 @@ expression: visualization.result v143_: int = add v140_ v142_; v138_: int = id v143_; v75_: int = id v138_; - v78_: int = id c4_; + v78_: int = id v66_; v68_: int = id v78_; jmp .b69_; .b73_: @@ -296,7 +296,7 @@ expression: visualization.result br v149_ .b150_ .b151_; .b150_: v152_: int = call @fac c2_; - v153_: int = id c4_; + v153_: int = id v144_; v146_: int = id v153_; .b147_: v154_: int = sub v144_ c4_; @@ -308,7 +308,7 @@ expression: visualization.result br v159_ .b160_ .b161_; .b160_: v162_: int = call @fac c2_; - v163_: int = id c4_; + v163_: int = id v154_; v156_: int = id v163_; .b157_: v164_: int = add v146_ v156_; @@ -337,8 +337,8 @@ expression: visualization.result } @main { .b0_: - c1_: int = const 2; - c2_: int = const 0; + c1_: int = const 0; + c2_: int = const 2; v3_: bool = eq c1_ c2_; c4_: int = const 1; v5_: int = id c4_; @@ -348,27 +348,27 @@ expression: visualization.result ret; jmp .b8_; .b7_: - v9_: bool = eq c1_ c4_; + v9_: bool = eq c2_ c4_; br v9_ .b10_ .b11_; .b10_: - v12_: bool = eq c2_ c2_; + v12_: bool = eq c1_ c1_; c13_: int = const 1; v14_: int = id c13_; br v12_ .b15_ .b16_; .b15_: - v17_: int = id c1_; + v17_: int = id c2_; v5_: int = id v17_; print v5_; ret; jmp .b8_; .b16_: - v18_: bool = eq c13_ c2_; + v18_: bool = eq c13_ c1_; br v18_ .b19_ .b20_; .b19_: - v21_: int = call @fac c2_; - v22_: int = id c2_; + v21_: int = call @fac c1_; + v22_: int = id c1_; v14_: int = id v22_; - v17_: int = id c1_; + v17_: int = id c2_; v5_: int = id v17_; print v5_; ret; @@ -381,24 +381,24 @@ expression: visualization.result v27_: int = add v24_ v26_; v22_: int = id v27_; v14_: int = id v22_; - v17_: int = id c1_; + v17_: int = id c2_; v5_: int = id v17_; print v5_; ret; jmp .b8_; .b11_: - v28_: bool = eq c2_ c4_; + v28_: bool = eq c1_ c4_; v29_: int = id c4_; br v28_ .b30_ .b31_; .b31_: v32_: bool = eq c4_ c4_; br v32_ .b33_ .b34_; .b33_: - v35_: int = call @fac c2_; + v35_: int = call @fac c1_; v36_: int = id c4_; v29_: int = id v36_; .b30_: - v37_: bool = eq c2_ c2_; + v37_: bool = eq c1_ c1_; v38_: int = id c4_; br v37_ .b39_ .b40_; .b39_: @@ -409,11 +409,11 @@ expression: visualization.result ret; jmp .b8_; .b40_: - v42_: bool = eq c2_ c4_; + v42_: bool = eq c1_ c4_; br v42_ .b43_ .b44_; .b43_: - v45_: int = call @fac c2_; - v46_: int = id c4_; + v45_: int = call @fac c1_; + v46_: int = id c1_; v38_: int = id v46_; v41_: int = add v29_ v38_; v17_: int = id v41_; @@ -436,7 +436,7 @@ expression: visualization.result ret; jmp .b8_; .b34_: - v52_: int = call @fac c2_; + v52_: int = call @fac c1_; c53_: int = const -1; v54_: int = call @fac c53_; v55_: int = add v52_ v54_; diff --git a/tests/snapshots/files__fib_recursive-optimize.snap b/tests/snapshots/files__fib_recursive-optimize.snap index 1019a84a..3884bd9d 100644 --- a/tests/snapshots/files__fib_recursive-optimize.snap +++ b/tests/snapshots/files__fib_recursive-optimize.snap @@ -18,37 +18,37 @@ expression: visualization.result br v9_ .b10_ .b11_; .b10_: v12_: bool = eq c2_ c2_; - v13_: int = id c4_; + v13_: int = id v0; br v12_ .b14_ .b15_; .b14_: - v16_: int = id c4_; + v16_: int = id v0; v5_: int = id v16_; ret v5_; jmp .b8_; .b15_: - v17_: bool = eq c2_ c4_; + v17_: bool = eq c2_ v0; br v17_ .b18_ .b19_; .b18_: v20_: bool = eq c2_ c2_; - v21_: int = id c4_; + v21_: int = id v0; br v20_ .b22_ .b23_; .b22_: - v24_: int = id c4_; + v24_: int = id v0; v13_: int = id v24_; - v16_: int = id c4_; + v16_: int = id v0; v5_: int = id v16_; ret v5_; jmp .b8_; .b23_: - v25_: bool = eq c2_ c4_; + v25_: bool = eq c2_ v0; br v25_ .b26_ .b27_; .b26_: v28_: int = call @fac c2_; - v29_: int = id c4_; + v29_: int = id v0; v21_: int = id v29_; - v24_: int = id c4_; + v24_: int = id v0; v13_: int = id v24_; - v16_: int = id c4_; + v16_: int = id v0; v5_: int = id v16_; ret v5_; jmp .b8_; @@ -60,9 +60,9 @@ expression: visualization.result v34_: int = add v32_ v33_; v29_: int = id v34_; v21_: int = id v29_; - v24_: int = id c4_; + v24_: int = id v0; v13_: int = id v24_; - v16_: int = id c4_; + v16_: int = id v0; v5_: int = id v16_; ret v5_; jmp .b8_; @@ -71,31 +71,31 @@ expression: visualization.result v36_: bool = eq c2_ c35_; c37_: int = const -1; v38_: bool = eq c2_ c37_; - v39_: int = id c4_; + v39_: int = id v0; br v38_ .b40_ .b41_; .b40_: - v42_: int = id c4_; + v42_: int = id v0; .b43_: br v36_ .b44_ .b45_; .b44_: v46_: int = add v39_ v42_; v24_: int = id v46_; v13_: int = id v24_; - v16_: int = id c4_; + v16_: int = id v0; v5_: int = id v16_; ret v5_; jmp .b8_; .b45_: - v47_: bool = eq c35_ c4_; + v47_: bool = eq c35_ v0; br v47_ .b48_ .b49_; .b48_: v50_: int = call @fac c2_; - v51_: int = id c4_; + v51_: int = id v0; v42_: int = id v51_; v46_: int = add v39_ v42_; v24_: int = id v46_; v13_: int = id v24_; - v16_: int = id c4_; + v16_: int = id v0; v5_: int = id v16_; ret v5_; jmp .b8_; @@ -110,18 +110,18 @@ expression: visualization.result v46_: int = add v39_ v42_; v24_: int = id v46_; v13_: int = id v24_; - v16_: int = id c4_; + v16_: int = id v0; v5_: int = id v16_; ret v5_; jmp .b8_; .b41_: - v57_: bool = eq c37_ c4_; + v57_: bool = eq c37_ v0; br v57_ .b58_ .b59_; .b58_: v60_: int = call @fac c2_; - v61_: int = id c4_; + v61_: int = id v0; v39_: int = id v61_; - v42_: int = id c4_; + v42_: int = id v0; jmp .b43_; .b59_: c62_: int = const -3; @@ -131,7 +131,7 @@ expression: visualization.result v66_: int = add v64_ v65_; v61_: int = id v66_; v39_: int = id v61_; - v42_: int = id c4_; + v42_: int = id v0; jmp .b43_; .b11_: v67_: int = sub v0 c4_; @@ -155,10 +155,10 @@ expression: visualization.result br v79_ .b80_ .b81_; .b80_: v82_: bool = eq c2_ c2_; - v83_: int = id c4_; + v83_: int = id v68_; br v82_ .b84_ .b85_; .b84_: - v86_: int = id c4_; + v86_: int = id v68_; v74_: int = id v86_; v78_: int = add v71_ v74_; v16_: int = id v78_; @@ -166,13 +166,13 @@ expression: visualization.result ret v5_; jmp .b8_; .b85_: - v87_: bool = eq c2_ c4_; + v87_: bool = eq c2_ v68_; br v87_ .b88_ .b89_; .b88_: v90_: int = call @fac c2_; - v91_: int = id c4_; + v91_: int = id v68_; v83_: int = id v91_; - v86_: int = id c4_; + v86_: int = id v68_; v74_: int = id v86_; v78_: int = add v71_ v74_; v16_: int = id v78_; @@ -187,7 +187,7 @@ expression: visualization.result v96_: int = add v94_ v95_; v91_: int = id v96_; v83_: int = id v91_; - v86_: int = id c4_; + v86_: int = id v68_; v74_: int = id v86_; v78_: int = add v71_ v74_; v16_: int = id v78_; @@ -219,7 +219,7 @@ expression: visualization.result br v109_ .b110_ .b111_; .b110_: v112_: int = call @fac c2_; - v113_: int = id c4_; + v113_: int = id v98_; v104_: int = id v113_; v108_: int = add v101_ v104_; v86_: int = id v108_; @@ -250,7 +250,7 @@ expression: visualization.result br v119_ .b120_ .b121_; .b120_: v122_: int = call @fac c2_; - v123_: int = id c4_; + v123_: int = id v97_; v101_: int = id v123_; v104_: int = id c4_; jmp .b105_; @@ -269,21 +269,21 @@ expression: visualization.result br v129_ .b130_ .b131_; .b130_: v132_: bool = eq c2_ c2_; - v133_: int = id c4_; + v133_: int = id v67_; br v132_ .b134_ .b135_; .b134_: - v136_: int = id c4_; + v136_: int = id v67_; v71_: int = id v136_; v74_: int = id c4_; jmp .b75_; .b135_: - v137_: bool = eq c2_ c4_; + v137_: bool = eq c2_ v67_; br v137_ .b138_ .b139_; .b138_: v140_: int = call @fac c2_; - v141_: int = id c4_; + v141_: int = id v67_; v133_: int = id v141_; - v136_: int = id c4_; + v136_: int = id v67_; v71_: int = id v136_; v74_: int = id c4_; jmp .b75_; @@ -295,7 +295,7 @@ expression: visualization.result v146_: int = add v144_ v145_; v141_: int = id v146_; v133_: int = id v141_; - v136_: int = id c4_; + v136_: int = id v67_; v71_: int = id v136_; v74_: int = id c4_; jmp .b75_; @@ -315,7 +315,7 @@ expression: visualization.result br v158_ .b159_ .b160_; .b159_: v161_: int = call @fac c2_; - v162_: int = id c4_; + v162_: int = id v148_; v154_: int = id v162_; .b156_: v163_: int = add v151_ v154_; @@ -337,7 +337,7 @@ expression: visualization.result br v169_ .b170_ .b171_; .b170_: v172_: int = call @fac c2_; - v173_: int = id c4_; + v173_: int = id v147_; v151_: int = id v173_; v154_: int = id c4_; jmp .b155_; @@ -355,8 +355,8 @@ expression: visualization.result } @main { .b0_: - c1_: int = const 0; - c2_: int = const 2; + c1_: int = const 2; + c2_: int = const 0; v3_: bool = eq c1_ c2_; c4_: int = const 1; v5_: int = id c4_; @@ -366,27 +366,27 @@ expression: visualization.result ret; jmp .b8_; .b7_: - v9_: bool = eq c2_ c4_; + v9_: bool = eq c1_ c4_; br v9_ .b10_ .b11_; .b10_: - v12_: bool = eq c1_ c1_; + v12_: bool = eq c2_ c2_; c13_: int = const 1; v14_: int = id c13_; br v12_ .b15_ .b16_; .b15_: - v17_: int = id c2_; + v17_: int = id c4_; v5_: int = id v17_; print v5_; ret; jmp .b8_; .b16_: - v18_: bool = eq c13_ c1_; + v18_: bool = eq c13_ c2_; br v18_ .b19_ .b20_; .b19_: - v21_: int = call @fac c1_; + v21_: int = call @fac c2_; v22_: int = id c13_; v14_: int = id v22_; - v17_: int = id c2_; + v17_: int = id c4_; v5_: int = id v17_; print v5_; ret; @@ -399,14 +399,14 @@ expression: visualization.result v27_: int = add v25_ v26_; v22_: int = id v27_; v14_: int = id v22_; - v17_: int = id c2_; + v17_: int = id c4_; v5_: int = id v17_; print v5_; ret; jmp .b8_; .b11_: - v28_: bool = eq c1_ c1_; - v29_: bool = eq c1_ c4_; + v28_: bool = eq c2_ c2_; + v29_: bool = eq c2_ c4_; v30_: int = id c4_; br v29_ .b31_ .b32_; .b31_: @@ -421,10 +421,10 @@ expression: visualization.result ret; jmp .b8_; .b36_: - v38_: bool = eq c1_ c4_; + v38_: bool = eq c2_ c4_; br v38_ .b39_ .b40_; .b39_: - v41_: int = call @fac c1_; + v41_: int = call @fac c2_; v42_: int = id c4_; v33_: int = id v42_; v37_: int = add v30_ v33_; @@ -451,14 +451,14 @@ expression: visualization.result v48_: bool = eq c4_ c4_; br v48_ .b49_ .b50_; .b49_: - v51_: int = call @fac c1_; + v51_: int = call @fac c2_; v52_: int = id c4_; v30_: int = id v52_; v33_: int = id c4_; jmp .b34_; .b50_: c53_: int = const -1; - v54_: int = call @fac c1_; + v54_: int = call @fac c2_; v55_: int = call @fac c53_; v56_: int = add v54_ v55_; v52_: int = id v56_; diff --git a/tests/snapshots/files__gamma_condition_and-optimize-sequential.snap b/tests/snapshots/files__gamma_condition_and-optimize-sequential.snap index 62c20c1c..d2fd71ed 100644 --- a/tests/snapshots/files__gamma_condition_and-optimize-sequential.snap +++ b/tests/snapshots/files__gamma_condition_and-optimize-sequential.snap @@ -6,8 +6,8 @@ expression: visualization.result @main(v0: int) { .b1_: c2_: int = const 0; - v3_: bool = lt v0 c2_; - v4_: bool = gt v0 c2_; + v3_: bool = gt v0 c2_; + v4_: bool = lt v0 c2_; v5_: bool = and v3_ v4_; c6_: int = const 1; v7_: int = id c6_; @@ -17,8 +17,8 @@ expression: visualization.result ret; jmp .b10_; .b9_: - v11_: bool = lt v0 c2_; - v12_: bool = gt v0 c2_; + v11_: bool = lt c2_ v0; + v12_: bool = lt v0 c2_; v13_: bool = and v11_ v12_; c14_: int = const 3; v15_: int = id c14_; @@ -30,7 +30,7 @@ expression: visualization.result v21_: int = id c6_; .b22_: v23_: int = add v19_ v21_; - v24_: bool = gt v23_ v20_; + v24_: bool = lt v20_ v23_; v25_: bool = not v24_; v19_: int = id v23_; v20_: int = id v20_; diff --git a/tests/snapshots/files__gamma_condition_and-optimize.snap b/tests/snapshots/files__gamma_condition_and-optimize.snap index f473425d..a5e70213 100644 --- a/tests/snapshots/files__gamma_condition_and-optimize.snap +++ b/tests/snapshots/files__gamma_condition_and-optimize.snap @@ -6,8 +6,8 @@ expression: visualization.result @main(v0: int) { .b1_: c2_: int = const 0; - v3_: bool = lt v0 c2_; - v4_: bool = gt v0 c2_; + v3_: bool = lt c2_ v0; + v4_: bool = lt v0 c2_; c5_: int = const 1; c6_: int = const 3; v7_: int = id c6_; diff --git a/tests/snapshots/files__if_dead_code_nested-optimize-sequential.snap b/tests/snapshots/files__if_dead_code_nested-optimize-sequential.snap index 3c457c9d..fea4e238 100644 --- a/tests/snapshots/files__if_dead_code_nested-optimize-sequential.snap +++ b/tests/snapshots/files__if_dead_code_nested-optimize-sequential.snap @@ -24,7 +24,7 @@ expression: visualization.result ret; jmp .b15_; .b8_: - v16_: bool = gt v0 c6_; + v16_: bool = lt c6_ v0; c17_: bool = const false; c18_: int = const 2; v19_: int = id c18_; @@ -34,30 +34,10 @@ expression: visualization.result .b22_: v24_: bool = lt c5_ v0; c25_: int = const 4; - v26_: int = id c25_; - v27_: bool = id c17_; - v28_: int = id c4_; - br v24_ .b29_ .b30_; -.b29_: - c31_: int = const 3; - v26_: int = id c31_; - v27_: bool = id c17_; - v28_: int = id c4_; + v26_: int = select v24_ c5_ c25_; v19_: int = id v26_; - v20_: bool = id v27_; - v21_: int = id v28_; - v12_: int = id v19_; - v13_: int = id c4_; - v14_: int = select v3_ c2_ c4_; - print v14_; - print v3_; - print v12_; - ret; - jmp .b15_; -.b30_: - v19_: int = id v26_; - v20_: bool = id v27_; - v21_: int = id v28_; + v20_: bool = id c17_; + v21_: int = id c4_; v12_: int = id v19_; v13_: int = id c4_; v14_: int = select v3_ c2_ c4_; diff --git a/tests/snapshots/files__if_dead_code_nested-optimize.snap b/tests/snapshots/files__if_dead_code_nested-optimize.snap index 3c457c9d..fea4e238 100644 --- a/tests/snapshots/files__if_dead_code_nested-optimize.snap +++ b/tests/snapshots/files__if_dead_code_nested-optimize.snap @@ -24,7 +24,7 @@ expression: visualization.result ret; jmp .b15_; .b8_: - v16_: bool = gt v0 c6_; + v16_: bool = lt c6_ v0; c17_: bool = const false; c18_: int = const 2; v19_: int = id c18_; @@ -34,30 +34,10 @@ expression: visualization.result .b22_: v24_: bool = lt c5_ v0; c25_: int = const 4; - v26_: int = id c25_; - v27_: bool = id c17_; - v28_: int = id c4_; - br v24_ .b29_ .b30_; -.b29_: - c31_: int = const 3; - v26_: int = id c31_; - v27_: bool = id c17_; - v28_: int = id c4_; + v26_: int = select v24_ c5_ c25_; v19_: int = id v26_; - v20_: bool = id v27_; - v21_: int = id v28_; - v12_: int = id v19_; - v13_: int = id c4_; - v14_: int = select v3_ c2_ c4_; - print v14_; - print v3_; - print v12_; - ret; - jmp .b15_; -.b30_: - v19_: int = id v26_; - v20_: bool = id v27_; - v21_: int = id v28_; + v20_: bool = id c17_; + v21_: int = id c4_; v12_: int = id v19_; v13_: int = id c4_; v14_: int = select v3_ c2_ c4_; diff --git a/tests/snapshots/files__if_in_loop-optimize-sequential.snap b/tests/snapshots/files__if_in_loop-optimize-sequential.snap index bc0f7a91..c4c086be 100644 --- a/tests/snapshots/files__if_in_loop-optimize-sequential.snap +++ b/tests/snapshots/files__if_in_loop-optimize-sequential.snap @@ -8,26 +8,24 @@ expression: visualization.result c2_: int = const 0; c3_: int = const 1; c4_: int = const 10; - v5_: bool = lt v0 c3_; - v6_: int = id c2_; - v7_: int = id c3_; - v8_: int = id v0; - v9_: int = id c2_; - v10_: int = id c4_; - v11_: bool = id v5_; -.b12_: - v13_: int = select v11_ v7_ v9_; - print v13_; + v5_: int = id c2_; + v6_: int = id c3_; + v7_: int = id v0; + v8_: int = id c2_; + v9_: int = id c4_; +.b10_: + v11_: bool = lt v7_ v6_; + v12_: int = select v11_ v6_ v8_; + print v12_; print v11_; - v14_: int = add v6_ v7_; - v15_: bool = lt v6_ v10_; - v6_: int = id v14_; + v13_: int = add v5_ v6_; + v14_: bool = lt v5_ v9_; + v5_: int = id v13_; + v6_: int = id v6_; v7_: int = id v7_; v8_: int = id v8_; v9_: int = id v9_; - v10_: int = id v10_; - v11_: bool = id v11_; - br v15_ .b12_ .b16_; -.b16_: + br v14_ .b10_ .b15_; +.b15_: ret; } diff --git a/tests/snapshots/files__nested_call-optimize-sequential.snap b/tests/snapshots/files__nested_call-optimize-sequential.snap index 5ca7dc3d..0fa10fc3 100644 --- a/tests/snapshots/files__nested_call-optimize-sequential.snap +++ b/tests/snapshots/files__nested_call-optimize-sequential.snap @@ -5,10 +5,10 @@ expression: visualization.result # ARGS: @inc(v0: int): int { .b1_: - c2_: int = const 1; - v3_: int = add c2_ v0; - c4_: int = const 2; - v5_: int = mul c4_ v3_; + c2_: int = const 2; + c3_: int = const 1; + v4_: int = add c3_ v0; + v5_: int = mul c2_ v4_; ret v5_; } @double(v0: int): int { diff --git a/tests/snapshots/files__rec_to_loop-optimize-sequential.snap b/tests/snapshots/files__rec_to_loop-optimize-sequential.snap index e787087b..465ce77c 100644 --- a/tests/snapshots/files__rec_to_loop-optimize-sequential.snap +++ b/tests/snapshots/files__rec_to_loop-optimize-sequential.snap @@ -7,51 +7,75 @@ expression: visualization.result .b1_: c2_: int = const 0; v3_: bool = eq c2_ v0; - v4_: bool = not v3_; - v5_: int = id v0; - br v4_ .b6_ .b7_; + v4_: int = id v0; + br v3_ .b5_ .b6_; +.b5_: + ret v4_; + jmp .b7_; .b6_: - v8_: int = id v0; -.b9_: - print v8_; - c10_: int = const 1; - v11_: int = sub v8_ c10_; - c12_: int = const 0; - v13_: bool = eq c12_ v11_; - v14_: bool = not v13_; - v8_: int = id v11_; - br v14_ .b9_ .b15_; -.b15_: - v5_: int = id v8_; - ret c2_; - jmp .b16_; + c8_: int = const 0; + c9_: int = const 1; + v10_: int = sub v0 c9_; + v11_: bool = eq c8_ v10_; + print v0; + v12_: int = id v10_; + br v11_ .b13_ .b14_; +.b13_: + v4_: int = id v12_; + ret v4_; + jmp .b7_; +.b14_: + c15_: int = const 1; + v16_: int = sub v10_ c15_; + c17_: int = const 0; + v18_: bool = eq c17_ v16_; + print v10_; + v19_: int = id v16_; + br v18_ .b20_ .b21_; +.b20_: + v12_: int = id v19_; + v4_: int = id v12_; + ret v4_; + jmp .b7_; +.b21_: + c22_: int = const 1; + v23_: int = sub v16_ c22_; + print v16_; + v24_: int = call @recPrint v23_; + v19_: int = id v24_; + v12_: int = id v19_; + v4_: int = id v12_; + ret v4_; .b7_: - ret c2_; -.b16_: } @main(v0: int) { .b1_: c2_: int = const 0; v3_: bool = eq c2_ v0; - v4_: bool = not v3_; - v5_: int = id v0; - br v4_ .b6_ .b7_; + v4_: int = id v0; + br v3_ .b5_ .b6_; +.b5_: + ret; + jmp .b7_; .b6_: - v8_: int = id v0; -.b9_: - print v8_; - c10_: int = const 1; - v11_: int = sub v8_ c10_; - c12_: int = const 0; - v13_: bool = eq c12_ v11_; - v14_: bool = not v13_; - v8_: int = id v11_; - br v14_ .b9_ .b15_; -.b15_: - v5_: int = id v8_; + c8_: int = const 1; + v9_: int = sub v0 c8_; + c10_: int = const 0; + v11_: bool = eq c10_ v9_; + print v0; + v12_: int = id v9_; + br v11_ .b13_ .b14_; +.b13_: + v4_: int = id v12_; ret; - jmp .b16_; -.b7_: + jmp .b7_; +.b14_: + c15_: int = const 1; + v16_: int = sub v9_ c15_; + print v9_; + v17_: int = call @recPrint v16_; + v12_: int = id v17_; + v4_: int = id v12_; ret; -.b16_: +.b7_: } diff --git a/tests/snapshots/files__rec_to_loop-optimize.snap b/tests/snapshots/files__rec_to_loop-optimize.snap index e787087b..465ce77c 100644 --- a/tests/snapshots/files__rec_to_loop-optimize.snap +++ b/tests/snapshots/files__rec_to_loop-optimize.snap @@ -7,51 +7,75 @@ expression: visualization.result .b1_: c2_: int = const 0; v3_: bool = eq c2_ v0; - v4_: bool = not v3_; - v5_: int = id v0; - br v4_ .b6_ .b7_; + v4_: int = id v0; + br v3_ .b5_ .b6_; +.b5_: + ret v4_; + jmp .b7_; .b6_: - v8_: int = id v0; -.b9_: - print v8_; - c10_: int = const 1; - v11_: int = sub v8_ c10_; - c12_: int = const 0; - v13_: bool = eq c12_ v11_; - v14_: bool = not v13_; - v8_: int = id v11_; - br v14_ .b9_ .b15_; -.b15_: - v5_: int = id v8_; - ret c2_; - jmp .b16_; + c8_: int = const 0; + c9_: int = const 1; + v10_: int = sub v0 c9_; + v11_: bool = eq c8_ v10_; + print v0; + v12_: int = id v10_; + br v11_ .b13_ .b14_; +.b13_: + v4_: int = id v12_; + ret v4_; + jmp .b7_; +.b14_: + c15_: int = const 1; + v16_: int = sub v10_ c15_; + c17_: int = const 0; + v18_: bool = eq c17_ v16_; + print v10_; + v19_: int = id v16_; + br v18_ .b20_ .b21_; +.b20_: + v12_: int = id v19_; + v4_: int = id v12_; + ret v4_; + jmp .b7_; +.b21_: + c22_: int = const 1; + v23_: int = sub v16_ c22_; + print v16_; + v24_: int = call @recPrint v23_; + v19_: int = id v24_; + v12_: int = id v19_; + v4_: int = id v12_; + ret v4_; .b7_: - ret c2_; -.b16_: } @main(v0: int) { .b1_: c2_: int = const 0; v3_: bool = eq c2_ v0; - v4_: bool = not v3_; - v5_: int = id v0; - br v4_ .b6_ .b7_; + v4_: int = id v0; + br v3_ .b5_ .b6_; +.b5_: + ret; + jmp .b7_; .b6_: - v8_: int = id v0; -.b9_: - print v8_; - c10_: int = const 1; - v11_: int = sub v8_ c10_; - c12_: int = const 0; - v13_: bool = eq c12_ v11_; - v14_: bool = not v13_; - v8_: int = id v11_; - br v14_ .b9_ .b15_; -.b15_: - v5_: int = id v8_; + c8_: int = const 1; + v9_: int = sub v0 c8_; + c10_: int = const 0; + v11_: bool = eq c10_ v9_; + print v0; + v12_: int = id v9_; + br v11_ .b13_ .b14_; +.b13_: + v4_: int = id v12_; ret; - jmp .b16_; -.b7_: + jmp .b7_; +.b14_: + c15_: int = const 1; + v16_: int = sub v9_ c15_; + print v9_; + v17_: int = call @recPrint v16_; + v12_: int = id v17_; + v4_: int = id v12_; ret; -.b16_: +.b7_: } diff --git a/tests/snapshots/files__recurse_once-optimize-sequential.snap b/tests/snapshots/files__recurse_once-optimize-sequential.snap index 86d0906e..b5be4dda 100644 --- a/tests/snapshots/files__recurse_once-optimize-sequential.snap +++ b/tests/snapshots/files__recurse_once-optimize-sequential.snap @@ -10,34 +10,44 @@ expression: visualization.result v4_: int = id v0; br v3_ .b5_ .b6_; .b5_: - v7_: int = id v0; -.b8_: - c9_: int = const 1; - v10_: int = sub v7_ c9_; - c11_: int = const 0; - v12_: bool = lt c11_ v10_; - v7_: int = id v10_; - br v12_ .b8_ .b13_; + c7_: int = const 0; + c8_: int = const 1; + v9_: int = sub v0 c8_; + v10_: bool = lt c7_ v9_; + v11_: int = id v9_; + br v10_ .b12_ .b13_; +.b12_: + c14_: int = const 0; + c15_: int = const 1; + v16_: int = sub v9_ c15_; + v17_: bool = lt c14_ v16_; + v18_: int = id v16_; + br v17_ .b19_ .b20_; +.b19_: + c21_: int = const 1; + v22_: int = sub v16_ c21_; + v23_: int = call @to_zero v22_; + v18_: int = id v23_; + v11_: int = id v18_; + v4_: int = id v11_; + ret v4_; + jmp .b24_; +.b20_: + v11_: int = id v18_; + v4_: int = id v11_; + ret v4_; + jmp .b24_; .b13_: - v4_: int = id v7_; + v4_: int = id v11_; ret v4_; - jmp .b14_; + jmp .b24_; .b6_: ret v4_; -.b14_: +.b24_: } @main { .b0_: - c1_: int = const 1; - v2_: int = id c1_; -.b3_: - c4_: int = const 1; - v5_: int = sub v2_ c4_; - c6_: int = const 0; - v7_: bool = lt c6_ v5_; - v2_: int = id v5_; - br v7_ .b3_ .b8_; -.b8_: - print v2_; + c1_: int = const 0; + print c1_; ret; } diff --git a/tests/snapshots/files__recurse_once-optimize.snap b/tests/snapshots/files__recurse_once-optimize.snap index 86d0906e..b5be4dda 100644 --- a/tests/snapshots/files__recurse_once-optimize.snap +++ b/tests/snapshots/files__recurse_once-optimize.snap @@ -10,34 +10,44 @@ expression: visualization.result v4_: int = id v0; br v3_ .b5_ .b6_; .b5_: - v7_: int = id v0; -.b8_: - c9_: int = const 1; - v10_: int = sub v7_ c9_; - c11_: int = const 0; - v12_: bool = lt c11_ v10_; - v7_: int = id v10_; - br v12_ .b8_ .b13_; + c7_: int = const 0; + c8_: int = const 1; + v9_: int = sub v0 c8_; + v10_: bool = lt c7_ v9_; + v11_: int = id v9_; + br v10_ .b12_ .b13_; +.b12_: + c14_: int = const 0; + c15_: int = const 1; + v16_: int = sub v9_ c15_; + v17_: bool = lt c14_ v16_; + v18_: int = id v16_; + br v17_ .b19_ .b20_; +.b19_: + c21_: int = const 1; + v22_: int = sub v16_ c21_; + v23_: int = call @to_zero v22_; + v18_: int = id v23_; + v11_: int = id v18_; + v4_: int = id v11_; + ret v4_; + jmp .b24_; +.b20_: + v11_: int = id v18_; + v4_: int = id v11_; + ret v4_; + jmp .b24_; .b13_: - v4_: int = id v7_; + v4_: int = id v11_; ret v4_; - jmp .b14_; + jmp .b24_; .b6_: ret v4_; -.b14_: +.b24_: } @main { .b0_: - c1_: int = const 1; - v2_: int = id c1_; -.b3_: - c4_: int = const 1; - v5_: int = sub v2_ c4_; - c6_: int = const 0; - v7_: bool = lt c6_ v5_; - v2_: int = id v5_; - br v7_ .b3_ .b8_; -.b8_: - print v2_; + c1_: int = const 0; + print c1_; ret; } diff --git a/tests/snapshots/files__select-optimize.snap b/tests/snapshots/files__select-optimize.snap index 17394539..e8a2b7b5 100644 --- a/tests/snapshots/files__select-optimize.snap +++ b/tests/snapshots/files__select-optimize.snap @@ -15,32 +15,37 @@ expression: visualization.result c9_: int = const 5; v10_: bool = eq c9_ v5_; v11_: bool = not v10_; - v12_: int = id v4_; - v13_: int = id v5_; - v14_: int = id v6_; - v15_: int = id v7_; - br v11_ .b16_ .b17_; -.b16_: - c18_: int = const 1; - v19_: int = add c18_ v6_; - v20_: int = add v19_ v4_; - v21_: bool = eq v19_ v7_; - c22_: int = const 5; - v23_: int = select v21_ c22_ v5_; - v12_: int = id v20_; - v13_: int = id v23_; - v14_: int = id v19_; - v15_: int = id v7_; - v4_: int = id v12_; - v5_: int = id v13_; - v6_: int = id v14_; - v7_: int = id v15_; - jmp .b8_; -.b17_: - v4_: int = id v12_; - v5_: int = id v13_; - v6_: int = id v14_; - v7_: int = id v15_; + v12_: bool = not v11_; + v13_: bool = not v12_; + v14_: int = id v4_; + v15_: int = id v5_; + v16_: int = id v6_; + v17_: int = id v7_; + br v13_ .b18_ .b19_; +.b18_: + c20_: int = const 1; + v21_: int = add c20_ v6_; + v22_: int = add v21_ v4_; + v23_: bool = eq v21_ v7_; + c24_: int = const 5; + v25_: int = select v23_ c24_ v5_; + v14_: int = id v22_; + v15_: int = id v25_; + v16_: int = id v21_; + v17_: int = id v7_; + v4_: int = id v14_; + v5_: int = id v15_; + v6_: int = id v16_; + v7_: int = id v17_; +.b26_: + br v11_ .b8_ .b27_; +.b19_: + v4_: int = id v14_; + v5_: int = id v15_; + v6_: int = id v16_; + v7_: int = id v17_; + jmp .b26_; +.b27_: print v4_; ret; } diff --git a/tests/snapshots/files__simple_recursive-optimize-sequential.snap b/tests/snapshots/files__simple_recursive-optimize-sequential.snap index 76777a92..72c23a84 100644 --- a/tests/snapshots/files__simple_recursive-optimize-sequential.snap +++ b/tests/snapshots/files__simple_recursive-optimize-sequential.snap @@ -10,36 +10,51 @@ expression: visualization.result v4_: int = id v0; br v3_ .b5_ .b6_; .b5_: - v7_: int = id v0; -.b8_: - c9_: int = const 1; - v10_: int = add c9_ v7_; - print v10_; - c11_: int = const 2; - v12_: bool = lt v10_ c11_; - v7_: int = id v10_; - br v12_ .b8_ .b13_; + c7_: int = const 1; + v8_: int = add c7_ v0; + c9_: int = const 2; + v10_: bool = lt v8_ c9_; + print v8_; + v11_: int = id v8_; + br v10_ .b12_ .b13_; +.b12_: + c14_: int = const 1; + v15_: int = add c14_ v8_; + c16_: int = const 2; + v17_: bool = lt v15_ c16_; + print v15_; + v18_: int = id v15_; + br v17_ .b19_ .b20_; +.b19_: + c21_: int = const 1; + v22_: int = add c21_ v15_; + print v22_; + v23_: int = call @inc v22_; + v18_: int = id v23_; + v11_: int = id v18_; + v4_: int = id v11_; + ret v4_; + jmp .b24_; +.b20_: + v11_: int = id v18_; + v4_: int = id v11_; + ret v4_; + jmp .b24_; .b13_: - v4_: int = id v7_; + v4_: int = id v11_; ret v4_; - jmp .b14_; + jmp .b24_; .b6_: ret v4_; -.b14_: +.b24_: } @main { .b0_: - c1_: int = const 0; - v2_: int = id c1_; -.b3_: - c4_: int = const 1; - v5_: int = add c4_ v2_; - print v5_; - c6_: int = const 2; - v7_: bool = lt v5_ c6_; - v2_: int = id v5_; - br v7_ .b3_ .b8_; -.b8_: - print v2_; + c1_: int = const 2; + c2_: int = const 1; + print c2_; + print c1_; + v3_: int = call @inc c1_; + print v3_; ret; } diff --git a/tests/snapshots/files__simple_recursive-optimize.snap b/tests/snapshots/files__simple_recursive-optimize.snap index 76777a92..72c23a84 100644 --- a/tests/snapshots/files__simple_recursive-optimize.snap +++ b/tests/snapshots/files__simple_recursive-optimize.snap @@ -10,36 +10,51 @@ expression: visualization.result v4_: int = id v0; br v3_ .b5_ .b6_; .b5_: - v7_: int = id v0; -.b8_: - c9_: int = const 1; - v10_: int = add c9_ v7_; - print v10_; - c11_: int = const 2; - v12_: bool = lt v10_ c11_; - v7_: int = id v10_; - br v12_ .b8_ .b13_; + c7_: int = const 1; + v8_: int = add c7_ v0; + c9_: int = const 2; + v10_: bool = lt v8_ c9_; + print v8_; + v11_: int = id v8_; + br v10_ .b12_ .b13_; +.b12_: + c14_: int = const 1; + v15_: int = add c14_ v8_; + c16_: int = const 2; + v17_: bool = lt v15_ c16_; + print v15_; + v18_: int = id v15_; + br v17_ .b19_ .b20_; +.b19_: + c21_: int = const 1; + v22_: int = add c21_ v15_; + print v22_; + v23_: int = call @inc v22_; + v18_: int = id v23_; + v11_: int = id v18_; + v4_: int = id v11_; + ret v4_; + jmp .b24_; +.b20_: + v11_: int = id v18_; + v4_: int = id v11_; + ret v4_; + jmp .b24_; .b13_: - v4_: int = id v7_; + v4_: int = id v11_; ret v4_; - jmp .b14_; + jmp .b24_; .b6_: ret v4_; -.b14_: +.b24_: } @main { .b0_: - c1_: int = const 0; - v2_: int = id c1_; -.b3_: - c4_: int = const 1; - v5_: int = add c4_ v2_; - print v5_; - c6_: int = const 2; - v7_: bool = lt v5_ c6_; - v2_: int = id v5_; - br v7_ .b3_ .b8_; -.b8_: - print v2_; + c1_: int = const 2; + c2_: int = const 1; + print c2_; + print c1_; + v3_: int = call @inc c1_; + print v3_; ret; } diff --git a/tests/snapshots/files__small-collatz-optimize-sequential.snap b/tests/snapshots/files__small-collatz-optimize-sequential.snap index a5f839cd..ffa5e7af 100644 --- a/tests/snapshots/files__small-collatz-optimize-sequential.snap +++ b/tests/snapshots/files__small-collatz-optimize-sequential.snap @@ -20,7 +20,7 @@ expression: visualization.result v14_: int = id v6_; v15_: int = id v7_; v16_: int = id v8_; - v17_: int = id v9_; + v17_: int = id v7_; v18_: int = id v10_; v19_: int = id v11_; br v13_ .b20_ .b21_; diff --git a/tests/snapshots/files__small-collatz-optimize.snap b/tests/snapshots/files__small-collatz-optimize.snap index a5f839cd..ffa5e7af 100644 --- a/tests/snapshots/files__small-collatz-optimize.snap +++ b/tests/snapshots/files__small-collatz-optimize.snap @@ -20,7 +20,7 @@ expression: visualization.result v14_: int = id v6_; v15_: int = id v7_; v16_: int = id v8_; - v17_: int = id v9_; + v17_: int = id v7_; v18_: int = id v10_; v19_: int = id v11_; br v13_ .b20_ .b21_; diff --git a/tests/snapshots/files__sqrt_small-optimize.snap b/tests/snapshots/files__sqrt_small-optimize.snap index 24f7d2dc..b8cf9bc2 100644 --- a/tests/snapshots/files__sqrt_small-optimize.snap +++ b/tests/snapshots/files__sqrt_small-optimize.snap @@ -46,8 +46,8 @@ expression: visualization.result v31_: float = fadd v24_ v30_; v32_: float = fdiv v31_ v27_; v33_: float = fdiv v32_ v24_; - v34_: bool = fle v33_ v25_; - v35_: bool = fge v33_ v26_; + v34_: bool = fge v33_ v26_; + v35_: bool = fle v33_ v25_; v36_: bool = and v34_ v35_; v37_: bool = not v36_; v23_: float = id v23_;