Skip to content

[SYCL] Addrspace cast phi operands when lowering conditional operator #768

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

Merged

Conversation

sndmitriev
Copy link
Contributor

Make sure that all operands of phi instruction that is generated while
lowering conditional operator have the same type. This fixes compiler
assertion.

Signed-off-by: Sergey Dmitriev [email protected]

@sndmitriev sndmitriev requested review from bader and Fznamznon October 29, 2019 04:55
phi->addIncoming(rhs->getPointer(), rhsBlock);
llvm::Value *lhsPtr = lhs->getPointer();
llvm::Value *rhsPtr = rhs->getPointer();
if (rhsPtr->getType() != lhsPtr->getType())
Copy link
Contributor

Choose a reason for hiding this comment

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

JIC, is it guaranteed that rhsPtr/lhsPtr are non-nullptr?

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 think it is. In any case I am not changing behavior with regards to this part. So if it was or was not guaranteed earlier the same behavior remains now.

llvm::Value *lhsPtr = lhs->getPointer();
llvm::Value *rhsPtr = rhs->getPointer();
if (rhsPtr->getType() != lhsPtr->getType())
rhsPtr = Builder.CreatePointerBitCastOrAddrSpaceCast(rhsPtr,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not always legal. If RHS is a local pointer and LHS is a global pointer, the cast is "local->global", which is invalid.
If pointer address spaces are different, the only correct cast is a cast to generic (addrspace 4). Check the #388, where a similar change was made around select instruction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added casts to generic address space as needed.

@sndmitriev sndmitriev force-pushed the public/sndmitriev/addrspace-cond-op branch from 0bb9032 to c34fbc6 Compare October 30, 2019 14:33
asavonic
asavonic previously approved these changes Oct 30, 2019
Copy link
Contributor

@asavonic asavonic left a comment

Choose a reason for hiding this comment

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

LGTM overall. See a couple of code-style suggestions below.

llvm::Value *rhsPtr = rhs->getPointer();
if (rhsPtr->getType() != lhsPtr->getType()) {
if (getLangOpts().SYCLIsDevice) {
auto CastToAS = [](llvm::Value *V, llvm::BasicBlock *BB, unsigned AS) {
Copy link
Contributor

Choose a reason for hiding this comment

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

insertAddressSpaceCast from #388 seems to do exactly the same, and IIRC, this will be a third place where we need it. Can you use it here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

insertAddressSpaceCast from #388 uses some assumptions which I believe are not legal here. For example on line 4155 the input value V is casted to Instruction. I do not think we can guarantee that lhsPtr or rhsPtr here is an Instruction.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Well, you can refactor that function to take an insertion point, but this is a minor problem, so feel free to ignore it if you don't think that it worth the effort.

Make sure that all operands of phi instruction that is generated while
lowering conditional operator have the same type. This fixes compiler
assertion.

Signed-off-by: Sergey Dmitriev <[email protected]>
@sndmitriev
Copy link
Contributor Author

If there are no more comments can someone please approve this PR?

@bader bader requested review from AGindinson and asavonic November 5, 2019 16:38
@romanovvlad romanovvlad merged commit a47242e into intel:sycl Nov 6, 2019
vmaksimo pushed a commit to vmaksimo/llvm that referenced this pull request Oct 12, 2020
* Add ReadNone attr for Builtin functions

Signed-off-by: Aleksander Fadeev <[email protected]>
@sndmitriev sndmitriev deleted the public/sndmitriev/addrspace-cond-op branch December 22, 2020 02:39
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.

5 participants