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

Fix reverse translation of OpPtrDiff with untyped pointers #2858

Merged
merged 2 commits into from
Nov 28, 2024

Conversation

vmaksimo
Copy link
Contributor

@vmaksimo vmaksimo commented Nov 13, 2024

We should not lose operand type when SPV_KHR_untyped_pointers is used.

Type *ElemTy = nullptr;
// Should we better get the type info from alloca instruction or from the
// OpUntypedVariableKHR DataType field?
if (auto *AI = dyn_cast<AllocaInst>(Operand1))
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if we remove this if, leaving only else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll get:
ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64)
instead of this on the line 49 of the test:
ptrtoint (ptr getelementptr (float, ptr null, i32 1) to i64)

Copy link
Contributor

@MrSidims MrSidims Nov 20, 2024

Choose a reason for hiding this comment

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

I was wondering, if the pointers we compare by ptrdiif come not from an alloca instructions, but from operand of a function. In this case the type can be restored by looking at accessing it loads/stores or may be demangling the function. I'm not asking to do such analysis here, but lets say we have the worst case scenario and we can't do anything to restore the type. In this case shouldn't we get ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to i64) instead of ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64)?

Copy link
Contributor

Choose a reason for hiding this comment

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

May be resolving this can go to a different patch. This patch already improves the code base.

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 see, I believe it'd be a good idea to unify this piece of code https://github.com/KhronosGroup/SPIRV-LLVM-Translator/pull/2857/files#diff-7990d99acb2f8325d245dfecdab758eae5aebae2b54c04fd8e906212eb80ae10R3463-R3473 to be used in every place where we use untyped instructions to restore correct type.

@MrSidims MrSidims requested a review from svenvh November 21, 2024 09:00
Value *Operand1 = Ops[0]->stripPointerCasts();

Type *ElemTy = nullptr;
// Should we better get the type info from alloca instruction or from the
Copy link
Contributor

@MrSidims MrSidims Nov 21, 2024

Choose a reason for hiding this comment

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

Both is fine IMO. May be it would be more clean to get it from OpUntypedVariableKHR as we are in SPIR-V consumer part of the translator. Please don't forget to remove the comment.

@MrSidims MrSidims merged commit 926a92a into KhronosGroup:main Nov 28, 2024
9 checks passed
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