-
Notifications
You must be signed in to change notification settings - Fork 768
[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
[SYCL] Addrspace cast phi operands when lowering conditional operator #768
Conversation
clang/lib/CodeGen/CGExpr.cpp
Outdated
phi->addIncoming(rhs->getPointer(), rhsBlock); | ||
llvm::Value *lhsPtr = lhs->getPointer(); | ||
llvm::Value *rhsPtr = rhs->getPointer(); | ||
if (rhsPtr->getType() != lhsPtr->getType()) |
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.
JIC, is it guaranteed that rhsPtr
/lhsPtr
are non-nullptr
?
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 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.
clang/lib/CodeGen/CGExpr.cpp
Outdated
llvm::Value *lhsPtr = lhs->getPointer(); | ||
llvm::Value *rhsPtr = rhs->getPointer(); | ||
if (rhsPtr->getType() != lhsPtr->getType()) | ||
rhsPtr = Builder.CreatePointerBitCastOrAddrSpaceCast(rhsPtr, |
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.
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.
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.
Added casts to generic address space as needed.
0bb9032
to
c34fbc6
Compare
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.
LGTM overall. See a couple of code-style suggestions below.
clang/lib/CodeGen/CGExpr.cpp
Outdated
llvm::Value *rhsPtr = rhs->getPointer(); | ||
if (rhsPtr->getType() != lhsPtr->getType()) { | ||
if (getLangOpts().SYCLIsDevice) { | ||
auto CastToAS = [](llvm::Value *V, llvm::BasicBlock *BB, unsigned AS) { |
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.
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?
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.
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
.
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 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]>
c34fbc6
to
c9d6415
Compare
If there are no more comments can someone please approve this PR? |
* Add ReadNone attr for Builtin functions Signed-off-by: Aleksander Fadeev <[email protected]>
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]