1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=memcpyopt -mtriple=x86_64 < %s | FileCheck %s --check-prefixes=CHECK,LIBCALLS
3 ; RUN: opt -S -passes=memcpyopt -mtriple=amdgcn-- < %s | FileCheck %s --check-prefixes=CHECK,NO-LIBCALLS
4 ; RUN: opt -S -passes=memcpyopt -mtriple=amdgcn-- -enable-memcpyopt-without-libcalls < %s \
5 ; RUN: | FileCheck %s --check-prefixes=CHECK,LIBCALLS
7 ; REQUIRES: amdgpu-registered-target
8 ; REQUIRES: x86-registered-target
10 define void @dont_create_memset(ptr %p) {
11 ; LIBCALLS-LABEL: @dont_create_memset(
12 ; LIBCALLS-NEXT: [[P1:%.*]] = getelementptr i32, ptr [[P:%.*]], i64 1
13 ; LIBCALLS-NEXT: [[P2:%.*]] = getelementptr i32, ptr [[P]], i64 2
14 ; LIBCALLS-NEXT: [[P3:%.*]] = getelementptr i32, ptr [[P]], i64 3
15 ; LIBCALLS-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[P]], i8 0, i64 16, i1 false)
16 ; LIBCALLS-NEXT: ret void
18 ; NO-LIBCALLS-LABEL: @dont_create_memset(
19 ; NO-LIBCALLS-NEXT: store i32 0, ptr [[P:%.*]], align 4
20 ; NO-LIBCALLS-NEXT: [[P1:%.*]] = getelementptr i32, ptr [[P]], i64 1
21 ; NO-LIBCALLS-NEXT: store i32 0, ptr [[P1]], align 4
22 ; NO-LIBCALLS-NEXT: [[P2:%.*]] = getelementptr i32, ptr [[P]], i64 2
23 ; NO-LIBCALLS-NEXT: store i32 0, ptr [[P2]], align 4
24 ; NO-LIBCALLS-NEXT: [[P3:%.*]] = getelementptr i32, ptr [[P]], i64 3
25 ; NO-LIBCALLS-NEXT: store i32 0, ptr [[P3]], align 4
26 ; NO-LIBCALLS-NEXT: ret void
29 %p1 = getelementptr i32, ptr %p, i64 1
31 %p2 = getelementptr i32, ptr %p, i64 2
33 %p3 = getelementptr i32, ptr %p, i64 3
40 define void @dont_create_memcpy(ptr %p1, ptr %p2) {
41 ; LIBCALLS-LABEL: @dont_create_memcpy(
42 ; LIBCALLS-NEXT: call void @llvm.memmove.p0.p0.i64(ptr align 8 [[P2:%.*]], ptr align 8 [[P1:%.*]], i64 8, i1 false)
43 ; LIBCALLS-NEXT: ret void
45 ; NO-LIBCALLS-LABEL: @dont_create_memcpy(
46 ; NO-LIBCALLS-NEXT: [[V:%.*]] = load [[TY:%.*]], ptr [[P1:%.*]], align 8
47 ; NO-LIBCALLS-NEXT: store [[TY]] [[V]], ptr [[P2:%.*]], align 8
48 ; NO-LIBCALLS-NEXT: ret void
50 %v = load %ty, ptr %p1
55 define void @forward_memcpy(ptr noalias %p1, ptr noalias %p2, ptr noalias %p3) {
56 ; CHECK-LABEL: @forward_memcpy(
57 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[P2:%.*]], ptr [[P1:%.*]], i64 16, i1 false)
58 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[P3:%.*]], ptr [[P1]], i64 16, i1 false)
59 ; CHECK-NEXT: ret void
61 call void @llvm.memcpy.p0.p0.i64(ptr %p2, ptr %p1, i64 16, i1 false)
62 call void @llvm.memcpy.p0.p0.i64(ptr %p3, ptr %p2, i64 16, i1 false)
66 declare void @llvm.memcpy.p0.p0.i64(ptr, ptr, i64, i1)