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

simplify reinterpret array code #43955

Merged
merged 1 commit into from
Feb 15, 2022
Merged

simplify reinterpret array code #43955

merged 1 commit into from
Feb 15, 2022

Conversation

vtjnash
Copy link
Sponsor Member

@vtjnash vtjnash commented Jan 27, 2022

This converts most memcpy into a unsafe_load or unsafe_store! (only one, not both), which should avoid at least one alloca in most cases, and hopefully helps LLVM with AA in some of those cases also.

No measurable impact on the internal tests:

Test         (Worker) | Time (s) | GC (s) | GC % | Alloc (MB) | RSS (MB)
PR                (1) |    12.62 |   0.59 |  4.7 |    1764.51 |   394.09
master            (1) |    12.93 |   0.67 |  5.2 |    1805.12 |   391.55

@nanosoldier runbenchmarks("array", vs=":master")

@vtjnash vtjnash requested a review from Keno January 27, 2022 22:07
@tkf
Copy link
Member

tkf commented Jan 28, 2022

Can you comment on how does it interact with TBAA? Doesn't this make Julia less strict even than C wrt aliasing? I don't know how much of Julia's type is passed down to LLVM currently but I wondered if it closes future possibilities. cc @vchuravy

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here.

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Jan 28, 2022

Both memcpy and unsafe calls disable TBAA optimizations. That is sort of the point of these intrinsics, and of reinterpretarray.

@tkf
Copy link
Member

tkf commented Jan 28, 2022

Thanks for the clarification. I didn't know that unsafe_load and unsafe_store! have such semantics.

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Feb 7, 2022

@Keno bump

@oscardssmith
Copy link
Member

What's the status on this? Is it good to merge?

@oscardssmith oscardssmith added the domain:arrays [a, r, r, a, y, s] label Feb 13, 2022
@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Feb 13, 2022

Waiting for Keno's review

@Keno
Copy link
Member

Keno commented Feb 13, 2022

If it passes tests, it's fine by me. The implementation looks like, but LLVM is very fussy about this kind of code, since it depends on the idiom recognition to turn it back into memcpy for performance. If there is a particular motivating case, perhaps that can be turned into a codegen test?

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Feb 14, 2022

Why do we want it to add extra memcpy calls? I thought we wanted it to remove those and turn it back into bitcast. This should just simplify our emitted llvm IR from being load + store + memcpy + load to load + store + load (where the first and last load might actually be emitted as a memcpy, if the value is an FCA)

@Keno
Copy link
Member

Keno commented Feb 14, 2022

Depends how big the struct is that you're copying. For small things, it's just a bitcast of course.

@vtjnash vtjnash merged commit 07f0fdb into master Feb 15, 2022
@vtjnash vtjnash deleted the jn/reinterpretarray-simple branch February 15, 2022 02:00
antoine-levitt pushed a commit to antoine-levitt/julia that referenced this pull request Feb 17, 2022
Avoid one of the memcpy calls, when possible.
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
Avoid one of the memcpy calls, when possible.
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
Avoid one of the memcpy calls, when possible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:arrays [a, r, r, a, y, s]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants