merge-phi-usage-analysis.js (1452B)
1 function expensive() { 2 with({}) {} 3 } 4 5 function phi_merge_0(i) { 6 // These computations can overflow, if the output is not truncated. 7 i = i | 0; 8 var a0 = i + i; 9 var a1 = i + i; 10 11 if ((a1 | 0) - ((2 * i) | 0)) { 12 // Good candidate for branch pruning, which marks only a1 as having 13 // removed uses. 14 expensive(); 15 expensive(); 16 expensive(); 17 expensive(); 18 expensive(); 19 } 20 21 // Simple branch made to let GVN merge the Phi instructions. 22 if (a1 % 3 == 1) { 23 a1 = 2 * i; 24 a0 = 2 * i; 25 } 26 27 // a0 is never used, but a1 is truncated. 28 return a1 | 0; 29 } 30 31 function phi_merge_1(i) { 32 // These computations can overflow, if the output is not truncated. 33 i = i | 0; 34 var a1 = i + i; 35 var a0 = i + i; 36 37 if ((a1 | 0) - ((2 * i) | 0)) { 38 // Good candidate for branch pruning, which marks only a1 as having 39 // removed uses. 40 expensive(); 41 expensive(); 42 expensive(); 43 expensive(); 44 expensive(); 45 } 46 47 // Simple branch made to let GVN merge the Phi instructions. 48 if (a1 % 3 == 1) { 49 a1 = 2 * i; 50 a0 = 2 * i; 51 } 52 53 // a0 is never used, but a1 is truncated. 54 return a1 | 0; 55 } 56 57 for (var j = 0; j < 300; j++) { 58 for (var i = 1; i == (i | 0); i = 2 * i + 1) { 59 assertEq(phi_merge_0(i) < 0x80000000, true); 60 assertEq(phi_merge_1(i) < 0x80000000, true); 61 } 62 }