Skip to content

Commit f3e7b35

Browse files
authored
[SPIRV] Test file for memcpy intrinsic (#151657)
Test lowering of llvm.memcpy intrinsics to OpCopyMemorySized with alignment.
1 parent 09a6a25 commit f3e7b35

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
%struct.B = type { [2 x i32] }
5+
%struct.A = type { i64, %struct.B }
6+
7+
@__const.foo.b = private unnamed_addr addrspace(2) constant %struct.B { [2 x i32] [i32 1, i32 2] }, align 4
8+
@__const.bar.a = private unnamed_addr addrspace(2) constant %struct.A { i64 0, %struct.B { [2 x i32] [i32 1, i32 2] } }, align 8
9+
10+
define spir_func void @foo(%struct.A* noalias sret(%struct.A) %agg.result) {
11+
entry:
12+
%b = alloca %struct.B, align 4
13+
%0 = bitcast %struct.B* %b to i8*
14+
call void @llvm.lifetime.start.p0i8(i64 8, i8* %0)
15+
%1 = bitcast %struct.B* %b to i8*
16+
call void @llvm.memcpy.p0i8.p2i8.i32(i8* align 4 %1, i8 addrspace(2)* align 4 bitcast (%struct.B addrspace(2)* @__const.foo.b to i8 addrspace(2)*), i32 8, i1 false)
17+
; CHECK: OpCopyMemorySized %[[#]] %[[#]] %[[#]] Aligned 4
18+
%b1 = getelementptr inbounds %struct.A, %struct.A* %agg.result, i32 0, i32 1
19+
%2 = bitcast %struct.B* %b1 to i8*
20+
%3 = bitcast %struct.B* %b to i8*
21+
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 8 %2, i8* align 4 %3, i32 8, i1 false)
22+
; CHECK: %[[#PTR1:]] = OpInBoundsPtrAccessChain %[[#]] %[[#]] %[[#]] %[[#]]
23+
; CHECK: OpCopyMemorySized %[[#PTR1]] %[[#]] %[[#]] Aligned 8
24+
%4 = bitcast %struct.B* %b to i8*
25+
call void @llvm.lifetime.end.p0i8(i64 8, i8* %4)
26+
ret void
27+
}
28+
29+
declare void @llvm.lifetime.start.p0i8(i64, i8* captures(none))
30+
31+
declare void @llvm.memcpy.p0i8.p2i8.i32(i8* captures(none) writeonly, i8 addrspace(2)* captures(none) readonly, i32, i1)
32+
33+
declare void @llvm.memcpy.p0i8.p0i8.i32(i8* captures(none) writeonly, i8* captures(none) readonly, i32, i1)
34+
35+
declare void @llvm.lifetime.end.p0i8(i64, i8* captures(none))
36+
37+
define spir_func void @bar(%struct.B* noalias sret(%struct.B) %agg.result) {
38+
entry:
39+
%a = alloca %struct.A, align 8
40+
%0 = bitcast %struct.A* %a to i8*
41+
call void @llvm.lifetime.start.p0i8(i64 16, i8* %0)
42+
%1 = bitcast %struct.A* %a to i8*
43+
call void @llvm.memcpy.p0i8.p2i8.i32(i8* align 8 %1, i8 addrspace(2)* align 8 bitcast (%struct.A addrspace(2)* @__const.bar.a to i8 addrspace(2)*), i32 16, i1 false)
44+
; CHECK: OpCopyMemorySized %[[#]] %[[#]] %[[#]] Aligned 8
45+
%b = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 1
46+
%2 = bitcast %struct.B* %agg.result to i8*
47+
%3 = bitcast %struct.B* %b to i8*
48+
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %2, i8* align 8 %3, i32 8, i1 false)
49+
; CHECK: %[[#PTR2:]] = OpInBoundsPtrAccessChain %[[#]] %[[#]] %[[#]] %[[#]]
50+
; CHECK: OpCopyMemorySized %[[#]] %[[#PTR2]] %[[#]] Aligned 4
51+
%4 = bitcast %struct.A* %a to i8*
52+
call void @llvm.lifetime.end.p0i8(i64 16, i8* %4)
53+
ret void
54+
}

0 commit comments

Comments
 (0)