@samitouri / QOS-React / commits / 5b9992075c

Driveby optimization of DCE

Lift a constant evaluation out of a loop

Joe Savona committed Apr 26, 2023 at 11:27 UTC 5b9992075c7127ff4e2b5361dd57b732f86b97ad
1 file changed +1 -1
compiler/forget/src/Optimization/DeadCodeElimination.ts
+1 -1
@@ -33,13 +33,13 @@ export function deadCodeElimination(fn: HIRFunction): void {
33 // of the blocks
34 const hasLoop = hasBackEdge(fn);
35
36 + const reversedBlocks = [...fn.body.blocks.values()].reverse();
37 let size = state.count;
38 do {
39 size = state.count;
40
41 // Iterate blocks in postorder (successors before predecessors, excepting loops)
42 // to find usages before declarations
42 - const reversedBlocks = [...fn.body.blocks.values()].reverse();
43 for (const block of reversedBlocks) {
44 for (const operand of eachTerminalOperand(block.terminal)) {
45 state.reference(operand.identifier);