def _fix_redvar_name_ssa_mismatch(parfor, lowerer, inst, redvar_name):
    """Fix reduction variable name mismatch due to SSA.
    """
    # Only process reduction statements post-gufunc execution
    # until we see an assignment with a left-hand side to the
    # reduction variable's name.  This fixes problems with
    # cases where there are multiple assignments to the
    # reduction variable in the parfor.
    scope = parfor.init_block.scope
    if isinstance(inst, ir.Assign):
        try:
            reduction_var = scope.get_exact(redvar_name)
        except NotDefinedError:
            # Ideally, this shouldn't happen. The redvar name
            # missing from scope indicates an error from
            # other rewrite passes.
            is_same_source_var = redvar_name == inst.target.name
        else:
            # Because of SSA, the redvar and target var of
            # the current assignment would be different even
            # though they refer to the same source-level var.
            redvar_unver_name = reduction_var.unversioned_name
            target_unver_name = inst.target.unversioned_name
            is_same_source_var = redvar_unver_name == target_unver_name

        if is_same_source_var:
            # If redvar is different from target var, add an
            # assignment to put target var into redvar.
            if redvar_name != inst.target.name:
                val = lowerer.loadvar(inst.target.name)
                lowerer.storevar(val, name=redvar_name)
                return True

    return False
Fix reduction variable name mismatch due to SSA.
    
numba/parfors/parfor_lowering.py