+
+; PR18726: Check that we use memcpy and memset to fill out padding when we have
+; a slice with a simple single type whose store size is smaller than the slice
+; size.
+
+%union.Foo = type { x86_fp80, i64, i64 }
+
+@foo_copy_source = external constant %union.Foo
+@i64_sink = global i64 0
+
+define void @memcpy_fp80_padding() {
+ %x = alloca %union.Foo
+
+ ; Copy from a global.
+ %x_i8 = bitcast %union.Foo* %x to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %x_i8, i8* bitcast (%union.Foo* @foo_copy_source to i8*), i32 32, i32 16, i1 false)
+
+ ; Access a slice of the alloca to trigger SROA.
+ %mid_p = getelementptr %union.Foo* %x, i32 0, i32 1
+ %elt = load i64* %mid_p
+ store i64 %elt, i64* @i64_sink
+ ret void
+}
+; CHECK-LABEL: define void @memcpy_fp80_padding
+; CHECK: alloca x86_fp80
+; CHECK: call void @llvm.memcpy.p0i8.p0i8.i32
+; CHECK: load i64* getelementptr inbounds (%union.Foo* @foo_copy_source, i64 0, i32 1)
+; CHECK: load i64* getelementptr inbounds (%union.Foo* @foo_copy_source, i64 0, i32 2)
+
+define void @memset_fp80_padding() {
+ %x = alloca %union.Foo
+
+ ; Set to all ones.
+ %x_i8 = bitcast %union.Foo* %x to i8*
+ call void @llvm.memset.p0i8.i32(i8* %x_i8, i8 -1, i32 32, i32 16, i1 false)
+
+ ; Access a slice of the alloca to trigger SROA.
+ %mid_p = getelementptr %union.Foo* %x, i32 0, i32 1
+ %elt = load i64* %mid_p
+ store i64 %elt, i64* @i64_sink
+ ret void
+}
+; CHECK-LABEL: define void @memset_fp80_padding
+; CHECK: alloca x86_fp80
+; CHECK: call void @llvm.memset.p0i8.i32(i8* %{{.*}}, i8 -1, i32 16, i32 16, i1 false)
+; CHECK: store i64 -1, i64* @i64_sink