-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add a special GC AS for array ptrs #28251
Conversation
Bugpointed test case for the LLVM bug:
|
Introduced by the vectorizer:
|
loop-vectorize only test case:
|
Filed upstream as https://bugs.llvm.org/show_bug.cgi?id=38290 |
Candidate patch:
|
Looks like there's another issue in loop-reduce. Bugpoint reduction:
|
Loop reduce bug looks fixed on upstream master. I'll bisect to find the relevant commit |
The commit that fixes LSR is:
|
Ok, everything builds and passes with those two patches. I'll go ahead and do those patches as a separate PR for ease of integration. |
MDNode *tbaa = arraytype_constshape(tinfo.typ) ? tbaa_const : tbaa_arrayptr; | ||
PointerType *PT = cast<PointerType>(addr->getType()); | ||
PointerType *PPT = cast<PointerType>(PT->getElementType()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addr->getResultElementType()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need the reference to PT anyway, so I think this is fine.
src/llvm-late-gc-lowering.cpp
Outdated
if (auto PtrT = dyn_cast<PointerType>(LI->getType())) { | ||
if (PtrT->getAddressSpace() == AddressSpace::Loaded) { | ||
CurrentV = LI->getPointerOperand(); | ||
if (getValueAddrSpace(CurrentV) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be if (!isSpecialPtr(getValueAddrSpace(CurrentV)))
, or is the idea that we only want to allow the base pointer to be either Tracked or None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really have non-gc address spaces in a target that can do GC, so I don't think it matters too much, but I'll change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they support having code in the gc address space, as long as it eventually (after optimizations) doesn't end up in the final code. I think only maleadt would know if this makes a difference here, so I'm probably just being overly conservative.
doc/src/devdocs/llvm.md
Outdated
@@ -211,6 +211,11 @@ three different address spaces (their numbers are defined in `src/codegen_shared | |||
future), but unlike the other pointers need not be rooted if passed to a | |||
call (they do still need to be rooted if they are live across another safepoint | |||
between the definition and the call). | |||
- Pointers loaded from tracked object (currently 13): This is used by arrays, | |||
which themselves contain a data to the managed data. This data area is owned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"a pointer to"
First patch is submitted upstream as https://reviews.llvm.org/D49832. |
Committed upstream as https://reviews.llvm.org/rL338072 / https://reviews.llvm.org/rL338073, but we can keep the D49832 version. It's functionally equivalent. |
The array data pointer is somewhat special. It points to a chunk for memory that is effectively managed by the GC, but is not itself a GC-tracked value. However, it is also not quite an interior pointer into the array, since it may be an external allocation (or at the more immediate IR level it is derived using a load rather than a gep). We could try to make Derived do both, but the semantics turn out to be rather different, so add a new kind of AS `Loaded`, that handles precisely this situation: It roots the object that it was loaded from while it is live. Fixes #27955
The array data pointer is somewhat special. It points to a chunk for memory that is effectively managed by the GC, but is not itself a GC-tracked value. However, it is also not quite an interior pointer into the array, since it may be an external allocation (or at the more immediate IR level it is derived using a load rather than a gep). We could try to make Derived do both, but the semantics turn out to be rather different, so add a new kind of AS `Loaded`, that handles precisely this situation: It roots the object that it was loaded from while it is live. Fixes #27955
The array data pointer is somewhat special. It points to a chunk
for memory that is effectively managed by the GC, but is not itself
a GC-tracked value. However, it is also not quite an interior pointer
into the array, since it may be an external allocation (or at the
more immediate IR level it is derived using a load rather than
a gep). We could try to make Derived do both, but the semantics
turn out to be rather different, so add a new kind of AS
Loaded
,that handles precisely this situation: It roots the object that it
was loaded from while it is live.
Fixes #27955
Current status: Seems to fix the issue, but seems to trigger LLVM bugs (optimizations introducing illegal ptrtoint).