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

Improve allocation optimization with gc_preserve intrinsics #24416

Merged
merged 1 commit into from
Nov 1, 2017

Conversation

yuyichao
Copy link
Contributor

Delete them directly so that they don't mess up LLVM optimizations.

@yuyichao yuyichao added the compiler:codegen Generation of LLVM IR and native code label Oct 31, 2017
Delete them directly so that they don't mess up LLVM optimizations.
@yuyichao yuyichao merged commit a62ca27 into master Nov 1, 2017
@yuyichao yuyichao deleted the yyc/codegen/alloc branch November 1, 2017 02:27
@maleadt
Copy link
Member

maleadt commented Nov 6, 2017

I think this broke (or at least changed behavior) of multi-arg @gc_preserve as used in CUDAdrv:

function foobar(a, b)
    a_ref = Base.RefValue(a)
    b_ref = Base.RefValue(b)

    a_ptr = Base.unsafe_convert(Ptr{Void}, a_ref)
    b_ptr = Base.unsafe_convert(Ptr{Void}, b_ref)

    ptrs = [a_ptr, b_ptr]
    Base.@gc_preserve a_ref b_ref ptrs

    ccall(:whatever, Cint, (Ptr{Ptr{Void}},), ptrs)
end

const a = [1]
const b = [2]

foobar(pointer(a), pointer(b))
@code_llvm foobar(pointer(a), pointer(b))

Before merging this, both lifetime.ends are together near the end of the function, while now one lifetime is ended much sooner. The old behavior can be restored by using one @gc_preserve for each argument (a_ref and b_ref). Or am I misusing the intrinsic?

@yuyichao
Copy link
Contributor Author

yuyichao commented Nov 6, 2017

#24475

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants