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

Emit OpMemberDecorate for member 0 annotations #1646

Merged
merged 2 commits into from Oct 14, 2022

Conversation

dwoodwor-intel
Copy link
Contributor

@dwoodwor-intel dwoodwor-intel commented Oct 13, 2022

LLVMToSPIRVBase::transIntrinsicInst translates ptr.annotation intrinsics marking struct members by looking for struct GEPs. However, a GEPs is not necessary for the first member, and so in some cases when the first member is annotated SPIRVWriter has been emitting OpDecorate for these instead which leads to a crash in some cases on reverse translation. This change enables emitting OpMemberDecorate for the first member even if there isn't a GEP and the pointer value is based on a struct alloca instead.

This change also moves the handling of FPGARegIntel annotations so that they're translated to OpFPGARegINTEL before attempting to translate struct member annotations. This ensures that they don't get incorrectly translated with OpMemberDecorate.

LLVMToSPIRVBase::transIntrinsicInst translates ptr.annotation intrinsics
marking struct members by looking for struct GEPs. However, a GEPs is not
necessary for the first member, and so in some cases when the first
member is annotated SPIRVWriter has been emitting OpDecorate for these
instead which leads to a crash in some cases on reverse translation.
This change enables emitting OpMemberDecorate for the first member even
if there isn't a GEP and the pointer value is based on a struct alloca
instead.
@dwoodwor-intel
Copy link
Contributor Author

This is another approach to the problem in #1635 which seems to be a more proper fix

Copy link
Contributor

@MrSidims MrSidims left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM just one nit

lib/SPIRV/SPIRVWriter.cpp Outdated Show resolved Hide resolved
@MrSidims
Copy link
Contributor

@asudarsa @vmaksimo could you please also take a look?

@@ -3745,15 +3745,38 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
AnnotationDecorations Decorations =
tryParseAnnotationString(BM, AnnotationString);

// Translate FPGARegIntel annotations to OpFPGARegINTEL.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems to be unrelated to the issue being addressed. Can you please comment? Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was something I discovered when running the tests: there are a few cases where this FPGARegIntel annotation is used on struct values, and my change was incorrectly trying to translate those as OpMemberDecorate instead. It seems like in cases where we have an FPGARegIntel annotation we want to translate it to OpFPGARegINTEL regardless of whether we find a struct type, so I thought the cleanest way of doing that would be moving this check up here.

@vmaksimo, from the git log it looks like you originally added this code; is putting it here correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dwoodwor-intel Oh, that has been some long time ago, and I missed a big part of changes related to this feature transformation :)

But I do think that now it's a correct place - it looks logical and has not failed any tests.

addAnnotationDecorations(DecSubj, Decorations.MemoryAccessesVec);
II->replaceAllUsesWith(II->getOperand(0));
}
// Memory accesses to a standalone pointer variable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please specify if the scope of this change goes beyond addressing the first member of the struct variable? This change also seems unrelated. Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just removed the OpFPGARegINTEL code from here; the rest of the changes in this part are just formatting

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks

Copy link
Contributor

@MrSidims MrSidims left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI issues don't relate with the patch
Checking them

Copy link
Contributor

@asudarsa asudarsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please validate SPIR-V generated using spirv-val. Thanks

@dwoodwor-intel
Copy link
Contributor Author

LGTM. Please validate SPIR-V generated using spirv-val. Thanks

I ran spirv-val on this test and did find an error:

$ spirv-val annotate_attribute.spv
error: line 236: Variables can not have a function[7] storage class outside of a function
  %_str = OpVariable %_ptr_Function__arr_uchar_ulong_3 Function %9

I also tried without this change on the main branch and I see the same error there too. It seems to be a preexisting issue unrelated to this change.

@MrSidims
Copy link
Contributor

llvm-bolt is a known issue reported in llvm/llvm-project#58317 and several other places. Merging.

@MrSidims MrSidims merged commit d071672 into KhronosGroup:main Oct 14, 2022
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.

None yet

4 participants