You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ensure type annotations are added for reference returning intrinsics/operators #5357
If an intrinsic returns a reference to a new object or UDT that isn't guaranteed to have already been annotated by some other means, the current code fails to add a type annotation for this type (if it is used without being assigned/copied to a temporary variable first). If a non-reference type is added, the type annotation gets added during EmitAutoVarAlloca.
At present, it's unclear where this has impact. The order of operations here should be to find what else this type annotation gap might impact, write a test for that, and fix it.
Chris B (@llvm-beanz) I thought the issue was that the subscript operator for NodeOutputArray was defined as `T& operator versus T operator. That is not the case, it does return a value:
Also, #5357 requires adding type annotations to reference types returned by intrinsics, with that in place, should this be changed to return a reference, consistent with the other HLSL types.
Tex Riddell (@tex3d) may need to weigh in here. I know that I authored the public version of this issue, but Tex authored the original internal issue (111).
Tex had an internal comment:
The annotation may be missing because our code paths that add it aren't triggered for the an intermediate NodeOutput object in some cases, for example myNodeOutputArray[i] won't get a type annotation added because there's no explicit intermediate variable, because the operator[] returns a reference:
Now, operator[] shouldn't return a reference in this case (which is one part of a fix, but I think that one wasn't trivial), and we also need to cover the reference case for adding the type annotation anyway.
We may just need testing to verify that these cases are correctly handled by the code in CGHLSLMSFinishCodeGen.cpp that creates node record handle annotations.
The issue was detected when the NodeOutputArray subscript operator returned a reference to a NodeOutput object, which was not correct. For returning the record struct itself (not the object), like what Get() and the Node*OutputRecords subscript operators return, these should be a reference. But when returning an object (handle), it should be a value (the object is synthesized, not pre-existing and referenced).
Now, the subscript operator was fixed, but the bug that can lead to a missing type annotation remains which might impact some other operator that returns a reference.
That's the issue: find what else this type annotation gap might impact, write a test for that, and fix it.
To be clear, this no longer impacts the same work graph case, it might impact some other pre-existing scenario, it isn't a regression, therefore shouldn't be considered an SM 6.8 issue.
In light of the above, this is an existing issue that was not introduced by 6.8 work nor does it impact any 6.8 features insofar as we are aware. As such, I'll be dropping this from the sm6.8 milestone.
Chris B (@llvm-beanz) I thought the issue was that the subscript operator for NodeOutputArray was defined as `T& operator versus T operator. That is not the case, it does return a value:
Also, #5357 requires adding type annotations to reference types returned by intrinsics, with that in place, should this be changed to return a reference, consistent with the other HLSL types.
To directly answer this question: this operator is now correct.
It should return a value, since it's not returning a reference to an existent thing elsewhere, instead it's synthesizing a handle that refers to a particular output slot. The references you see for other subscript operators are returning references to data in a buffer or other existent things, which are meant to be read and/or modified directly.
This particular issue was just about the possibility of a missing type annotation which might occur elsewhere. It should be explored, but it's also possible that the issue is not reachable at this time.
Tex Riddell (@tex3d)
Thank you for the details. I went back to the original change that added the subscript operator for NodeOutputArray types and it returns a value and not a reference, that part of the code hasn't changed. It works now because we added a recordSizeWAR code in AddOpcodeParamForIntrinsic function in CGHLSLMSFinishCodeGen.cpp. Without the workaround, we see failures from missing type annotation like before. I can leave this assigned to myself and work on it in a few weeks if you think that this fix is not critical for the SM6.8 release.
Tex Riddell (@tex3d) Thank you for the details. I went back to the original change that added the subscript operator for NodeOutputArray types and it returns a value and not a reference, that part of the code hasn't changed. It works now because we added a recordSizeWAR code in AddOpcodeParamForIntrinsic function in CGHLSLMSFinishCodeGen.cpp. Without the workaround, we see failures from missing type annotation like before. I can leave this assigned to myself and work on it in a few weeks if you think that this fix is not critical for the SM6.8 release.
I thought there was some intermediate version (may never have been merged) that returned a reference which I was debugging around the time I filed the original issue. I distinctly remember that in codegen, direct use of the reference return value of the subscript operator would not generate the temp, so it wouldn't add the type annotation, while an intermediate object returned from the operator would generate a temp (RValue), which caused the type annotation to be added. I remember being able to work around the issue by assigning the result from the subscript operator to a local temp variable, then using the temp variable instead. Perhaps there's another interacting factor here as well. Oh well...
In any case, I think the missing type annotation issue is a problem, but not one blocking the release at the moment. So, I think your suggestion to keep it assigned to yourself and work on it in a few weeks would be fine.
Anupama Chandrasekhar (@anupamachandra)
I put up a draft PR that adds missing type annotations by iterating methods on node objects, as well as making sure that any Type template parameter for something we are adding template argument annotation for will also have a type annotation added.
Tex Riddell (@tex3d) Thank you for the details. I went back to the original change that added the subscript operator for NodeOutputArray types and it returns a value and not a reference, that part of the code hasn't changed. It works now because we added a recordSizeWAR code in AddOpcodeParamForIntrinsic function in CGHLSLMSFinishCodeGen.cpp. Without the workaround, we see failures from missing type annotation like before. I can leave this assigned to myself and work on it in a few weeks if you think that this fix is not critical for the SM6.8 release.
I thought there was some intermediate version (may never have been merged) that returned a reference which I was debugging around the time I filed the original issue. I distinctly remember that in codegen, direct use of the reference return value of the subscript operator would not generate the temp, so it wouldn't add the type annotation, while an intermediate object returned from the operator would generate a temp (RValue), which caused the type annotation to be added. I remember being able to work around the issue by assigning the result from the subscript operator to a local temp variable, then using the temp variable instead. Perhaps there's another interacting factor here as well. Oh well...
In any case, I think the missing type annotation issue is a problem, but not one blocking the release at the moment. So, I think your suggestion to keep it assigned to yourself and work on it in a few weeks would be fine.
Tex Riddell (@tex3d) you are right, the original PR had the subscript operator returning a reference that was fixed with using a temp which invoked the AddTypeAnnotation path in EmitAutoVar. I had fixed the subsctript operator return but the underlying issue remained. Thanks for the fix, I'll take a look at it.
Activity
pow2clk commentedon Oct 23, 2023
Anupama Chandrasekhar (@anupamachandra), do you think your work on #5358 is going to overlap with this?
anupamachandra commentedon Oct 24, 2023
Yes, I believe so.
anupamachandra commentedon Jan 22, 2024
Chris B (@llvm-beanz) I thought the issue was that the subscript operator for NodeOutputArray was defined as `T& operator versus T operator. That is not the case, it does return a value:
Also, #5357 requires adding type annotations to reference types returned by intrinsics, with that in place, should this be changed to return a reference, consistent with the other HLSL types.
llvm-beanz commentedon Jan 24, 2024
Tex Riddell (@tex3d) may need to weigh in here. I know that I authored the public version of this issue, but Tex authored the original internal issue (111).
Tex had an internal comment:
We may just need testing to verify that these cases are correctly handled by the code in CGHLSLMSFinishCodeGen.cpp that creates node record handle annotations.
Tex Riddell (@tex3d) thoughts?
tex3d commentedon Jan 24, 2024
The issue was detected when the NodeOutputArray subscript operator returned a reference to a NodeOutput object, which was not correct. For returning the record struct itself (not the object), like what Get() and the
Node*OutputRecordssubscript operators return, these should be a reference. But when returning an object (handle), it should be a value (the object is synthesized, not pre-existing and referenced).Now, the subscript operator was fixed, but the bug that can lead to a missing type annotation remains which might impact some other operator that returns a reference.
That's the issue: find what else this type annotation gap might impact, write a test for that, and fix it.
tex3d commentedon Jan 24, 2024
To be clear, this no longer impacts the same work graph case, it might impact some other pre-existing scenario, it isn't a regression, therefore shouldn't be considered an SM 6.8 issue.
pow2clk commentedon Jan 24, 2024
In light of the above, this is an existing issue that was not introduced by 6.8 work nor does it impact any 6.8 features insofar as we are aware. As such, I'll be dropping this from the sm6.8 milestone.
3 remaining items
tex3d commentedon Jan 24, 2024
Anupama Chandrasekhar (@anupamachandra)
To directly answer this question: this operator is now correct.
It should return a value, since it's not returning a reference to an existent thing elsewhere, instead it's synthesizing a handle that refers to a particular output slot. The references you see for other subscript operators are returning references to data in a buffer or other existent things, which are meant to be read and/or modified directly.
This particular issue was just about the possibility of a missing type annotation which might occur elsewhere. It should be explored, but it's also possible that the issue is not reachable at this time.
anupamachandra commentedon Jan 30, 2024
Tex Riddell (@tex3d)
Thank you for the details. I went back to the original change that added the subscript operator for NodeOutputArray types and it returns a value and not a reference, that part of the code hasn't changed. It works now because we added a recordSizeWAR code in
AddOpcodeParamForIntrinsicfunction in CGHLSLMSFinishCodeGen.cpp. Without the workaround, we see failures from missing type annotation like before. I can leave this assigned to myself and work on it in a few weeks if you think that this fix is not critical for the SM6.8 release.tex3d commentedon Jan 31, 2024
I thought there was some intermediate version (may never have been merged) that returned a reference which I was debugging around the time I filed the original issue. I distinctly remember that in codegen, direct use of the reference return value of the subscript operator would not generate the temp, so it wouldn't add the type annotation, while an intermediate object returned from the operator would generate a temp (RValue), which caused the type annotation to be added. I remember being able to work around the issue by assigning the result from the subscript operator to a local temp variable, then using the temp variable instead. Perhaps there's another interacting factor here as well. Oh well...
In any case, I think the missing type annotation issue is a problem, but not one blocking the release at the moment. So, I think your suggestion to keep it assigned to yourself and work on it in a few weeks would be fine.
tex3d commentedon Jan 31, 2024
Dang, it looks like type annotations are still not added for these subscript operators when they return values as well.
I was able to crash the current code due to a missing annotation still with this:
tex3d commentedon Jan 31, 2024
Anupama Chandrasekhar (@anupamachandra)
I put up a draft PR that adds missing type annotations by iterating methods on node objects, as well as making sure that any
Typetemplate parameter for something we are adding template argument annotation for will also have a type annotation added.anupamachandra commentedon Jan 31, 2024
Tex Riddell (@tex3d) you are right, the original PR had the subscript operator returning a reference that was fixed with using a temp which invoked the
AddTypeAnnotationpath inEmitAutoVar. I had fixed the subsctript operator return but the underlying issue remained. Thanks for the fix, I'll take a look at it.