Sfoglia il codice sorgente

[analyzer] cull dead branches during fusion

While the data flow analysis already detects and respects dead branches, the TIf remains in the AST at that point. This can cause it to block off some fusion, simply because something like `var x; if (false) { } else x = 1` can occur. With this change, we take out the TIf a bit earlier and thus make fusion stronger.
Simon Krajewski 8 anni fa
parent
commit
f4d27f38d7
1 ha cambiato i file con 9 aggiunte e 0 eliminazioni
  1. 9 0
      src/optimization/analyzerTexpr.ml

+ 9 - 0
src/optimization/analyzerTexpr.ml

@@ -657,6 +657,15 @@ module Fusion = struct
 				block_element acc (e1 :: el1 @ el2)
 			| {eexpr = TNew(c,tl,el1)} :: el2 when (match c.cl_constructor with Some cf when PurityState.is_pure c cf -> true | _ -> false) && config.local_dce ->
 				block_element acc (el1 @ el2)
+			| {eexpr = TIf ({ eexpr = TConst (TBool t) },e1,e2)} :: el ->
+				if t then
+					block_element acc (e1 :: el)
+				else begin match e2 with
+					| None ->
+						block_element acc el
+					| Some e ->
+						block_element acc (e :: el)
+				end
 			(* no-side-effect composites *)
 			| {eexpr = TParenthesis e1 | TMeta(_,e1) | TCast(e1,None) | TField(e1,_) | TUnop(_,_,e1)} :: el ->
 				block_element acc (e1 :: el)