blob: 9cf4f91e6aa26d8fdd2d3f8d6040d6e372ff9ae8 [file] [log] [blame]
Nick Lewycky99384942014-02-06 06:29:19 +00001; RUN: opt < %s -basicaa -memcpyopt -S | FileCheck %s
2
3target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
4target triple = "x86_64-apple-macosx10.8.0"
5
6%struct.foo = type { i8, [7 x i8], i32 }
7
8define i32 @test1(%struct.foo* nocapture %foobie) nounwind noinline ssp uwtable {
9 %bletch.sroa.1 = alloca [7 x i8], align 1
David Blaikie79e6c742015-02-27 19:29:02 +000010 %1 = getelementptr inbounds %struct.foo, %struct.foo* %foobie, i64 0, i32 0
Nick Lewycky99384942014-02-06 06:29:19 +000011 store i8 98, i8* %1, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000012 %2 = getelementptr inbounds %struct.foo, %struct.foo* %foobie, i64 0, i32 1, i64 0
13 %3 = getelementptr inbounds [7 x i8], [7 x i8]* %bletch.sroa.1, i64 0, i64 0
Daniel Neilson1e687242018-01-19 17:13:12 +000014 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* %3, i64 7, i1 false)
David Blaikie79e6c742015-02-27 19:29:02 +000015 %4 = getelementptr inbounds %struct.foo, %struct.foo* %foobie, i64 0, i32 2
Nick Lewycky99384942014-02-06 06:29:19 +000016 store i32 20, i32* %4, align 4
17 ret i32 undef
18
19; Check that the memcpy is removed.
20; CHECK-LABEL: @test1(
21; CHECK-NOT: call void @llvm.memcpy
22}
23
Nick Lewycky77d5fb42014-03-26 23:45:15 +000024define void @test2(i8* sret noalias nocapture %out, i8* %in) nounwind noinline ssp uwtable {
Matt Arsenaultf10061e2017-04-10 20:18:21 +000025 call void @llvm.lifetime.start.p0i8(i64 8, i8* %in)
Daniel Neilson1e687242018-01-19 17:13:12 +000026 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %out, i8* %in, i64 8, i1 false)
Nick Lewycky77d5fb42014-03-26 23:45:15 +000027 ret void
28
29; Check that the memcpy is removed.
30; CHECK-LABEL: @test2(
31; CHECK-NOT: call void @llvm.memcpy
32}
33
34define void @test3(i8* sret noalias nocapture %out, i8* %in) nounwind noinline ssp uwtable {
Matt Arsenaultf10061e2017-04-10 20:18:21 +000035 call void @llvm.lifetime.start.p0i8(i64 4, i8* %in)
Daniel Neilson1e687242018-01-19 17:13:12 +000036 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %out, i8* %in, i64 8, i1 false)
Nick Lewycky77d5fb42014-03-26 23:45:15 +000037 ret void
38
39; Check that the memcpy is not removed.
40; CHECK-LABEL: @test3(
41; CHECK: call void @llvm.memcpy
42}
43
Daniel Neilson1e687242018-01-19 17:13:12 +000044declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
Nick Lewycky99384942014-02-06 06:29:19 +000045
Matt Arsenaultf10061e2017-04-10 20:18:21 +000046declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) nounwind