Browse Source

rebuild prefix unops too (closes #4797)

Simon Krajewski 9 years ago
parent
commit
9ba6a39f18
2 changed files with 14 additions and 0 deletions
  1. 5 0
      analyzer.ml
  2. 9 0
      tests/optimization/src/TestJs.hx

+ 5 - 0
analyzer.ml

@@ -591,6 +591,11 @@ module Fusion = struct
 							change_num_uses v2 (-1);
 							let e = (f {e1 with eexpr = TUnop(op,Postfix,ev)}) in
 							fuse (e :: acc) el
+						| TLocal v2 when v == v2 ->
+							changed := true;
+							change_num_uses v2 (-1);
+							let e = (f {e1 with eexpr = TUnop(op,Prefix,ev)}) in
+							fuse (e :: acc) el
 						| _ ->
 							raise Exit
 					end

+ 9 - 0
tests/optimization/src/TestJs.hx

@@ -548,6 +548,15 @@ class TestJs {
 		a[i++] = i++;
 	}
 
+	@:js('
+		var i = 5;
+		while(--i >= 0) TestJs["use"](i);
+	')
+	static function testPrefixRebuilding() {
+		var i:Int = 5;
+		while (--i >= 0) use(i);
+	}
+
 	static inline function inlineCall<S, T>(d1:S, d2:T) {
 		return call(d2, d1);
 	}