Skip to content

Add noalias/allocsize attributes to GC allocation runtime functions#5154

Draft
kubo39 wants to merge 1 commit into
ldc-developers:masterfrom
kubo39:add-noalias-allocsize-attr-for-allocation-apis
Draft

Add noalias/allocsize attributes to GC allocation runtime functions#5154
kubo39 wants to merge 1 commit into
ldc-developers:masterfrom
kubo39:add-noalias-allocsize-attr-for-allocation-apis

Conversation

@kubo39

@kubo39 kubo39 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Mark the returned pointer of _d_allocmemory, _d_allocmemoryT and _d_newclass/_d_allocclass with noalias, and give _d_allocmemory an allocsize(0).
This helps alias analysis and enables llvm's objectsize-based optimizations.

Mark the returned pointer of _d_allocmemory, _d_allocmemoryT and
_d_newclass/_d_allocclass with noalias, and give _d_allocmemory
an allocsize(0).
This helps alias analysis and enables llvm's objectsize-based
optimizations.
@kubo39 kubo39 marked this pull request as draft June 22, 2026 12:13
@thewilsonator

Copy link
Copy Markdown
Contributor

Looks good,

The following tests FAILED:
	1716 - druntime-test-exceptions-release (Failed)

not sure why though.

@JohanEngelen

Copy link
Copy Markdown
Member

Are we sure this works when doing something like:

new
delete (GC collection)
new
delete (GC collection)
new
delete (GC collection)
new

where all news might actually return the same memory address. Will LLVM's optimizer make the right decisions?

A delete means that we have no references any more to the item, so in D code, the noalias must be correct because any new call will return a pointer that is indeed not aliasing any existing memory reference any more.
However, in the LLVM IR optimizer, this "temporal" connection might be gone after reordering of code. I did not think this through myself yet.

@kubo39

kubo39 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Looks like it's because of SimplifyDRuntimeCalls.

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 this pull request may close these issues.

3 participants