heavyai/rbc

DeadCodeElimination pass might not be safe to use before type inference

Closed this issue · 1 comments

DeadCodeElimination pass was introduced in #405 to branch prune dtype comparisons. Turns out it might not be safe to use it before the full type inference pass is executed (ref). Nevertheless, it seems to be easy to remove dead basic blocks without relying on DCE.

Below is the IR generated for the test rbc/tests/test_omnisci_column_basic.py::test_column_dtype with and without DCE
https://gist.github.com/guilhermeleobas/d74b01c73f5eb3060a6bc844f7240155

In the basic block labeled 20, the branch condition is true and one could propagate this information to replace the branch by a direct jump to 34

label 20:
    i = $phi20.1                             ['$phi20.1', 'i']
    $24load_attr.3 = getattr(value=x, attr=dtype) ['$24load_attr.3', 'x']
    $26load_deref.4 = freevar(types: <module 'numba.types' from '/home/guilhermeleobas/miniconda3/envs/rbc/lib/python3.10/site-packages/numba/types/__init__.py'>) ['$26load_deref.4']
    $28load_attr.5 = getattr(value=$26load_deref.4, attr=int32) ['$26load_deref.4', '$28load_attr.5']
    $30compare_op.6 = const(bool, True)      ['$30compare_op.6']
    bool32 = global(bool: <class 'bool'>)    ['bool32']
    $32pred = call bool32($30compare_op.6, func=bool32, args=(Var($30compare_op.6, test_omnisci_column_basic.py:834),), kws=(), vararg=None, target=None) ['$30compare_op.6', '$32pred', 'bool32']
    branch $32pred, 34, 44                   ['$32pred']

Closing as this issue doesn't apply anymore