Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A concrete case for potential ref-pruning chances #1044

Open
dlee992 opened this issue Apr 29, 2024 · 0 comments · May be fixed by #1045
Open

A concrete case for potential ref-pruning chances #1044

dlee992 opened this issue Apr 29, 2024 · 0 comments · May be fixed by #1045

Comments

@dlee992
Copy link
Contributor

dlee992 commented Apr 29, 2024

code of typed.List's get_item:

@overload(operator.getitem)
def impl_getitem(l, index):
    ...
    if index in index_types:
        if IS_NOT_NONE:
            def integer_non_none_impl(l, index):
                castedindex = _cast(index, indexty)
                handledindex = handle_index(l, castedindex)
                status, item = _list_getitem(l, handledindex)
                if status == ListStatus.LIST_OK:
                    return _nonoptional(item)
                else:
                    raise AssertionError("internal list error during getitem")
            return integer_non_none_impl

IR of integer_non_none_impl:

entry:
  tail call void @NRT_incref(i8* %arg.l.0)
  tail call void @NRT_incref(i8* %arg.l.0), !noalias !22
  ...
  br i1 %.27.i, label %B0.if, label %B20.endif.i

B20.endif.i:                                      ; preds = %entry
  ...
  tail call void @NRT_decref(i8* %arg.l.0), !noalias !22
  ...
  br i1 %.60.not.i, label %B46.endif, label %B0.if

common.ret:                                       ; preds = %B46.endif, %B0.if
  %common.ret.op = phi i32 [ 0, %B46.endif ], [ 1, %B0.if ]
  ret i32 %common.ret.op

B0.if:                                            ; preds = %B20.endif.i, %entry
  %l.sroa.0.0.i = phi i8* [ %arg.l.0, %entry ], [ null, %B20.endif.i ]
  tail call void @NRT_decref(i8* %l.sroa.0.0.i), !noalias !22
  store ..., ... %excinfo, align 8, !numba_exception_output !13
  br label %common.ret

B46.endif:                                        ; preds = %B20.endif.i
  ...
  tail call void @NRT_decref(i8* %arg.l.0)
  ...
  br label %common.ret

Ideally, we should remove all refcount calls of %arg.l.0 and %l.sroa.0.0.i, since %l.sroa.0.0.i is null or %arg.l.0.
However, current ref-pruning algorithm can't remove any of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant