• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Deoptimize Elimination
2## Overview
3**Deoptimize Elimination** - optimization which try to reduce number of DeoptimizeIf instructions.
4
5## Rationality
6Reduce number of instructions and removes unnecessary data-flow dependencies.
7
8## Dependences
9* RPO
10* DomTree
11
12## Algorithm
13Visit `DeoptimizeIf` and `SaveStateDeoptimize` instructions in RPO order and check specific rules.
14
15### Rules
16#### SaveStateDeoptimize
17If `SaveStateDeoptimize` didn't have users, this instruction is replaced by `NOP`.
18
19#### DeoptimizeIf
20If input of `DeoptimizeIf` is constant:
21* Constant is equal 0 -> `DeoptimizeIf` is replaced by `NOP`.
22* Other constant -> `DeoptimizeIf` is replaced by `Deoptimize` instruction.
23
24
25If input is `IsMustDeoptimize`:
26    Run search recursively from current block to start block.
27    We can remove guard (`IsMustDeoptimize` +  `DeoptimizeIf`), if guard is met in all ways and there should be no call instructions between current guard and found guards.
28
29For another inputs, algorithm try to replaced by `NOP` all `DeoptimizeIf` instruction which is dominated by current instruction and have same input.
30
31## Pseudocode
32    TODO
33
34## Examples
35Before Deoptimize Elimination:
36```
371. Constant 0
382. Constant 1
39
408. SaveStateDeoptimize
413. DeoptimizeIf v1, v8
424. DeoptimizeIf v2, v8
43
449. SaveStateDeoptimize
455. Some condition
466. DeoptimizeIf v5, v9
47
4810. SaveStateDeoptimize
497.  DeoptimizeIf v5, v10
50```
51
52After:
53```
541. Constant 0
552. Constant 1
56
578. SaveStateDeoptimize
583. NOP
594. Deoptimize v8
60
619. SaveStateDeoptimize
625. Some condition
636. DeoptimizeIf v5, v9
64
6510. NOP
667.  NOP
67```
68
69## Links
70Source code:
71[deoptimize_elimination.h](../optimizer/optimizations/deoptimize_elimination.h)
72[deoptimize_elimination.cpp](../optimizer/optimizations/deoptimize_elimination.cpp)
73
74Tests:
75[deoptimize_elimination_test.cpp](../tests/deoptimize_elimination_test.cpp)