-
Notifications
You must be signed in to change notification settings - Fork 220
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
[SPIR-V 1.4] Support OpPtrEqual, OpPtrNotEqual and OpPtrDiff to compare pointers #2482
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c7af03f
Add support for Ptr(Not)Equal
vmaksimo f6493a5
Add PtrDiff support
vmaksimo c9f25db
Do reverse translation with lowering to llvm instructions
vmaksimo 1774b5a
Apply suggestion
vmaksimo 5ca1095
apply suggestions
vmaksimo 9a53933
Merge branch 'main' into ptr-equal-diff
MrSidims 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
; Check support of OpPtrDiff instruction that was added in SPIR-V 1.4 | ||
|
||
; RUN: llvm-as %s -o %t.bc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a small test description (one-liner). Thanks |
||
; RUN: not llvm-spirv --spirv-max-version=1.3 %t.bc 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s | ||
|
||
; RUN: llvm-spirv %t.bc -o %t.spv | ||
; RUN: llvm-spirv %t.spv -to-text -o %t.spt | ||
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV | ||
; RUN: spirv-val %t.spv | ||
|
||
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc | ||
; RUN: llvm-dis %t.rev.bc | ||
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM | ||
|
||
; CHECK-ERROR: RequiresVersion: Cannot fulfill SPIR-V version restriction: | ||
; CHECK-ERROR-NEXT: SPIR-V version was restricted to at most 1.3 (66304) but a construct from the input requires SPIR-V version 1.4 (66560) or above | ||
|
||
; SPIR-V 1.4 | ||
; CHECK-SPIRV: 66560 | ||
; CHECK-SPIRV: TypeInt [[#TypeInt:]] 32 0 | ||
; CHECK-SPIRV: TypeFloat [[#TypeFloat:]] 32 | ||
; CHECK-SPIRV: TypePointer [[#TypePointer:]] [[#]] [[#TypeFloat]] | ||
|
||
; CHECK-SPIRV: Variable [[#TypePointer]] [[#Var:]] | ||
; CHECK-SPIRV: PtrDiff [[#TypeInt]] [[#]] [[#Var]] [[#Var]] | ||
|
||
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" | ||
target triple = "spir64-unknown-unknown" | ||
|
||
; Function Attrs: nounwind | ||
define spir_kernel void @test(float %a) local_unnamed_addr #0 { | ||
entry: | ||
%0 = alloca float, align 4 | ||
store float %a, ptr %0, align 4 | ||
; CHECK-LLVM: %[[#Arg1:]] = ptrtoint ptr %[[#]] to i64 | ||
; CHECK-LLVM: %[[#Arg2:]] = ptrtoint ptr %[[#]] to i64 | ||
; CHECK-LLVM: %[[#Sub:]] = sub i64 %[[#Arg1]], %[[#Arg2]] | ||
; CHECK-LLVM: sdiv exact i64 %[[#Sub]], ptrtoint (ptr getelementptr (i32, ptr null, i32 1) to i64) | ||
%1 = call spir_func noundef i32 @_Z15__spirv_PtrDiff(ptr %0, ptr %0) | ||
ret void | ||
} | ||
|
||
declare spir_func noundef i32 @_Z15__spirv_PtrDiff(ptr, ptr) | ||
|
||
attributes #0 = { convergent nounwind writeonly } | ||
|
||
!llvm.module.flags = !{!0} | ||
!opencl.ocl.version = !{!1} | ||
!opencl.spir.version = !{!1} | ||
|
||
!0 = !{i32 1, !"wchar_size", i32 4} | ||
!1 = !{i32 2, i32 0} |
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,60 @@ | ||
; Check support of OpPtrEqual and OpPtrNotEqual instructions that were added in SPIR-V 1.4 | ||
|
||
; RUN: llvm-as %s -o %t.bc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a small test description (one-liner). Thanks |
||
; RUN: not llvm-spirv --spirv-max-version=1.3 %t.bc 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s | ||
|
||
; RUN: llvm-spirv %t.bc -o %t.spv | ||
; RUN: llvm-spirv %t.spv -to-text -o %t.spt | ||
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV | ||
; RUN: spirv-val %t.spv | ||
|
||
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc | ||
; RUN: llvm-dis %t.rev.bc | ||
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM | ||
|
||
; CHECK-ERROR: RequiresVersion: Cannot fulfill SPIR-V version restriction: | ||
; CHECK-ERROR-NEXT: SPIR-V version was restricted to at most 1.3 (66304) but a construct from the input requires SPIR-V version 1.4 (66560) or above | ||
|
||
; SPIR-V 1.4 | ||
; CHECK-SPIRV: 66560 | ||
; CHECK-SPIRV: TypeFloat [[#TypeFloat:]] 32 | ||
; CHECK-SPIRV: TypePointer [[#TypePointer:]] [[#]] [[#TypeFloat]] | ||
; CHECK-SPIRV: TypeBool [[#TypeBool:]] | ||
|
||
; CHECK-SPIRV: Variable [[#TypePointer]] [[#Var1:]] | ||
; CHECK-SPIRV: Variable [[#TypePointer]] [[#Var2:]] | ||
; CHECK-SPIRV: PtrEqual [[#TypeBool]] [[#]] [[#Var1]] [[#Var2]] | ||
; CHECK-SPIRV: PtrNotEqual [[#TypeBool]] [[#]] [[#Var1]] [[#Var2]] | ||
|
||
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" | ||
target triple = "spir64-unknown-unknown" | ||
|
||
; Function Attrs: nounwind | ||
define spir_kernel void @test(float %a, float %b) local_unnamed_addr #0 { | ||
entry: | ||
%0 = alloca float, align 4 | ||
%1 = alloca float, align 4 | ||
store float %a, ptr %0, align 4 | ||
store float %b, ptr %1, align 4 | ||
; CHECK-LLVM: %[[#Arg1:]] = ptrtoint ptr %[[#]] to i64 | ||
; CHECK-LLVM: %[[#Arg2:]] = ptrtoint ptr %[[#]] to i64 | ||
; CHECK-LLVM: icmp eq i64 %[[#Arg1]], %[[#Arg2]] | ||
%2 = call spir_func noundef i1 @_Z16__spirv_PtrEqual(ptr %0, ptr %1) | ||
; CHECK-LLVM: %[[#Arg3:]] = ptrtoint ptr %[[#]] to i64 | ||
; CHECK-LLVM: %[[#Arg4:]] = ptrtoint ptr %[[#]] to i64 | ||
; CHECK-LLVM: icmp ne i64 %[[#Arg3]], %[[#Arg4]] | ||
%3 = call spir_func noundef i1 @_Z19__spirv_PtrNotEqual(ptr %0, ptr %1) | ||
ret void | ||
} | ||
|
||
declare spir_func noundef i1 @_Z16__spirv_PtrEqual(ptr, ptr) | ||
declare spir_func noundef i1 @_Z19__spirv_PtrNotEqual(ptr, ptr) | ||
|
||
attributes #0 = { convergent nounwind writeonly } | ||
|
||
!llvm.module.flags = !{!0} | ||
!opencl.ocl.version = !{!1} | ||
!opencl.spir.version = !{!1} | ||
|
||
!0 = !{i32 1, !"wchar_size", i32 4} | ||
!1 = !{i32 2, i32 0} |
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.
It's a nice occasion to improve diagnostics in this place and add precise info about op code that is not supported. I've once hit this exactly line when SPIRV Backend generated code for missed OpPtrEqual/NotEqual and spent some time on debugging. To avoid this in future we may want to improve diagnostics right in this place and give a user-friendly description of what exactly SPIRV Translator doesn't have support for.
@MrSidims @asudarsa what do you think? ^
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.
Agree with Slava
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 the subsequent change from @vmaksimo does provide more information. One issue I see here is our reliance on 'assert'. Should we try to provide an error mechanism which will stop translation in such cases? This can be made as a separate effort.
Thanks