1;  RUN: llc < %s -mtriple=x86_64-unknown-linux -O2 | FileCheck %s
2;  RUN: llc < %s -mtriple=i686-unknown-linux -O2 | FileCheck %s
3
4; This test checks that:
5; (1)  mempcpy is lowered as memcpy, and
6; (2)  its return value is DST+N i.e. the dst pointer adjusted by the copy size.
7; To keep the testing of (2) independent of the exact instructions used to
8; adjust the dst pointer, DST+N is explicitly computed and stored to a global
9; variable G before the mempcpy call. This instance of DST+N causes the repeat
10; DST+N done in the context of the return value of mempcpy to be redundant, and
11; the first instance to be reused as the return value. This allows the check for
12; (2) to be expressed as verifying that the MOV to store DST+N to G and
13; the MOV to copy DST+N to %rax use the same source register.
14@G = common global i8* null, align 8
15
16; CHECK-LABEL: RET_MEMPCPY:
17; CHECK: mov{{.*}} [[REG:%[er][a-z0-9]+]], {{.*}}G
18; CHECK: call{{.*}} {{.*}}memcpy
19; CHECK: mov{{.*}} [[REG]], %{{[er]}}ax
20;
21define i8* @RET_MEMPCPY(i8* %DST, i8* %SRC, i64 %N) {
22  %add.ptr = getelementptr inbounds i8, i8* %DST, i64 %N
23  store i8* %add.ptr, i8** @G, align 8
24  %call = tail call i8* @mempcpy(i8* %DST, i8* %SRC, i64 %N)
25  ret i8* %call
26}
27
28declare i8* @mempcpy(i8*, i8*, i64)
29