aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Kelly <ryan@rfk.id.au>2014-01-23 21:59:13 +1100
committerRyan Kelly <ryan@rfk.id.au>2014-01-23 22:32:40 +1100
commit0bae95f2fc0f917b2ddf7343171c2353aa11a820 (patch)
tree18e7a09f5d406dcfe2731aa81df767c157dac2e6
parenta912e8271c990e59b2dd7c1d03d1adb9151f49de (diff)
Add dedicated testcases for registerizeHarder pass.
-rw-r--r--tests/test_other.py2
-rw-r--r--tools/test-js-optimizer-asm-regs-harder-output.js131
-rw-r--r--tools/test-js-optimizer-asm-regs-harder.js150
3 files changed, 283 insertions, 0 deletions
diff --git a/tests/test_other.py b/tests/test_other.py
index 53128391..8895a911 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -1773,6 +1773,8 @@ f.close()
['asm', 'eliminate']),
(path_from_root('tools', 'test-js-optimizer-asm-regs.js'), open(path_from_root('tools', 'test-js-optimizer-asm-regs-output.js')).read(),
['asm', 'registerize']),
+ (path_from_root('tools', 'test-js-optimizer-asm-regs-harder.js'), open(path_from_root('tools', 'test-js-optimizer-asm-regs-harder-output.js')).read(),
+ ['asm', 'registerizeHarder']),
(path_from_root('tools', 'test-js-optimizer-asm-regs-min.js'), open(path_from_root('tools', 'test-js-optimizer-asm-regs-min-output.js')).read(),
['asm', 'registerize', 'minifyLocals']),
(path_from_root('tools', 'test-js-optimizer-asm-pre.js'), open(path_from_root('tools', 'test-js-optimizer-asm-pre-output.js')).read(),
diff --git a/tools/test-js-optimizer-asm-regs-harder-output.js b/tools/test-js-optimizer-asm-regs-harder-output.js
new file mode 100644
index 00000000..710018bb
--- /dev/null
+++ b/tools/test-js-optimizer-asm-regs-harder-output.js
@@ -0,0 +1,131 @@
+function asm(d1, i2) {
+ d1 = +d1;
+ i2 = i2 | 0;
+ i2 = d1 + d1 | 0;
+ d1 = d(Math_max(10, Math_min(5, f())));
+ i2 = i2 + 2 | 0;
+ print(i2);
+ d1 = d1 * 5;
+ return d1;
+}
+function _doit(i3, i2, i1) {
+ i3 = i3 | 0;
+ i2 = i2 | 0;
+ i1 = i1 | 0;
+ i3 = STACKTOP;
+ _printf(__str | 0, (tempInt = STACKTOP, STACKTOP = STACKTOP + 8 | 0, HEAP32[(tempInt & 16777215) >> 2] = i2, HEAP32[(tempInt + 4 & 16777215) >> 2] = i1, tempInt));
+ STACKTOP = i3;
+ return 0 | 0;
+}
+function stackRestore(i1) {
+ i1 = i1 | 0;
+ STACKTOP = i1;
+}
+function switchey(d1, i2) {
+ d1 = +d1;
+ i2 = i2 | 0;
+ switch (d1 | 0) {
+ case 0:
+ i2 = d1 + d1 | 0;
+ d1 = d(Math_max(10, Math_min(5, f())));
+ i2 = i2 + 2 | 0;
+ print(i2);
+ d1 = d1 * 5;
+ return d1;
+ case 1:
+ return 20;
+ }
+}
+function switchey2() {
+ var i1 = 0, i2 = 0, i3 = 0, i4 = 0, i5 = 0, i6 = 0, d7 = +0, d8 = +0;
+ i2 = STACKTOP;
+ STACKTOP = STACKTOP + 8 | 0;
+ i6 = 1;
+ while (1) switch (i6 | 0) {
+ case 1:
+ i1 = i2 | 0;
+ __ZN6RandomC1Ev(i1);
+ i4 = 0;
+ i3 = 0;
+ i6 = 2;
+ break;
+ case 2:
+ d8 = +__ZN6Random3getEf(8, +1);
+ d7 = +__ZN6Random3getEf(i1, +1);
+ _printf(24, (tempInt = STACKTOP, STACKTOP = STACKTOP + 16 | 0, HEAPF64[CHECK_ALIGN_8(tempInt | 0) >> 3] = d8, HEAPF64[CHECK_ALIGN_8(tempInt + 8 | 0) >> 3] = d7, tempInt) | 0);
+ i5 = (d8 != d7 & 1) + i3 | 0;
+ i6 = i4 + 1 | 0;
+ if ((i6 | 0) < 100) {
+ i4 = i6;
+ i3 = i5;
+ i6 = 2;
+ break;
+ } else {
+ i6 = 3;
+ break;
+ }
+ case 3:
+ _printf(16, (tempInt = STACKTOP, STACKTOP = STACKTOP + 8 | 0, HEAP32[CHECK_ALIGN_4(tempInt | 0) >> 2] = i5, tempInt) | 0);
+ STACKTOP = i2;
+ return 0;
+ }
+ return 0;
+}
+function iffey() {
+ var i1 = 0, i2 = 0, i3 = 0, i4 = 0, i5 = 0, d6 = +0, d7 = +0;
+ i2 = STACKTOP;
+ STACKTOP = STACKTOP + 8 | 0;
+ i4 = 1;
+ while (1) {
+ if (i4 | 0) {
+ i1 = i2 | 0;
+ __ZN6RandomC1Ev(i1);
+ i3 = 0;
+ i5 = 0;
+ i4 = 2;
+ } else {
+ d7 = +__ZN6Random3getEf(8, +1);
+ d6 = +__ZN6Random3getEf(i1, +1);
+ _printf(24, (tempInt = STACKTOP, STACKTOP = STACKTOP + 16 | 0, HEAPF64[CHECK_ALIGN_8(tempInt | 0) >> 3] = d7, HEAPF64[CHECK_ALIGN_8(tempInt + 8 | 0) >> 3] = d6, tempInt) | 0);
+ i5 = (d7 != d6 & 1) + i5 | 0;
+ i3 = i3 + 1 | 0;
+ if ((i3 | 0) < 100) {
+ i4 = 2;
+ } else {
+ return 10;
+ }
+ }
+ }
+ return 0;
+}
+function labelledJump(i3) {
+ i3 = i3 | 0;
+ var i1 = 0, i2 = 0;
+ i2 = 2;
+ if (i3) {
+ i2 = 17;
+ i1 = 1;
+ }
+ if (i1 == 1) {
+ i3 = i2 + 1;
+ } else {
+ i3 = i2 + 1;
+ }
+ return i3;
+}
+function linkedVars() {
+ var i1 = 0, i2 = 0;
+ while (1) {
+ i2 = 9;
+ i1 = 5;
+ while (i2 > 0 || i1 > 0) {
+ if (i2 < i1) {
+ i2 = i2 - 1;
+ } else {
+ i1 = i1 - 1;
+ }
+ }
+ }
+ return i2 + i1;
+}
+
diff --git a/tools/test-js-optimizer-asm-regs-harder.js b/tools/test-js-optimizer-asm-regs-harder.js
new file mode 100644
index 00000000..cf44c1dd
--- /dev/null
+++ b/tools/test-js-optimizer-asm-regs-harder.js
@@ -0,0 +1,150 @@
+function asm(x, y) {
+ x = +x;
+ y = y | 0;
+ var int1 = 0, int2 = 0; // do not mix the types!
+ var double1 = +0, double2 = +0;
+ int1 = (x+x)|0;
+ double1 = d(Math_max(10, Math_min(5, f())));
+ int2 = (int1+2)|0;
+ print(int2);
+ double2 = double1*5;
+ return double2;
+}
+function _doit($x, $y$0, $y$1) {
+ $x = $x | 0;
+ $y$0 = $y$0 | 0;
+ $y$1 = $y$1 | 0;
+ var __stackBase__ = 0;
+ __stackBase__ = STACKTOP;
+ _printf(__str | 0, (tempInt = STACKTOP, STACKTOP = STACKTOP + 8 | 0, HEAP32[(tempInt & 16777215) >> 2] = $y$0, HEAP32[(tempInt + 4 & 16777215) >> 2] = $y$1, tempInt));
+ STACKTOP = __stackBase__;
+ return 0 | 0;
+}
+function stackRestore(top) {
+ top = top|0;
+ STACKTOP = top;
+}
+function switchey(x, y) {
+ x = +x;
+ y = y | 0;
+ var int1 = 0, int2 = 0; // do not mix the types!
+ var double1 = +0, double2 = +0;
+ switch(x|0) {
+ case 0:
+ int1 = (x+x)|0;
+ double1 = d(Math_max(10, Math_min(5, f())));
+ int2 = (int1+2)|0;
+ print(int2);
+ double2 = double1*5;
+ return double2;
+ case 1:
+ return 20;
+ }
+}
+function switchey2() {
+ var $rng2 = 0, $count_06 = 0, $i_05 = 0, $2 = +0, $3 = +0, $count_1 = 0, $9 = 0, label = 0, __stackBase__ = 0;
+ __stackBase__ = STACKTOP;
+ STACKTOP = STACKTOP + 8 | 0;
+ label = 1;
+ while (1) switch (label | 0) {
+ case 1:
+ $rng2 = __stackBase__ | 0;
+ __ZN6RandomC1Ev($rng2);
+ $i_05 = 0;
+ $count_06 = 0;
+ label = 2;
+ break;
+ case 2:
+ $2 = +__ZN6Random3getEf(8, +1);
+ $3 = +__ZN6Random3getEf($rng2, +1);
+ _printf(24, (tempInt = STACKTOP, STACKTOP = STACKTOP + 16 | 0, HEAPF64[CHECK_ALIGN_8(tempInt | 0) >> 3] = $2, HEAPF64[CHECK_ALIGN_8(tempInt + 8 | 0) >> 3] = $3, tempInt) | 0);
+ $count_1 = ($2 != $3 & 1) + $count_06 | 0;
+ $9 = $i_05 + 1 | 0;
+ if (($9 | 0) < 100) {
+ $i_05 = $9;
+ $count_06 = $count_1;
+ label = 2;
+ break;
+ } else {
+ label = 3;
+ break;
+ }
+ case 3:
+ _printf(16, (tempInt = STACKTOP, STACKTOP = STACKTOP + 8 | 0, HEAP32[CHECK_ALIGN_4(tempInt | 0) >> 2] = $count_1, tempInt) | 0);
+ STACKTOP = __stackBase__;
+ return 0;
+ }
+ return 0;
+}
+function iffey() {
+ var $rng2 = 0, $count_06 = 0, $i_05 = 0, $2 = +0, $3 = +0, $count_1 = 0, $9 = 0, label = 0, __stackBase__ = 0;
+ __stackBase__ = STACKTOP;
+ STACKTOP = STACKTOP + 8 | 0;
+ label = 1;
+ while (1) {
+ if (label | 0) {
+ $rng2 = __stackBase__ | 0;
+ __ZN6RandomC1Ev($rng2);
+ $i_05 = 0;
+ $count_06 = 0;
+ label = 2;
+ } else {
+ $2 = +__ZN6Random3getEf(8, +1);
+ $3 = +__ZN6Random3getEf($rng2, +1);
+ _printf(24, (tempInt = STACKTOP, STACKTOP = STACKTOP + 16 | 0, HEAPF64[CHECK_ALIGN_8(tempInt | 0) >> 3] = $2, HEAPF64[CHECK_ALIGN_8(tempInt + 8 | 0) >> 3] = $3, tempInt) | 0);
+ $count_1 = ($2 != $3 & 1) + $count_06 | 0;
+ $9 = $i_05 + 1 | 0;
+ if (($9 | 0) < 100) {
+ $i_05 = $9;
+ $count_06 = $count_1;
+ label = 2;
+ } else {
+ label = 3;
+ return 10;
+ }
+ }
+ }
+ return 0;
+}
+function labelledJump(x) {
+ x = x | 0;
+ var label = 0
+ // y and z don't conflict, but only if you know about labelled jumps.
+ var y = 0, z = 0;
+ y = 2;
+ if (x) {
+ z = 17;
+ label = 1;
+ }
+ if (label == 1) {
+ x = z + 1;
+ } else {
+ x = y + 1;
+ }
+ return x;
+}
+function linkedVars() {
+ var outer1 = 0, outer2 = 0;
+ var inner1_0 = 0, inner1_1 = 0, inner2_0 = 0, inner2_1 = 0;
+ while (1) {
+ outer1 = 9;
+ outer2 = 5;
+ while (outer1 > 0 || outer2 > 0) {
+ // All these copy assignment should be eliminated by var sharing.
+ inner1_0 = outer1;
+ inner2_0 = outer2;
+ if (inner1_0 < inner2_0) {
+ inner1_1 = inner1_0 - 1;
+ inner2_1 = inner2_0;
+ } else {
+ inner1_1 = inner1_0;
+ inner2_1 = inner2_0 - 1;
+ }
+ outer1 = inner1_1;
+ outer2 = inner2_1;
+ }
+ }
+ return outer1 + outer2;
+}
+// EMSCRIPTEN_GENERATED_FUNCTIONS: ["asm", "_doit", "stackRestore", "switchey", "switchey2", "iffey", "labelledJump", "linkedVars']
+