-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SPIR-V] Emit valid SPIR-V code for integer sizes other than 8,16,32,64 #94219
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
; The goal of the test is to check that only one "OpTypeInt 8" instruction | ||
; is generated for a series of LLVM integer types with number of bits less | ||
; than 8. | ||
|
||
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV | ||
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %} | ||
|
||
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV | ||
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %} | ||
|
||
; CHECK-SPIRV: %[[#CharTy:]] = OpTypeInt 8 0 | ||
; CHECK-SPIRV-NO: %[[#CharTy:]] = OpTypeInt 8 0 | ||
|
||
define spir_func void @foo(i2 %a, i4 %b) { | ||
entry: | ||
ret void | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
; The goal of the test case is to ensure valid SPIR-V code emision | ||
; on translation of integers with bit width less than 8. | ||
|
||
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - | FileCheck %s --check-prefix=CHECK-SPIRV | ||
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - -filetype=obj | spirv-val %} | ||
|
||
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - | FileCheck %s --check-prefix=CHECK-SPIRV | ||
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - -filetype=obj | spirv-val %} | ||
|
||
; CHECK-SPIRV: OpCapability BitInstructions | ||
; CHECK-SPIRV: OpExtension "SPV_KHR_bit_instructions" | ||
; CHECK-SPIRV: %[[#CharTy:]] = OpTypeInt 8 0 | ||
; CHECK-SPIRV-NO: %[[#CharTy:]] = OpTypeInt 8 0 | ||
; CHECK-SPIRV-COUNT-2: %[[#]] = OpBitReverse %[[#CharTy]] %[[#]] | ||
|
||
define spir_func void @foo(i2 %a, i4 %b) { | ||
entry: | ||
%res2 = tail call i2 @llvm.bitreverse.i2(i2 %a) | ||
%res4 = tail call i4 @llvm.bitreverse.i4(i4 %b) | ||
ret void | ||
} | ||
|
||
declare i2 @llvm.bitreverse.i2(i2) | ||
declare i4 @llvm.bitreverse.i4(i4) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,10 @@ | |
; CHECK-SPIRV: OpCapability BitInstructions | ||
; CHECK-SPIRV: OpExtension "SPV_KHR_bit_instructions" | ||
; CHECK-SPIRV: %[[#CharTy:]] = OpTypeInt 8 0 | ||
; CHECK-SPIRV: %[[#]] = OpBitReverse %[[#CharTy]] %[[#]] | ||
; CHECK-SPIRV-NO: %[[#CharTy:]] = OpTypeInt 8 0 | ||
; CHECK-SPIRV: %[[#Arg:]] = OpFunctionParameter %[[#CharTy]] | ||
; CHECK-SPIRV: %[[#Res:]] = OpBitReverse %[[#CharTy]] %[[#Arg]] | ||
Comment on lines
+14
to
+15
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. Isn't there a behavior change between the LLVM-IR to SPIR-V? Shouldn't this LLVM code be converted to:
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. 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. Right I see! In that case, I'm fine with a simple TODO comment and to merge this PR to only address illegal codegen 😊 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. Sure, I will add a TODO. Thank you! 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. Done |
||
; CHECK-SPIRV: OpReturnValue %[[#Res]] | ||
|
||
define spir_func signext i2 @foo(i2 noundef signext %a) { | ||
entry: | ||
|
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.
Shall the last condition be removed, and this function always return 64 if width > 32? (given the assert above)
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 will replace assert() with report_fatal_error() and remove the last condition to be sure all is working the same way even for builds without asserts().
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.
Done