diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-05-20 11:20:21 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-05-20 11:20:21 -0700 |
commit | b3449a949816e15cbb68e31f6965a7ce2bcadd43 (patch) | |
tree | b14a71efa55d6803d683d4d65465f77455faf1df /tools/js-optimizer.js | |
parent | 881f94c087e4417c874dc136d01c31011c24684f (diff) | |
parent | 751756ddffdbdf8061b4b73ac6848c0a1f5e61b7 (diff) |
Merge pull request #2367 from rfk/rfk/fix-elimination-of-conditionals
Fix elimination of conditional expressions in registerizeHarder
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r-- | tools/js-optimizer.js | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 088c4f0f..2004efda 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -2237,18 +2237,30 @@ function registerizeHarder(ast) { break; case 'conditional': isInExpr++; - buildFlowGraph(node[1]); - var jEnter = markJunction(); - var jExit = addJunction(); - if (node[2]) { - buildFlowGraph(node[2]); - } - joinJunction(jExit); - setJunction(jEnter); - if (node[3]) { - buildFlowGraph(node[3]); + // If the conditional has no side-effects, we can treat it as a single + // block, which might open up opportunities to remove it entirely. + if (!hasSideEffects(node)) { + buildFlowGraph(node[1]); + if (node[2]) { + buildFlowGraph(node[2]); + } + if (node[3]) { + buildFlowGraph(node[3]); + } + } else { + buildFlowGraph(node[1]); + var jEnter = markJunction(); + var jExit = addJunction(); + if (node[2]) { + buildFlowGraph(node[2]); + } + joinJunction(jExit); + setJunction(jEnter); + if (node[3]) { + buildFlowGraph(node[3]); + } + joinJunction(jExit); } - joinJunction(jExit); isInExpr--; break; case 'while': |