Skip to content

Commit ac31b7a

Browse files
EbinJose2002sys-ce-bb
authored andcommitted
Porting tests from llvm-project (#3303)
Add tests for atomic exchange, type emission, bitcasts, and block reordering Original commit: KhronosGroup/SPIRV-LLVM-Translator@6fce8e4628f420e
1 parent 84a4c37 commit ac31b7a

File tree

5 files changed

+367
-49
lines changed

5 files changed

+367
-49
lines changed

llvm-spirv/test/AtomicExchange.ll

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s
3+
; RUN: llvm-spirv %t.bc -o %t.spv
4+
; RUN: spirv-val %t.spv
5+
; RUN: llvm-spirv -r --spirv-target-env=SPV-IR %t.spv -o %t.rev.bc
6+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-SPV-IR
7+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
8+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-OCL-IR
9+
10+
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"
11+
target triple = "spir"
12+
13+
; CHECK-DAG: TypeInt [[#Int64:]] 64 0
14+
; CHECK-COUNT-9: AtomicExchange [[#Int64]] [[#]] [[#]] [[#]] [[#]] [[#]]
15+
16+
; CHECK-SPV-IR-COUNT-9: __spirv_AtomicExchange
17+
; CHECK-OCL-IR-COUNT-9: call spir_func i64 @_Z9atom_xchg
18+
; TODO: The call to @_Z9atom_xchg is not yet lowered to the corresponding SPIR-V instruction.
19+
; It currently remains as a plain function call during SPIR-V generation.
20+
21+
%Type1 = type { i64 }
22+
%Type2 = type { ptr addrspace(4) }
23+
24+
define linkonce_odr dso_local spir_func void @f1() {
25+
entry:
26+
%a = alloca %Type1, align 8
27+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
28+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
29+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePyN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEy(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 3)
30+
ret void
31+
}
32+
33+
define linkonce_odr dso_local spir_func void @f2() {
34+
entry:
35+
%a = alloca %Type1, align 8
36+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
37+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
38+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePxN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEx(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 3)
39+
ret void
40+
}
41+
42+
define linkonce_odr dso_local spir_func void @f3() {
43+
entry:
44+
%a = alloca %Type1, align 8
45+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
46+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
47+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePmN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEm(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 3)
48+
ret void
49+
}
50+
51+
define linkonce_odr dso_local spir_func void @f4() {
52+
entry:
53+
%a = alloca %Type1, align 8
54+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
55+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
56+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePlN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEl(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 3)
57+
ret void
58+
}
59+
60+
61+
define linkonce_odr dso_local spir_func void @f5() {
62+
entry:
63+
%a = alloca %Type2, align 8
64+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
65+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
66+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePmN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEm(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 %p)
67+
ret void
68+
}
69+
70+
define linkonce_odr dso_local spir_func void @f6() {
71+
entry:
72+
%a = alloca %Type2, align 8
73+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
74+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
75+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePmN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEm(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 %p)
76+
ret void
77+
}
78+
79+
define linkonce_odr dso_local spir_func void @f7() {
80+
entry:
81+
%a = alloca %Type2, align 8
82+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
83+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
84+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePmN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEm(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 %p)
85+
ret void
86+
}
87+
88+
define linkonce_odr dso_local spir_func void @f8() {
89+
entry:
90+
%a = alloca %Type2, align 8
91+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
92+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
93+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePmN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEm(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 %p)
94+
ret void
95+
}
96+
97+
; Function Attrs: convergent mustprogress norecurse nounwind
98+
define linkonce_odr dso_local spir_func void @f9() {
99+
entry:
100+
%a = alloca %Type2, align 8
101+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
102+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
103+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePmN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEm(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 %p)
104+
ret void
105+
}
106+
107+
declare dso_local spir_func i64 @_Z22__spirv_AtomicExchangePyN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEy(ptr addrspace(4), i32, i32, i64)
108+
declare dso_local spir_func i64 @_Z22__spirv_AtomicExchangePxN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEx(ptr addrspace(4), i32, i32, i64)
109+
declare dso_local spir_func i64 @_Z22__spirv_AtomicExchangePmN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEm(ptr addrspace(4), i32, i32, i64)
110+
declare dso_local spir_func i64 @_Z22__spirv_AtomicExchangePlN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEl(ptr addrspace(4), i32, i32, i64)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: llvm-spirv %t.bc -spirv-text -o %t.txt
4+
; RUN: FileCheck < %t.txt %s
5+
; RUN: spirv-val %t.spv
6+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
7+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
8+
9+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
10+
target triple = "spir64"
11+
12+
define void @main() {
13+
entry:
14+
15+
; CHECK-DAG: Capability Float16Buffer
16+
; CHECK-DAG: Capability Float64
17+
18+
; CHECK-DAG: TypeFloat [[#half:]] 16
19+
; CHECK-DAG: TypeFloat [[#float:]] 32
20+
; CHECK-DAG: TypeFloat [[#double:]] 64
21+
22+
; CHECK-DAG: TypeVector [[#v2half:]] [[#half]] 2
23+
; CHECK-DAG: TypeVector [[#v3half:]] [[#half]] 3
24+
; CHECK-DAG: TypeVector [[#v4half:]] [[#half]] 4
25+
; CHECK-DAG: TypeVector [[#v2float:]] [[#float]] 2
26+
; CHECK-DAG: TypeVector [[#v3float:]] [[#float]] 3
27+
; CHECK-DAG: TypeVector [[#v4float:]] [[#float]] 4
28+
; CHECK-DAG: TypeVector [[#v2double:]] [[#double]] 2
29+
; CHECK-DAG: TypeVector [[#v3double:]] [[#double]] 3
30+
; CHECK-DAG: TypeVector [[#v4double:]] [[#double]] 4
31+
32+
; CHECK-DAG: TypePointer [[#ptr_Function_half:]] 7 [[#half]]
33+
; CHECK-DAG: TypePointer [[#ptr_Function_float:]] 7 [[#float]]
34+
; CHECK-DAG: TypePointer [[#ptr_Function_double:]] 7 [[#double]]
35+
; CHECK-DAG: TypePointer [[#ptr_Function_v2half:]] 7 [[#v2half]]
36+
; CHECK-DAG: TypePointer [[#ptr_Function_v3half:]] 7 [[#v3half]]
37+
; CHECK-DAG: TypePointer [[#ptr_Function_v4half:]] 7 [[#v4half]]
38+
; CHECK-DAG: TypePointer [[#ptr_Function_v2float:]] 7 [[#v2float]]
39+
; CHECK-DAG: TypePointer [[#ptr_Function_v3float:]] 7 [[#v3float]]
40+
; CHECK-DAG: TypePointer [[#ptr_Function_v4float:]] 7 [[#v4float]]
41+
; CHECK-DAG: TypePointer [[#ptr_Function_v2double:]] 7 [[#v2double]]
42+
; CHECK-DAG: TypePointer [[#ptr_Function_v3double:]] 7 [[#v3double]]
43+
; CHECK-DAG: TypePointer [[#ptr_Function_v4double:]] 7 [[#v4double]]
44+
45+
; CHECK-DAG: Variable [[#ptr_Function_half]] [[#]] 7
46+
; CHECK-LLVM: alloca half, align 2
47+
%half_Val = alloca half, align 2
48+
49+
; CHECK-DAG: Variable [[#ptr_Function_float]] [[#]] 7
50+
; CHECK-LLVM: alloca float, align 4
51+
%float_Val = alloca float, align 4
52+
53+
; CHECK-DAG: Variable [[#ptr_Function_double]] [[#]] 7
54+
; CHECK-LLVM: alloca double, align 8
55+
%double_Val = alloca double, align 8
56+
57+
; CHECK-DAG: Variable [[#ptr_Function_v2half]] [[#]] 7
58+
; CHECK-LLVM: alloca <2 x half>, align 4
59+
%half2_Val = alloca <2 x half>, align 4
60+
61+
; CHECK-DAG: Variable [[#ptr_Function_v3half]] [[#]] 7
62+
; CHECK-LLVM: alloca <3 x half>, align 8
63+
%half3_Val = alloca <3 x half>, align 8
64+
65+
; CHECK-DAG: Variable [[#ptr_Function_v4half]] [[#]] 7
66+
; CHECK-LLVM: alloca <4 x half>, align 8
67+
%half4_Val = alloca <4 x half>, align 8
68+
69+
; CHECK-DAG: Variable [[#ptr_Function_v2float]] [[#]] 7
70+
; CHECK-LLVM: alloca <2 x float>, align 8
71+
%float2_Val = alloca <2 x float>, align 8
72+
73+
; CHECK-DAG: Variable [[#ptr_Function_v3float]] [[#]] 7
74+
; CHECK-LLVM: alloca <3 x float>, align 16
75+
%float3_Val = alloca <3 x float>, align 16
76+
77+
; CHECK-DAG: Variable [[#ptr_Function_v4float]] [[#]] 7
78+
; CHECK-LLVM: alloca <4 x float>, align 16
79+
%float4_Val = alloca <4 x float>, align 16
80+
81+
; CHECK-DAG: Variable [[#ptr_Function_v2double]] [[#]] 7
82+
; CHECK-LLVM: alloca <2 x double>, align 16
83+
%double2_Val = alloca <2 x double>, align 16
84+
85+
; CHECK-DAG: Variable [[#ptr_Function_v3double]] [[#]] 7
86+
; CHECK-LLVM: alloca <3 x double>, align 32
87+
%double3_Val = alloca <3 x double>, align 32
88+
89+
; CHECK-DAG: Variable [[#ptr_Function_v4double]] [[#]] 7
90+
; CHECK-LLVM: alloca <4 x double>, align 32
91+
%double4_Val = alloca <4 x double>, align 32
92+
ret void
93+
}

llvm-spirv/test/basic_int_types.ll

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: llvm-spirv %t.bc -spirv-text -o %t.txt
4+
; RUN: FileCheck < %t.txt %s
5+
; RUN: spirv-val %t.spv
6+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
7+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
8+
9+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
10+
target triple = "spir64"
11+
12+
define void @main() {
13+
entry:
14+
; CHECK-DAG: TypeInt [[#short:]] 16 0
15+
; CHECK-DAG: TypeInt [[#int:]] 32 0
16+
; CHECK-DAG: TypeInt [[#long:]] 64 0
17+
18+
; CHECK-DAG: TypeVector [[#v2short:]] [[#short]] 2
19+
; CHECK-DAG: TypeVector [[#v3short:]] [[#short]] 3
20+
; CHECK-DAG: TypeVector [[#v4short:]] [[#short]] 4
21+
; CHECK-DAG: TypeVector [[#v2int:]] [[#int]] 2
22+
; CHECK-DAG: TypeVector [[#v3int:]] [[#int]] 3
23+
; CHECK-DAG: TypeVector [[#v4int:]] [[#int]] 4
24+
; CHECK-DAG: TypeVector [[#v2long:]] [[#long]] 2
25+
; CHECK-DAG: TypeVector [[#v3long:]] [[#long]] 3
26+
; CHECK-DAG: TypeVector [[#v4long:]] [[#long]] 4
27+
28+
; CHECK-DAG: TypePointer [[#ptr_Function_short:]] 7 [[#short]]
29+
; CHECK-DAG: TypePointer [[#ptr_Function_int:]] 7 [[#int]]
30+
; CHECK-DAG: TypePointer [[#ptr_Function_long:]] 7 [[#long]]
31+
; CHECK-DAG: TypePointer [[#ptr_Function_v2short:]] 7 [[#v2short]]
32+
; CHECK-DAG: TypePointer [[#ptr_Function_v3short:]] 7 [[#v3short]]
33+
; CHECK-DAG: TypePointer [[#ptr_Function_v4short:]] 7 [[#v4short]]
34+
; CHECK-DAG: TypePointer [[#ptr_Function_v2int:]] 7 [[#v2int]]
35+
; CHECK-DAG: TypePointer [[#ptr_Function_v3int:]] 7 [[#v3int]]
36+
; CHECK-DAG: TypePointer [[#ptr_Function_v4int:]] 7 [[#v4int]]
37+
; CHECK-DAG: TypePointer [[#ptr_Function_v2long:]] 7 [[#v2long]]
38+
; CHECK-DAG: TypePointer [[#ptr_Function_v3long:]] 7 [[#v3long]]
39+
; CHECK-DAG: TypePointer [[#ptr_Function_v4long:]] 7 [[#v4long]]
40+
41+
; CHECK-DAG: Variable [[#ptr_Function_short]] [[#]] 7
42+
; CHECK-LLVM: alloca i16, align 2
43+
%int16_t_Val = alloca i16, align 2
44+
45+
; CHECK-DAG: Variable [[#ptr_Function_int]] [[#]] 7
46+
; CHECK-LLVM: alloca i32, align 4
47+
%int_Val = alloca i32, align 4
48+
49+
; CHECK-DAG: Variable [[#ptr_Function_long]] [[#]] 7
50+
; CHECK-LLVM: alloca i64, align 8
51+
%int64_t_Val = alloca i64, align 8
52+
53+
; CHECK-DAG: Variable [[#ptr_Function_v2short]] [[#]] 7
54+
; CHECK-LLVM: alloca <2 x i16>, align 4
55+
%int16_t2_Val = alloca <2 x i16>, align 4
56+
57+
; CHECK-DAG: Variable [[#ptr_Function_v3short]] [[#]] 7
58+
; CHECK-LLVM: alloca <3 x i16>, align 8
59+
%int16_t3_Val = alloca <3 x i16>, align 8
60+
61+
; CHECK-DAG: Variable [[#ptr_Function_v4short]] [[#]] 7
62+
; CHECK-LLVM: alloca <4 x i16>, align 8
63+
%int16_t4_Val = alloca <4 x i16>, align 8
64+
65+
; CHECK-DAG: Variable [[#ptr_Function_v2int]] [[#]] 7
66+
; CHECK-LLVM: alloca <2 x i32>, align 8
67+
%int2_Val = alloca <2 x i32>, align 8
68+
69+
; CHECK-DAG: Variable [[#ptr_Function_v3int]] [[#]] 7
70+
; CHECK-LLVM: alloca <3 x i32>, align 16
71+
%int3_Val = alloca <3 x i32>, align 16
72+
73+
; CHECK-DAG: Variable [[#ptr_Function_v4int]] [[#]] 7
74+
; CHECK-LLVM: alloca <4 x i32>, align 16
75+
%int4_Val = alloca <4 x i32>, align 16
76+
77+
; CHECK-DAG: Variable [[#ptr_Function_v2long]] [[#]] 7
78+
; CHECK-LLVM: alloca <2 x i64>, align 16
79+
%int64_t2_Val = alloca <2 x i64>, align 16
80+
81+
; CHECK-DAG: Variable [[#ptr_Function_v3long]] [[#]] 7
82+
; CHECK-LLVM: alloca <3 x i64>, align 32
83+
%int64_t3_Val = alloca <3 x i64>, align 32
84+
85+
; CHECK-DAG: Variable [[#ptr_Function_v4long]] [[#]] 7
86+
; CHECK-LLVM: alloca <4 x i64>, align 32
87+
%int64_t4_Val = alloca <4 x i64>, align 32
88+
89+
ret void
90+
}

llvm-spirv/test/block-ordering.ll

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: llvm-spirv %t.bc -spirv-text -o %t.txt
4+
; RUN: FileCheck < %t.txt %s
5+
; RUN: spirv-val %t.spv
6+
7+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
8+
target triple = "spir64"
9+
10+
; Checks SPIR-V blocks are correctly reordered so that dominators shows up
11+
; before others in the binary layout.
12+
13+
define void @main() {
14+
; CHECK: Label
15+
; CHECK: Branch [[#l1:]]
16+
17+
; CHECK: Label [[#l1]]
18+
; CHECK: Branch [[#l2:]]
19+
20+
; CHECK: Label [[#l2]]
21+
; CHECK: Branch [[#end:]]
22+
23+
; CHECK: Label [[#end]]
24+
; CHECK: Return
25+
entry:
26+
br label %l1
27+
28+
l2:
29+
br label %end
30+
31+
l1:
32+
br label %l2
33+
34+
end:
35+
ret void
36+
}

0 commit comments

Comments
 (0)