1; RUN: llc < %s -force-align-stack -mtriple i386-apple-darwin -mcpu=i486 | FileCheck %s
2
3%struct.foo = type { [88 x i8] }
4
5declare void @bar(i8* nocapture, %struct.foo* align 4 byval) nounwind
6declare void @baz(i8*) nounwind
7
8; PR15249
9; We can't use rep;movsl here because it clobbers the base pointer in %esi.
10define void @test1(%struct.foo* nocapture %x, i32 %y) nounwind {
11  %dynalloc = alloca i8, i32 %y, align 1
12  call void @bar(i8* %dynalloc, %struct.foo* align 4 byval %x)
13  ret void
14
15; CHECK-LABEL: test1:
16; CHECK: andl $-16, %esp
17; CHECK: movl %esp, %esi
18; CHECK-NOT: rep;movsl
19}
20
21; PR19012
22; Also don't clobber %esi if the dynamic alloca comes after the memcpy.
23define void @test2(%struct.foo* nocapture %x, i32 %y, i8* %z) nounwind {
24  call void @bar(i8* %z, %struct.foo* align 4 byval %x)
25  %dynalloc = alloca i8, i32 %y, align 1
26  call void @baz(i8* %dynalloc)
27  ret void
28
29; CHECK-LABEL: test2:
30; CHECK: movl %esp, %esi
31; CHECK-NOT: rep;movsl
32}
33
34; Check that we do use rep movs if we make the alloca static.
35define void @test3(%struct.foo* nocapture %x, i32 %y, i8* %z) nounwind {
36  call void @bar(i8* %z, %struct.foo* align 4 byval %x)
37  %statalloc = alloca i8, i32 8, align 1
38  call void @baz(i8* %statalloc)
39  ret void
40
41; CHECK-LABEL: test3:
42; CHECK: rep;movsl
43}
44