Index: test/mjsunit/switch-opt.js |
diff --git a/test/mjsunit/compiler/regress-1394.js b/test/mjsunit/switch-opt.js |
similarity index 56% |
copy from test/mjsunit/compiler/regress-1394.js |
copy to test/mjsunit/switch-opt.js |
index fbf435731f15dc05efd560e3202a63d32124337b..ba5a2159b4494a6738d3bbc2553f2871fcae1b8d 100644 |
--- a/test/mjsunit/compiler/regress-1394.js |
+++ b/test/mjsunit/switch-opt.js |
@@ -1,4 +1,4 @@ |
-// Copyright 2011 the V8 project authors. All rights reserved. |
+// Copyright 2013 the V8 project authors. All rights reserved. |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
// met: |
@@ -27,32 +27,65 @@ |
// Flags: --allow-natives-syntax |
-function f(x) { |
- var ret = -1; |
- switch(x){ |
- default: |
- case 0: |
- ret = 0; |
+var result = []; |
+ |
+function branch(b) { |
+ if (b == "deopt") { |
+ %DeoptimizeFunction(f); |
+ return "c"; |
+ } |
+ |
+ return b ? "a" : "b"; |
+} |
+ |
titzer
2013/12/10 14:27:09
I would like to see several more tests for this op
|
+function f(label, b1, b2) { |
+ switch (label) { |
+ case "string": |
+ result.push(1); |
break; |
- case 1: |
- ret = 1; |
+ case branch(b1) + branch(b2): |
+ result.push(2); |
break; |
- case 2: |
- ret = 2; |
+ case 10: |
+ result.push(3); |
break; |
- case 3: |
- ret = 3; |
+ default: |
+ branch(b1); |
+ result.push(4); |
break; |
- case 4: |
- ret = 4; |
+ case 30: |
+ result.push(5); |
break; |
} |
- return ret; |
-}; |
+} |
-for (var i = 0; i < 3; i++) assertEquals(i, f(i)); |
+function assertResult(r, label, b1, b2) { |
+ f(label, b1, b2); |
+ assertEquals(result, r); |
+ result = []; |
+} |
+// Warmup. |
+assertResult([2], "aa", true, true); |
+assertResult([2], "ab", true, false); |
+assertResult([2], "ba", false, true); |
+assertResult([2], "bb", false, false); |
+assertResult([4], "other"); |
+assertResult([5], 30); |
%OptimizeFunctionOnNextCall(f); |
+// Test regular behavior. |
+assertResult([2], "aa", true, true); |
+assertResult([1], "string"); |
+assertResult([4], "other"); |
+assertResult([5], 30); |
-assertEquals(0, f(0)); |
-assertEquals(1, f(1)); |
+// Test deopt at the beginning of the case label evaluation. |
+assertResult([2], "ca", "deopt", true); |
+%OptimizeFunctionOnNextCall(f); |
+assertResult([4], "ca", "deopt", false); |
+%OptimizeFunctionOnNextCall(f); |
+ |
+// Test deopt in the middle of the case label evaluation. |
+assertResult([2], "ac", true, "deopt"); |
+%OptimizeFunctionOnNextCall(f); |
+assertResult([4], "ac", false, "deopt"); |