# How to dump optimized IR?

**URL:** <https://numba.discourse.group/t/how-to-dump-optimized-ir/2812>\
**Category:** Support: How do I do ...?\
**Created:** [November 26, 2024, 1:59am UTC](https://numba.discourse.group/t/how-to-dump-optimized-ir/2812 "2024-11-26T01:59:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wearone](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/wearone/32/1159_2.png) [@wearone](https://numba.discourse.group/u/wearone)\
**Post date:** [November 26, 2024, 1:59am UTC](https://numba.discourse.group/t/how-to-dump-optimized-ir/2812/1 "2024-11-26T01:59:31Z")

</div>

I have a simple python function with an unused intermediate variable. How can I dump optimized IR? which shows the unused variable being removed. `NUMBA_DUMP_IR=1` only shows non-optimized IR.

Additionally, can I turn off all the optimization passes and enable them individually? Are there certain optimizations that cannot be turned off with stock numba?

```python
@njit('float32(float32, float32)')
def adder(a, b):
    inter = 5.0
    total = 0.0
    total = a+b
    return total

```

`NUMBA_TRACE=1 NUMBA_DUMP_IR=1 python extract.py`

```auto
== Pipeline: nopython for __main__.adder
== -- analyzing bytecode
== -- fix up args
== -- processing IR
---------------------------------IR DUMP: adder---------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

== -- Handle with contexts
== -- inline calls to locally defined closures
== -- rewrite semantic constants
== -- dead branch pruning
== -- nopython rewrites
== -- rewrite dynamic raises
== -- convert make_function into JIT functions
== -- inline inlinable functions
== -- dead branch pruning
== -- find literally calls
== -- handles literal_unroll
== -- ssa
== -- Literal propagation
== -- nopython frontend
== -- remove phis nodes
== -- inline overloaded functions
== -- nopython rewrites
== -- ensure features that are in use are in a valid form
== -- ensure IR is legal prior to lowering
== -- annotate types
== -- native lowering
== -- nopython mode backend
== -- dump parfor diagnostics

```

---

<div class="post-metadata">

**Author:** ![gmarkall](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/gmarkall/32/42_2.png) [@gmarkall](https://numba.discourse.group/u/gmarkall)\
**Post date:** [November 26, 2024, 10:04pm UTC](https://numba.discourse.group/t/how-to-dump-optimized-ir/2812/2 "2024-11-26T22:04:16Z")

</div>

You can set `NUMBA_DUMP_OPTIMIZED=1` - see [Environment variables — Numba 0+untagged.871.g53e976f.dirty documentation](https://numba.readthedocs.io/en/stable/reference/envvars.html#envvar-NUMBA_DUMP_OPTIMIZED)

---

<div class="post-metadata">

**Author:** ![wearone](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/wearone/32/1159_2.png) [@wearone](https://numba.discourse.group/u/wearone)\
**Post date:** [November 27, 2024, 12:42am UTC](https://numba.discourse.group/t/how-to-dump-optimized-ir/2812/3 "2024-11-27T00:42:23Z")

</div>

I’m aware of `NUMBA_DUMP_OPTIMIZED`, but that outputs LLVM IR, which is not what I’m looking for. I’m seeking the same IR format dump, which I believe is Numba’s IR, but the optimized version of it. The issue with LLVM IR is that it contains a lot of noise with metadata.

---

<div class="post-metadata">

**Author:** ![gmarkall](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/gmarkall/32/42_2.png) [@gmarkall](https://numba.discourse.group/u/gmarkall)\
**Post date:** [November 27, 2024, 10:25am UTC](https://numba.discourse.group/t/how-to-dump-optimized-ir/2812/4 "2024-11-27T10:25:47Z")

</div>

Whoops, sorry - I misunderstood / misread the question. Perhaps setting [the `NUMBA_DEBUG_PRINT_AFTER` environment variable](https://numba.readthedocs.io/en/stable/developer/custom_pipeline.html#observing-ir-changes) is helpful - e.g. `NUMBA_DEBUG_PRINT_AFTER=all`.

For a simple function, this gives me something like:

> **(Example of dump after all passes, long output)**
>
> ```auto
> $ NUMBA_DEBUG_PRINT_AFTER=all python -c "from numba import njit; njit('int32(int32, int32)')(lambda x, y: x + y)"
> --------------------------------- __main__.<lambda>: nopython: AFTER translate_bytecode----------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ------------------------------------- __main__.<lambda>: nopython: AFTER fixup_args--------------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ------------------------------------ __main__.<lambda>: nopython: AFTER ir_processing------------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ------------------------------------ __main__.<lambda>: nopython: AFTER with_lifting-------------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> -------------------------------- __main__.<lambda>: nopython: AFTER inline_closure_likes---------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ----------------------------- __main__.<lambda>: nopython: AFTER rewrite_semantic_constants------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ---------------------------------- __main__.<lambda>: nopython: AFTER dead_branch_prune----------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ---------------------------------- __main__.<lambda>: nopython: AFTER generic_rewrites-----------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ------------------------------- __main__.<lambda>: nopython: AFTER Rewrite dynamic raises--------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ------------------------ __main__.<lambda>: nopython: AFTER make_function_op_code_to_jit_function------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ---------------------------------- __main__.<lambda>: nopython: AFTER inline_inlinables----------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ---------------------------------- __main__.<lambda>: nopython: AFTER dead_branch_prune----------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ----------------------------------- __main__.<lambda>: nopython: AFTER find_literally------------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ----------------------------------- __main__.<lambda>: nopython: AFTER literal_unroll------------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ----------------------------------- __main__.<lambda>: nopython: AFTER reconstruct_ssa-----------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ---------------------------------- __main__.<lambda>: nopython: AFTER dead_branch_prune----------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> --------------------------------- __main__.<lambda>: nopython: AFTER LiteralPropagation----------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ------------------------------- __main__.<lambda>: nopython: AFTER nopython_type_inference-------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ------------------------------------- __main__.<lambda>: nopython: AFTER strip_phis--------------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ---------------------------------- __main__.<lambda>: nopython: AFTER inline_overloads-----------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ---------------------------------- __main__.<lambda>: nopython: AFTER nopython_rewrites----------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ------------------------ __main__.<lambda>: nopython: AFTER nopython_supported_feature_validation------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> return $12return_value.3 ['$12return_value.3']
> 
> ----------------------------------- __main__.<lambda>: nopython: AFTER ir_legalization-----------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> del y []
> del x []
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> del $binop_add8.2 []
> return $12return_value.3 ['$12return_value.3']
> 
> ----------------------------------- __main__.<lambda>: nopython: AFTER annotate_types------------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> del y []
> del x []
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> del $binop_add8.2 []
> return $12return_value.3 ['$12return_value.3']
> 
> ----------------------------------- __main__.<lambda>: nopython: AFTER native_lowering-----------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> del y []
> del x []
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> del $binop_add8.2 []
> return $12return_value.3 ['$12return_value.3']
> 
> ---------------------------------- __main__.<lambda>: nopython: AFTER nopython_backend-----------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> del y []
> del x []
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> del $binop_add8.2 []
> return $12return_value.3 ['$12return_value.3']
> 
> ------------------------------- __main__.<lambda>: nopython: AFTER dump_parfor_diagnostics-------------------------------
> label 0:
> x = arg(0, name=x) ['x']
> y = arg(1, name=y) ['y']
> $binop_add8.2 = x + y ['$binop_add8.2', 'x', 'y']
> del y []
> del x []
> $12return_value.3 = cast(value=$binop_add8.2) ['$12return_value.3', '$binop_add8.2']
> del $binop_add8.2 []
> return $12return_value.3 ['$12return_value.3']
> 
> ```

---

<div class="post-metadata">

**Author:** ![wearone](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/wearone/32/1159_2.png) [@wearone](https://numba.discourse.group/u/wearone)\
**Post date:** [November 29, 2024, 8:09pm UTC](https://numba.discourse.group/t/how-to-dump-optimized-ir/2812/5 "2024-11-29T20:09:34Z")

</div>

I still don’t see an IR that removes the unused constant. I’m expecting “inter” variable entry to be removed from the IR after optimization. Does numba even output this kind of information? more importantly, does numba even optimize for this?

What would be the best way to illustrate before and after code transformation? Would translating the IR to some kind of a directed graph show this? for ex. for unused variable it would show a node with no incoming edges?

```auto
----------------------------------- __main__.adder: nopython: AFTER translate_bytecode-----------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

--------------------------------------- __main__.adder: nopython: AFTER fixup_args---------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

---------------------------------IR DUMP: adder---------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

------------------------------------- __main__.adder: nopython: AFTER ir_processing--------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

-------------------------------------- __main__.adder: nopython: AFTER with_lifting--------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

---------------------------------- __main__.adder: nopython: AFTER inline_closure_likes----------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

------------------------------- __main__.adder: nopython: AFTER rewrite_semantic_constants-------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

----------------------------------- __main__.adder: nopython: AFTER dead_branch_prune------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

------------------------------------ __main__.adder: nopython: AFTER generic_rewrites------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

--------------------------------- __main__.adder: nopython: AFTER Rewrite dynamic raises---------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

------------------------- __main__.adder: nopython: AFTER make_function_op_code_to_jit_function--------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

----------------------------------- __main__.adder: nopython: AFTER inline_inlinables------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

----------------------------------- __main__.adder: nopython: AFTER dead_branch_prune------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

------------------------------------- __main__.adder: nopython: AFTER find_literally-------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

------------------------------------- __main__.adder: nopython: AFTER literal_unroll-------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

------------------------------------ __main__.adder: nopython: AFTER reconstruct_ssa-------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

----------------------------------- __main__.adder: nopython: AFTER LiteralPropagation-----------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

-------------------------------- __main__.adder: nopython: AFTER nopython_type_inference---------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

--------------------------------------- __main__.adder: nopython: AFTER strip_phis---------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

------------------------------------ __main__.adder: nopython: AFTER inline_overloads------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

----------------------------------- __main__.adder: nopython: AFTER nopython_rewrites------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

------------------------- __main__.adder: nopython: AFTER nopython_supported_feature_validation--------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    total = const(float, 0.0) ['total']
    total.1 = a + b ['a', 'b', 'total.1']
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    return $24return_value.6 ['$24return_value.6']

------------------------------------ __main__.adder: nopython: AFTER ir_legalization-------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    del inter []
    total = const(float, 0.0) ['total']
    del total []
    total.1 = a + b ['a', 'b', 'total.1']
    del b []
    del a []
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    del total.1 []
    return $24return_value.6 ['$24return_value.6']

------------------------------------- __main__.adder: nopython: AFTER annotate_types-------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    del inter []
    total = const(float, 0.0) ['total']
    del total []
    total.1 = a + b ['a', 'b', 'total.1']
    del b []
    del a []
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    del total.1 []
    return $24return_value.6 ['$24return_value.6']

------------------------------------ __main__.adder: nopython: AFTER native_lowering-------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    del inter []
    total = const(float, 0.0) ['total']
    del total []
    total.1 = a + b ['a', 'b', 'total.1']
    del b []
    del a []
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    del total.1 []
    return $24return_value.6 ['$24return_value.6']

------------------------------------ __main__.adder: nopython: AFTER nopython_backend------------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    del inter []
    total = const(float, 0.0) ['total']
    del total []
    total.1 = a + b ['a', 'b', 'total.1']
    del b []
    del a []
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    del total.1 []
    return $24return_value.6 ['$24return_value.6']

-------------------------------- __main__.adder: nopython: AFTER dump_parfor_diagnostics---------------------------------
label 0:
    a = arg(0, name=a) ['a']
    b = arg(1, name=b) ['b']
    inter = const(float, 5.0) ['inter']
    del inter []
    total = const(float, 0.0) ['total']
    del total []
    total.1 = a + b ['a', 'b', 'total.1']
    del b []
    del a []
    $24return_value.6 = cast(value=total.1) ['$24return_value.6', 'total.1']
    del total.1 []
    return $24return_value.6 ['$24return_value.6']

```

---

<div class="post-metadata">

**Author:** ![Oyibo](https://avatars.discourse-cdn.com/v4/letter/o/4af34b/32.png) [@Oyibo](https://numba.discourse.group/u/Oyibo)\
**Post date:** [November 30, 2024, 11:54am UTC](https://numba.discourse.group/t/how-to-dump-optimized-ir/2812/6 "2024-11-30T11:54:34Z")

</div>

Great question @wearone .  
If dead code elimination is done by LLVM it will not be visible in the Numba IR but in LLVM IR.  
Reconstructing Numba IR from the LLVM IR after optimizations is probably pretty tricky and not very practical. This is because LLVM applies a lot of transformations like inlining, constant folding, and dead code elimination, which can make it hard to see the original structure of the program. Once LLVM has done its optimizations, a lot of the original Numba IR is lost.  
One very important question when dealing with arrays would be whether SIMD optimizations are applied properly during the LLVM process. However, these low-level optimizations wouldn’t show up in the original Numba IR, since it’s more abstract and doesn’t usually expose these kinds of details.  
The Numba tools to inspect lower level optimizations would be inspect\_asm or inspect\_llvm or NUMBA\_DUMP\_OPTIMIZED. Are there other more human-friendly options to inspect optimized code provided by Numba @gmarkall ?
