Skip to content

Commit

Permalink
Add new transcoding tests
Browse files Browse the repository at this point in the history
This also includes an XFAILed SPIR-V test for OpGroupIAdd, which has
incorrect name mangling as it maps to _Z21work_group_reduce_addi,
which is liable to use "no signed wrap" addition, rather than
_Z21work_group_reduce_addj, which should be tolerant of overflow.
  • Loading branch information
StuartDBrady authored and svenvh committed Aug 1, 2019
1 parent 7a53bfb commit 21e0587
Show file tree
Hide file tree
Showing 6 changed files with 637 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/OpGroupIAdd.spt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
119734787 65536 393230 13 0
2 Capability Addresses
2 Capability Kernel
2 Capability Groups
5 ExtInstImport 1 "OpenCL.std"
3 MemoryModel 1 2
10 EntryPoint 6 6 "testWorkGroupIAddUnsigned"
3 Source 3 200000
3 Name 7 "a"
4 Decorate 8 FuncParamAttr 5
4 TypeInt 3 32 0
4 Constant 3 11 2
2 TypeVoid 2
4 TypePointer 4 5 3
5 TypeFunction 5 2 3 4


5 Function 2 6 0 5
3 FunctionParameter 3 7
3 FunctionParameter 4 8

2 Label 9
6 GroupIAdd 3 10 11 0 7
5 Store 8 10 2 4
1 Return

1 FunctionEnd

; TODO: This currently maps to _Z21work_group_reduce_addi, but should map
; to _Z21work_group_reduce_addj, instead. Remove this test and update
; test/transcoding/group_ops.cl when fixing this.
; XFAIL: *
; RUN: llvm-spirv %s -to-binary -o %t.spv
; RUN: spirv-val %t.spv
; RUN: llvm-spirv -r %t.spv -o %t.bc
; RUN: llvm-dis < %t.bc | FileCheck %s

; CHECK: call spir_func i32 @_Z21work_group_reduce_addj(i32 %a)
76 changes: 76 additions & 0 deletions test/transcoding/DivRem.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// RUN: %clang_cc1 -triple spir-unknown-unknown -O1 -cl-std=CL2.0 -finclude-default-header -emit-llvm-bc %s -o %t.bc
// RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV
// RUN: llvm-spirv %t.bc -o %t.spv
// RUN: spirv-val %t.spv
// RUN: llvm-spirv -r %t.spv -o %t.rev.bc
// RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM

// CHECK-SPIRV-DAG: TypeInt [[int:[0-9]+]] 32 0
// CHECK-SPIRV-DAG: TypeVector [[int2:[0-9]+]] [[int]] 2
// CHECK-SPIRV-DAG: TypeFloat [[float:[0-9]+]] 32
// CHECK-SPIRV-DAG: TypeVector [[float2:[0-9]+]] [[float]] 2

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: SDiv [[int2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testSDiv
// CHECK-LLVM: sdiv <2 x i32> %a, %b

kernel void testSDiv(int2 a, int2 b, global int2 *res) {
res[0] = a / b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: UDiv [[int2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testUDiv
// CHECK-LLVM: udiv <2 x i32> %a, %b

kernel void testUDiv(uint2 a, uint2 b, global uint2 *res) {
res[0] = a / b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: FDiv [[float2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testFDiv
// CHECK-LLVM: fdiv <2 x float> %a, %b

kernel void testFDiv(float2 a, float2 b, global float2 *res) {
res[0] = a / b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: SRem [[int2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testSRem
// CHECK-LLVM: srem <2 x i32> %a, %b

kernel void testSRem(int2 a, int2 b, global int2 *res) {
res[0] = a % b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: UMod [[int2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testUMod
// CHECK-LLVM: urem <2 x i32> %a, %b

kernel void testUMod(uint2 a, uint2 b, global uint2 *res) {
res[0] = a % b;
}
191 changes: 191 additions & 0 deletions test/transcoding/RelationalOperators.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
// RUN: %clang_cc1 -triple spir-unknown-unknown -O1 -cl-std=CL2.0 -finclude-default-header -emit-llvm-bc %s -o %t.bc
// RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV
// RUN: llvm-spirv %t.bc -o %t.spv
// RUN: spirv-val %t.spv
// RUN: llvm-spirv -r %t.spv -o %t.rev.bc
// RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM

// CHECK-SPIRV: TypeBool [[bool:[0-9]+]]
// CHECK-SPIRV: TypeVector [[bool2:[0-9]+]] [[bool]] 2

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: UGreaterThan [[bool2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testUGreaterThan
// CHECK-LLVM: icmp ugt <2 x i32> %a, %b

kernel void testUGreaterThan(uint2 a, uint2 b, global int2 *res) {
res[0] = a > b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: SGreaterThan [[bool2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testSGreaterThan
// CHECK-LLVM: icmp sgt <2 x i32> %a, %b

kernel void testSGreaterThan(int2 a, int2 b, global int2 *res) {
res[0] = a > b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: UGreaterThanEqual [[bool2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testUGreaterThanEqual
// CHECK-LLVM: icmp uge <2 x i32> %a, %b

kernel void testUGreaterThanEqual(uint2 a, uint2 b, global int2 *res) {
res[0] = a >= b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: SGreaterThanEqual [[bool2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testSGreaterThanEqual
// CHECK-LLVM: icmp sge <2 x i32> %a, %b

kernel void testSGreaterThanEqual(int2 a, int2 b, global int2 *res) {
res[0] = a >= b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: ULessThan [[bool2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testULessThan
// CHECK-LLVM: icmp ult <2 x i32> %a, %b

kernel void testULessThan(uint2 a, uint2 b, global int2 *res) {
res[0] = a < b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: SLessThan [[bool2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testSLessThan
// CHECK-LLVM: icmp slt <2 x i32> %a, %b

kernel void testSLessThan(int2 a, int2 b, global int2 *res) {
res[0] = a < b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: ULessThanEqual [[bool2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testULessThanEqual
// CHECK-LLVM: icmp ule <2 x i32> %a, %b

kernel void testULessThanEqual(uint2 a, uint2 b, global int2 *res) {
res[0] = a <= b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: SLessThanEqual [[bool2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testSLessThanEqual
// CHECK-LLVM: icmp sle <2 x i32> %a, %b

kernel void testSLessThanEqual(int2 a, int2 b, global int2 *res) {
res[0] = a <= b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: FOrdEqual [[bool2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testFOrdEqual
// CHECK-LLVM: fcmp oeq <2 x float> %a, %b

kernel void testFOrdEqual(float2 a, float2 b, global int2 *res) {
res[0] = a == b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: FUnordNotEqual [[bool2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testFUnordNotEqual
// CHECK-LLVM: fcmp une <2 x float> %a, %b

kernel void testFUnordNotEqual(float2 a, float2 b, global int2 *res) {
res[0] = a != b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: FOrdGreaterThan [[bool2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testFOrdGreaterThan
// CHECK-LLVM: fcmp ogt <2 x float> %a, %b

kernel void testFOrdGreaterThan(float2 a, float2 b, global int2 *res) {
res[0] = a > b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: FOrdGreaterThanEqual [[bool2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testFOrdGreaterThanEqual
// CHECK-LLVM: fcmp oge <2 x float> %a, %b

kernel void testFOrdGreaterThanEqual(float2 a, float2 b, global int2 *res) {
res[0] = a >= b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: FOrdLessThan [[bool2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testFOrdLessThan
// CHECK-LLVM: fcmp olt <2 x float> %a, %b

kernel void testFOrdLessThan(float2 a, float2 b, global int2 *res) {
res[0] = a < b;
}

// CHECK-SPIRV-LABEL: 5 Function
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
// CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
// CHECK-SPIRV: FOrdLessThanEqual [[bool2]] {{[0-9]+}} [[A]] [[B]]
// CHECK-SPIRV: FunctionEnd

// CHECK-LLVM-LABEL: @testFOrdLessThanEqual
// CHECK-LLVM: fcmp ole <2 x float> %a, %b

kernel void testFOrdLessThanEqual(float2 a, float2 b, global int2 *res) {
res[0] = a <= b;
}
43 changes: 43 additions & 0 deletions test/transcoding/RelationalOperatorsFOrd.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc -spirv-text -o %t.txt
; RUN: FileCheck < %t.txt %s --check-prefix=CHECK-SPIRV
; RUN: llvm-spirv %t.bc -o %t.spv
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM

; CHECK-SPIRV: TypeBool [[bool:[0-9]+]]
; CHECK-SPIRV: TypeVector [[bool2:[0-9]+]] [[bool]] 2

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 = "spir-unknown-unknown"

; CHECK-SPIRV-LABEL: 5 Function
; CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[A:[0-9]+]]
; CHECK-SPIRV-NEXT: FunctionParameter {{[0-9]+}} [[B:[0-9]+]]
; CHECK-SPIRV: 5 FOrdNotEqual [[bool2]] {{[0-9]+}} [[A]] [[B]]
; CHECK-SPIRV: FunctionEnd

; CHECK-LLVM-LABEL: @testFOrdNotEqual
; CHECK-LLVM: fcmp one <2 x float> %a, %b

; Function Attrs: nounwind
define spir_kernel void @testFOrdNotEqual(<2 x float> %a, <2 x float> %b) #0 !kernel_arg_addr_space !2 !kernel_arg_access_qual !3 !kernel_arg_type !4 !kernel_arg_type_qual !5 !kernel_arg_base_type !4 {
entry:
%0 = fcmp one <2 x float> %a, %b
ret void
}

attributes #0 = { nounwind }

!opencl.enable.FP_CONTRACT = !{}
!opencl.spir.version = !{!0}
!opencl.ocl.version = !{!0}
!opencl.used.extensions = !{!1}
!opencl.used.optional.core.features = !{!1}

!0 = !{i32 2, i32 0}
!1 = !{}
!2 = !{i32 0, i32 0}
!3 = !{!"none", !"none"}
!4 = !{!"float2", !"float2"}
!5 = !{!"", !""}
Loading

0 comments on commit 21e0587

Please sign in to comment.