-
Notifications
You must be signed in to change notification settings - Fork 37
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
DRAFT: Fix for spir-v implicit address space cast #651
Open
coldav
wants to merge
3
commits into
uxlfoundation:main
Choose a base branch
from
coldav:colin/fix_spirv_addspacecast
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+129
−5
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
modules/compiler/spirv-ll/test/spvasm/op_sycl_addrspacecast_bitcast.spvasm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
; Copyright (C) Codeplay Software Limited | ||
; | ||
; Licensed under the Apache License, Version 2.0 (the "License") with LLVM | ||
; Exceptions; you may not use this file except in compliance with the License. | ||
; You may obtain a copy of the License at | ||
; | ||
; https://github.com/codeplaysoftware/oneapi-construction-kit/blob/main/LICENSE.txt | ||
; | ||
; Unless required by applicable law or agreed to in writing, software | ||
; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
; License for the specific language governing permissions and limitations | ||
; under the License. | ||
; | ||
; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
; RUN: %if online-spirv-as %{ spirv-as --target-env %spv_tgt_env -o %spv_file_s %s %} | ||
; RUN: %if online-spirv-as %{ spirv-val %spv_file_s %} | ||
; RUN: spirv-ll-tool -a OpenCL -b 64 -c GenericPointer -e SPV_KHR_linkonce_odr %spv_file_s | FileCheck %s | ||
|
||
OpCapability Addresses | ||
OpCapability Linkage | ||
OpCapability Kernel | ||
OpCapability Int64 | ||
OpCapability GenericPointer | ||
OpCapability Int8 | ||
OpExtension "SPV_KHR_linkonce_odr" | ||
%1 = OpExtInstImport "OpenCL.std" | ||
OpMemoryModel Physical64 OpenCL | ||
OpName %__spirv_BuiltInLocalInvocationId "__spirv_BuiltInLocalInvocationId" | ||
OpName %_Z27__spirv_LocalInvocationId_zv "_Z27__spirv_LocalInvocationId_zv" | ||
OpName %_Z28__spirv_GlobalInvocationId_xv "_Z28__spirv_GlobalInvocationId_xv" | ||
|
||
OpDecorate %__spirv_BuiltInLocalInvocationId LinkageAttributes "__spirv_BuiltInLocalInvocationId" Import | ||
OpDecorate %__spirv_BuiltInLocalInvocationId Constant | ||
OpDecorate %__spirv_BuiltInLocalInvocationId BuiltIn LocalInvocationId | ||
OpDecorate %__spirv_BuiltInLocalInvocationId Alignment 32 | ||
|
||
OpDecorate %__spirv_BuiltInGlobalInvocationId LinkageAttributes "__spirv_BuiltInGlobalInvocationId" Import | ||
OpDecorate %__spirv_BuiltInGlobalInvocationId Constant | ||
OpDecorate %__spirv_BuiltInGlobalInvocationId BuiltIn GlobalInvocationId | ||
OpDecorate %__spirv_BuiltInGlobalInvocationId Alignment 32 | ||
|
||
|
||
OpName %_useLocalInvocationId "_useLocalInvocationId" | ||
OpName %_useGlobalInvocationId "_useGlobalInvocationId" | ||
|
||
%ulong = OpTypeInt 64 0 | ||
%ulong_16 = OpConstant %ulong 16 | ||
%uchar = OpTypeInt 8 0 | ||
%uint = OpTypeInt 32 0 | ||
%v3ulong = OpTypeVector %ulong 3 | ||
%_ptr_CrossWorkgroup_v3ulong = OpTypePointer CrossWorkgroup %v3ulong | ||
%void = OpTypeVoid | ||
%_ptr_CrossWorkgroup_uchar = OpTypePointer CrossWorkgroup %uchar | ||
%574 = OpTypeFunction %ulong | ||
%575 = OpTypeFunction %ulong | ||
%403 = OpTypeFunction %ulong | ||
%_ptr_CrossWorkgroup_ulong = OpTypePointer CrossWorkgroup %ulong | ||
%__spirv_BuiltInLocalInvocationId = OpVariable %_ptr_CrossWorkgroup_v3ulong CrossWorkgroup | ||
%__spirv_BuiltInGlobalInvocationId = OpVariable %_ptr_CrossWorkgroup_v3ulong CrossWorkgroup | ||
|
||
OpDecorate %__spirv_BuiltInGlobalInvocationId LinkageAttributes "__spirv_BuiltInGlobalInvocationId" Import | ||
OpDecorate %__spirv_BuiltInGlobalInvocationId Constant | ||
OpDecorate %__spirv_BuiltInGlobalInvocationId BuiltIn GlobalInvocationId | ||
OpDecorate %__spirv_BuiltInGlobalInvocationId Alignment 32 | ||
|
||
; CHECK: call spir_func i64 @_Z12get_local_idj | ||
; CHECK: call spir_func i64 @_Z27__spirv_LocalInvocationId_zv | ||
|
||
%_Z27__spirv_LocalInvocationId_zv = OpFunction %ulong None %574 | ||
%entry_11 = OpLabel | ||
%623 = OpBitcast %_ptr_CrossWorkgroup_uchar %__spirv_BuiltInLocalInvocationId | ||
%624 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uchar %623 %ulong_16 | ||
%625 = OpBitcast %_ptr_CrossWorkgroup_ulong %624 | ||
%626 = OpLoad %ulong %625 Aligned 16 | ||
OpReturnValue %626 | ||
OpFunctionEnd | ||
|
||
%_Z28__spirv_GlobalInvocationId_xv = OpFunction %ulong None %574 | ||
%entry_6 = OpLabel | ||
%602 = OpBitcast %_ptr_CrossWorkgroup_ulong %__spirv_BuiltInGlobalInvocationId | ||
%603 = OpLoad %ulong %602 Aligned 32 | ||
OpReturnValue %603 | ||
OpFunctionEnd | ||
|
||
|
||
;%_useLocalInvocationId = OpFunction %void None %403 | ||
; %entry_10 = OpLabel | ||
; %call5 = OpFunctionCall %ulong %_Z27__spirv_LocalInvocationId_zv | ||
; OpReturnValue %call5 | ||
; OpFunctionEnd | ||
; | ||
;%_useGlobalInvocationId = OpFunction %void None %403 | ||
; %entry_12 = OpLabel | ||
; %call6 = OpFunctionCall %ulong %_Z28__spirv_GlobalInvocationId_xv | ||
; OpReturnValue %call6 | ||
; OpFunctionEnd | ||
|
||
;%_Z27__spirv_LocalInvocationId_zv = OpFunction %ulong None %574 | ||
; %entry_11 = OpLabel | ||
; %617 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_ulong %__spirv_BuiltInLocalInvocationId %uint_0 %uint_2 | ||
; %618 = OpLoad %ulong %617 Aligned 16 | ||
; OpReturnValue %618 | ||
; OpFunctionEnd |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The effect of a bitcast is supposed to be that of a store to memory as one type, and a load from the same memory as another type. I could be wrong, but I believe in general an
addrspacecast
is not guaranteed to be bit-pattern-preserving and this could be a wrong translation, unless I am missing a guarantee that we make somewhere that it doesn't matter?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.
https://llvm.org/docs/LangRef.html#addrspacecast-to-instruction "(i.e. casting the result back to the original address space should yield the original bit pattern)." - are you sure it's not reasonable to do this? How else would we get the same effect?
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.
Casting the result back may yield the original bit pattern, but in the different address space it may have a different bit pattern. Also from that link: "It can be a no-op cast or a complex value modification, depending on the target and the address space pair." I'm not sure what the best way to translate this is, one possibility is actually doing an
alloca
to have somewhere to store and load from, another possibility is it may be okay to doptrtoint
and theninttoptr
to the other address space, there may yet be more options that I'm not seeing right now.