diff --git a/numba/core/ssa.py b/numba/core/ssa.py
index d38918f8c..a4b30df67 100644
--- a/numba/core/ssa.py
+++ b/numba/core/ssa.py
@@ -430,15 +430,18 @@ class _FixSSAVars(_BaseHandler):
             return self._find_def_from_top(states, label, loc=loc)
 
     def _stmt_index(self, defstmt, block, stop=-1):
-        """Find the postitional index of the statement at ``block``.
+        """Find the positional index of the statement at ``block``.
 
         Assumptions:
         - no two statements can point to the same object.
         """
-        try:
-            return block.body.index(defstmt, 0, stop)
-        except ValueError:
-            return len(block.body)
+        # Compare using id() as IR node equality is for semantic equivalence
+        # opposed to direct equality (the location and scope are not considered
+        # as part of the equality measure, this is important here).
+        for i in range(len(block.body))[:stop]:
+            if block.body[i] is defstmt:
+                return i
+        return len(block.body)
 
 
 def _warn_about_uninitialized_variable(varname, loc):
diff --git a/numba/typed/typedlist.py b/numba/typed/typedlist.py
index 82259b5bc..2d3efd195 100644
--- a/numba/typed/typedlist.py
+++ b/numba/typed/typedlist.py
@@ -355,14 +355,13 @@ class List(MutableSequence):
         return _pop(self, i)
 
     def extend(self, iterable):
-        # Empty iterable, do nothing
-        if len(iterable) == 0:
-            return self
         if not self._typed:
             # Need to get the first element of the iterable to initialise the
             # type of the list. FIXME: this may be a problem if the iterable
             # can not be sliced.
             self._initialise_list(iterable[0])
+            self.append(iterable[0])
+            return _extend(self, iterable[1:])
         return _extend(self, iterable)
 
     def remove(self, item):

SSA pass causes invalid compilation (array write elided).
From https://github.com/pymatting/pymatting/issues/15, whilst long, this compiles incorrectly if the SSA passes are enabled. Problem is marked in the source by `PROBLEM IS HERE` comment.
```python
import numpy as np
import llvmlite
import numba
import platform
from numba import njit

print("System:", platform.uname())
print("llvmlite version:", llvmlite.__version__)
print("numba version:", numba.__version__)
print("numpy version:", np.__version__)

# If this should crash, try without this line
@njit("i8(i8[:], i8[:], i8[:], i8[:], i8[:], f4[:, :, :], f4[:], f4[:, :], i8[:], i8)",
      boundscheck=True, debug=True)
def _make_tree(
    i0_inds,
    i1_inds,
    less_inds,
    more_inds,
    split_dims,
    bounds,
    split_values,
    points,
    indices,
    min_leaf_size,
):
    dimension = points.shape[1]
    # Expect log2(len(points) / min_leaf_size) depth, 1000 should be plenty
    stack = np.ones(1000, np.int64) * -99999999999999
    stack_size = 0
    n_nodes = 0
    # min_leaf_size <= leaf_node_size < max_leaf_size
    max_leaf_size = 2 * min_leaf_size

    # Push i0, i1, i_node
    stack[stack_size] = 0
    stack_size += 1
    stack[stack_size] = points.shape[0]
    stack_size += 1
    stack[stack_size] = n_nodes
    n_nodes += 1
    stack_size += 1

    # While there are more tree nodes to process recursively
    while stack_size > 0:
        print("start", stack[:20])
        stack_size -= 1
        i_node = stack[stack_size]
        stack_size -= 1
        i1 = stack[stack_size]
        stack_size -= 1
        i0 = stack[stack_size]

        lo = bounds[i_node, 0]
        hi = bounds[i_node, 1]

        for d in range(dimension):
            lo[d] = points[i0, d]
            hi[d] = points[i0, d]

        # Find lower and upper bounds of points for each dimension
        for i in range(i0 + 1, i1):
            for d in range(dimension):
                lo[d] = min(lo[d], points[i, d])
                hi[d] = max(hi[d], points[i, d])

        # Done if node is small
        if i1 - i0 <= max_leaf_size:
            i0_inds[i_node] = i0
            i1_inds[i_node] = i1
            less_inds[i_node] = -1
            more_inds[i_node] = -1
            split_dims[i_node] = -1
            split_values[i_node] = np.float32(0.0)
        else:
            # Split on largest dimension
            lengths = hi - lo
            split_dim = np.argmax(lengths)
            split_value = lo[split_dim] + np.float32(0.5) * lengths[split_dim]

            # Partition i0:i1 range into points where points[i, split_dim] < split_value
            i = i0
            j = i1 - 1

            while i < j:
                while i < j and points[i, split_dim] < split_value:
                    i += 1
                while i < j and points[j, split_dim] >= split_value:
                    j -= 1

                # Swap points
                if i < j:
                    for d in range(dimension):
                        temp = points[i, d]
                        points[i, d] = points[j, d]
                        points[j, d] = temp

                    temp_i_node = indices[i]
                    indices[i] = indices[j]
                    indices[j] = temp_i_node

            if points[i, split_dim] < split_value:
                i += 1

            i_split = i

            # Now it holds that:
            # for i in range(i0, i_split): assert(points[i, split_dim] < split_value)
            # for i in range(i_split, i1): assert(points[i, split_dim] >= split_value)

            # Ensure that each node has at least min_leaf_size children
            i_split = max(i0 + min_leaf_size, min(i1 - min_leaf_size, i_split))
            print(i_split)

            less = n_nodes
            n_nodes += 1
            more = n_nodes
            n_nodes += 1

            # push i0, i_split, less
            print("i0", i0, "to", stack_size)
            stack[stack_size] = i0
            stack_size += 1
            print("i_split", i_split, "to", stack_size)
            stack[stack_size] = i_split
            stack_size += 1
            print("less", less, "to", stack_size)
            stack[stack_size] = less
            stack_size += 1

            # push i_split, i1, more
            print("i_split", i_split, "to", stack_size)
            stack[stack_size] = i_split # <----- PROBLEM IS HERE, THIS DOESN'T GET WRITTEN
            #stack[stack_size] = np.sqrt(i_split) # DO THIS AND IT WORKS WITH SSA!
            stack_size += 1
            print("i1", i1, "to", stack_size)
            stack[stack_size] = i1
            stack_size += 1
            print("more", more, "to", stack_size)
            stack[stack_size] = more
            stack_size += 1

            i0_inds[i_node] = i0
            i1_inds[i_node] = i1
            less_inds[i_node] = less
            more_inds[i_node] = more
            split_dims[i_node] = split_dim
            split_values[i_node] = split_value
            print("end", stack_size, "stack", stack[:20])
    return n_nodes

def main():
    k = 20
    n_data = 100_000
    n_query = n_data
    dimension = 5
    np.random.seed(0)
    data_points = np.random.rand(n_data, dimension).astype(np.float32)
    min_leaf_size = 8

    n_data, dimension = data_points.shape

    max_nodes = 2 * ((n_data + min_leaf_size - 1) // min_leaf_size)

    i0_inds = np.empty(max_nodes, np.int64)
    i1_inds = np.empty(max_nodes, np.int64)
    less_inds = np.empty(max_nodes, np.int64)
    more_inds = np.empty(max_nodes, np.int64)
    split_dims = np.empty(max_nodes, np.int64)
    bounds = np.empty((max_nodes, 2, dimension), np.float32)
    split_values = np.empty(max_nodes, np.float32)
    shuffled_data_points = data_points.copy()
    shuffled_indices = np.arange(n_data).astype(np.int64)

    _make_tree(
        i0_inds,
        i1_inds,
        less_inds,
        more_inds,
        split_dims,
        bounds,
        split_values,
        shuffled_data_points,
        shuffled_indices,
        min_leaf_size,
    )

main()
diff --git a/numba/tests/test_ssa.py b/numba/tests/test_ssa.py
index 0d3e7bc2d..5df232f34 100644
--- a/numba/tests/test_ssa.py
+++ b/numba/tests/test_ssa.py
@@ -370,3 +370,26 @@ class TestReportedSSAIssues(SSABaseTest):
         res2 = jit(forceobj=True, looplift=False)(foo)(10, 10, data)
         np.testing.assert_array_equal(expect, res1)
         np.testing.assert_array_equal(expect, res2)
+
+    def test_issue5623_equal_statements_in_same_bb(self):
+
+        def foo(pred, stack):
+            i = 0
+            c = 1
+
+            if pred is True:
+                stack[i] = c
+                i += 1
+                stack[i] = c
+                i += 1
+
+        python = np.array([0, 666])
+        foo(True, python)
+
+        nb = np.array([0, 666])
+        njit(foo)(True, nb)
+
+        expect = np.array([1, 1])
+
+        np.testing.assert_array_equal(python, expect)
+        np.testing.assert_array_equal(nb, expect)
diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py
index 3ce886f07..72f17fb5a 100644
--- a/numba/tests/test_typedlist.py
+++ b/numba/tests/test_typedlist.py
@@ -738,33 +738,6 @@ class TestExtend(MemoryLeakMixin, TestCase):
         got = impl()
         self.assertEqual(expected, got)
 
-    def test_extend_single_value_container(self):
-        @njit
-        def impl():
-            l = List()
-            l.extend((100,))
-            return l
-
-        expected = impl.py_func()
-        got = impl()
-        self.assertEqual(expected, got)
-
-    def test_extend_empty_unrefined(self):
-        # Extending an unrefined list with an empty iterable doesn't work in a
-        # jit compiled function as the list remains untyped.
-        l = List()
-        l.extend(tuple())
-        self.assertEqual(len(l), 0)
-        self.assertFalse(l._typed)
-
-    def test_extend_empty_refiend(self):
-        # Extending a refined list with an empty iterable doesn't work in a
-        # jit compiled function as the (empty) argument can't be typed
-        l = List((1,))
-        l.extend(tuple())
-        self.assertEqual(len(l), 1)
-        self.assertTrue(l._typed)
-
 
 @njit
 def cmp(a, b):

pip install -e .
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-xdist pytest-mock pytest-asyncio pytest
apt-get update apt-get install -y gcc g++
3.7
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
certifi @ file:///croot/certifi_1671487769961/work/certifi
coverage==7.2.7
exceptiongroup==1.2.2
execnet==2.0.2
importlib-metadata==6.7.0
iniconfig==2.0.0
llvmlite==0.32.1
-e git+https://github.com/numba/numba.git@1dabbf67426ad6243f7b6d791d3d38dbb68ab33e#egg=numba
numpy==1.21.6
packaging==24.0
pluggy==1.2.0
pytest==7.4.4
pytest-asyncio==0.21.2
pytest-cov==4.1.0
pytest-mock==3.11.1
pytest-xdist==3.5.0
tomli==2.0.1
typing_extensions==4.7.1
zipp==3.15.0

name: numba
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - argparse==1.4.0
      - coverage==7.2.7
      - exceptiongroup==1.2.2
      - execnet==2.0.2
      - importlib-metadata==6.7.0
      - iniconfig==2.0.0
      - llvmlite==0.32.1
      - numpy==1.21.6
      - packaging==24.0
      - pluggy==1.2.0
      - pytest==7.4.4
      - pytest-asyncio==0.21.2
      - pytest-cov==4.1.0
      - pytest-mock==3.11.1
      - pytest-xdist==3.5.0
      - tomli==2.0.1
      - typing-extensions==4.7.1
      - zipp==3.15.0
prefix: /opt/conda/envs/numba

numba/tests/test_ssa.py::TestReportedSSAIssues::test_issue5623_equal_statements_in_same_bb
numba/tests/test_ssa.py::TestSSA::test_argument_name_reused numba/tests/test_ssa.py::TestSSA::test_if_else_redefine numba/tests/test_ssa.py::TestSSA::test_phi_propagation numba/tests/test_ssa.py::TestSSA::test_sum_2d_loop numba/tests/test_ssa.py::TestSSA::test_sum_loop numba/tests/test_ssa.py::TestSSA::test_sum_loop_2vars numba/tests/test_ssa.py::TestSSA::test_undefined_var numba/tests/test_ssa.py::TestReportedSSAIssues::test_issue2194 numba/tests/test_ssa.py::TestReportedSSAIssues::test_issue3094 numba/tests/test_ssa.py::TestReportedSSAIssues::test_issue3931 numba/tests/test_ssa.py::TestReportedSSAIssues::test_issue3976 numba/tests/test_ssa.py::TestReportedSSAIssues::test_issue3979 numba/tests/test_ssa.py::TestReportedSSAIssues::test_issue5219 numba/tests/test_ssa.py::TestReportedSSAIssues::test_issue5223 numba/tests/test_ssa.py::TestReportedSSAIssues::test_issue5243 numba/tests/test_ssa.py::TestReportedSSAIssues::test_issue5482_missing_variable_init numba/tests/test_ssa.py::TestReportedSSAIssues::test_issue5482_objmode_expr_null_lowering numba/tests/test_ssa.py::TestReportedSSAIssues::test_issue5493_unneeded_phi numba/tests/test_typedlist.py::TestTypedList::test_basic numba/tests/test_typedlist.py::TestTypedList::test_catch_global_typed_list numba/tests/test_typedlist.py::TestTypedList::test_compiled numba/tests/test_typedlist.py::TestTypedList::test_delitem_slice numba/tests/test_typedlist.py::TestTypedList::test_dtype numba/tests/test_typedlist.py::TestTypedList::test_dtype_raises_exception_on_untyped_list numba/tests/test_typedlist.py::TestTypedList::test_getitem_slice numba/tests/test_typedlist.py::TestTypedList::test_list_create_no_jit_using_List numba/tests/test_typedlist.py::TestTypedList::test_list_create_no_jit_using_empty_list numba/tests/test_typedlist.py::TestTypedList::test_list_extend_refines_on_unicode_type numba/tests/test_typedlist.py::TestTypedList::test_repr numba/tests/test_typedlist.py::TestTypedList::test_setitem_slice numba/tests/test_typedlist.py::TestTypedList::test_setitem_slice_value_error numba/tests/test_typedlist.py::TestTypedList::test_unsigned_access numba/tests/test_typedlist.py::TestTypedList::test_unsigned_prange numba/tests/test_typedlist.py::TestNoneType::test_append_none numba/tests/test_typedlist.py::TestNoneType::test_equals_none numba/tests/test_typedlist.py::TestNoneType::test_getitem_none numba/tests/test_typedlist.py::TestNoneType::test_iter_none numba/tests/test_typedlist.py::TestNoneType::test_len_none numba/tests/test_typedlist.py::TestNoneType::test_none_typed_method_fails numba/tests/test_typedlist.py::TestNoneType::test_not_equals_none numba/tests/test_typedlist.py::TestNoneType::test_setitem_none numba/tests/test_typedlist.py::TestAllocation::test_allocation numba/tests/test_typedlist.py::TestAllocation::test_allocation_njit numba/tests/test_typedlist.py::TestAllocation::test_growth_and_shrinkage numba/tests/test_typedlist.py::TestExtend::test_extend_other numba/tests/test_typedlist.py::TestExtend::test_extend_self numba/tests/test_typedlist.py::TestExtend::test_extend_tuple numba/tests/test_typedlist.py::TestComparisons::test_empty_vs_empty numba/tests/test_typedlist.py::TestComparisons::test_empty_vs_singleton numba/tests/test_typedlist.py::TestComparisons::test_equal numba/tests/test_typedlist.py::TestComparisons::test_equals_non_list numba/tests/test_typedlist.py::TestComparisons::test_first_greater_than numba/tests/test_typedlist.py::TestComparisons::test_first_less_than numba/tests/test_typedlist.py::TestComparisons::test_first_shorter numba/tests/test_typedlist.py::TestComparisons::test_second_shorter numba/tests/test_typedlist.py::TestComparisons::test_singleton_vs_empty numba/tests/test_typedlist.py::TestComparisons::test_singleton_vs_singleton_equal numba/tests/test_typedlist.py::TestComparisons::test_singleton_vs_singleton_greater_than numba/tests/test_typedlist.py::TestComparisons::test_singleton_vs_singleton_less_than numba/tests/test_typedlist.py::TestListInferred::test_refine_extend_list numba/tests/test_typedlist.py::TestListInferred::test_refine_extend_set numba/tests/test_typedlist.py::TestListInferred::test_refine_list_extend_iter numba/tests/test_typedlist.py::TestListInferred::test_simple_refine_append numba/tests/test_typedlist.py::TestListInferred::test_simple_refine_insert numba/tests/test_typedlist.py::TestListRefctTypes::test_array_as_item_in_list numba/tests/test_typedlist.py::TestListRefctTypes::test_dict_as_item_in_list numba/tests/test_typedlist.py::TestListRefctTypes::test_dict_as_item_in_list_multi_refcount numba/tests/test_typedlist.py::TestListRefctTypes::test_equals_on_list_with_dict_for_equal_lists numba/tests/test_typedlist.py::TestListRefctTypes::test_equals_on_list_with_dict_for_unequal_dicts numba/tests/test_typedlist.py::TestListRefctTypes::test_equals_on_list_with_dict_for_unequal_lists numba/tests/test_typedlist.py::TestListRefctTypes::test_jitclass_as_item_in_list numba/tests/test_typedlist.py::TestListRefctTypes::test_list_as_item_in_list numba/tests/test_typedlist.py::TestListRefctTypes::test_list_as_value_in_dict numba/tests/test_typedlist.py::TestListRefctTypes::test_storage_model_mismatch numba/tests/test_typedlist.py::TestListRefctTypes::test_str_item numba/tests/test_typedlist.py::TestListRefctTypes::test_str_item_refcount_replace numba/tests/test_typedlist.py::TestListSort::test_sort_all_args numba/tests/test_typedlist.py::TestListSort::test_sort_dispatcher_key numba/tests/test_typedlist.py::TestListSort::test_sort_in_jit_w_global_key numba/tests/test_typedlist.py::TestListSort::test_sort_in_jit_w_lambda_key numba/tests/test_typedlist.py::TestListSort::test_sort_no_args numba/tests/test_typedlist.py::TestListSort::test_sort_on_arrays numba/tests/test_typedlist.py::TestImmutable::test_append_fails numba/tests/test_typedlist.py::TestImmutable::test_getitem_still_works_when_immutable numba/tests/test_typedlist.py::TestImmutable::test_is_immutable numba/tests/test_typedlist.py::TestImmutable::test_length_still_works_when_immutable numba/tests/test_typedlist.py::TestImmutable::test_make_immutable_is_immutable numba/tests/test_typedlist.py::TestImmutable::test_mutation_fails numba/tests/test_typedlist.py::TestListFromIter::test_dict_iters numba/tests/test_typedlist.py::TestListFromIter::test_exception_on_inhomogeneous_tuple numba/tests/test_typedlist.py::TestListFromIter::test_exception_on_kwargs numba/tests/test_typedlist.py::TestListFromIter::test_exception_on_plain_int numba/tests/test_typedlist.py::TestListFromIter::test_exception_on_too_many_args numba/tests/test_typedlist.py::TestListFromIter::test_ndarray_oned numba/tests/test_typedlist.py::TestListFromIter::test_ndarray_scalar numba/tests/test_typedlist.py::TestListFromIter::test_ndarray_twod numba/tests/test_typedlist.py::TestListFromIter::test_simple_iterable_types numba/tests/test_typedlist.py::TestListFromIter::test_unicode
numba/typed/typedlist.py numba/core/ssa.py
numba/typed/typedlist.py numba/core/ssa.py