blob: 98e2dddefe7f2863c58080685ea5ca7b24aea59e [file] [log] [blame]
Chris Lattnerdcd44db2007-03-19 00:15:43 +00001; PR1226
Chandler Carrutha5a29f92012-07-02 12:47:22 +00002; RUN: opt < %s -scalarrepl -S | grep "ret i32 16843009"
Dan Gohman18800922009-09-11 18:01:28 +00003; RUN: opt < %s -scalarrepl -S | not grep alloca
Chandler Carrutha5a29f92012-07-02 12:47:22 +00004; RUN: opt < %s -scalarrepl -instcombine -S | grep "ret i16 514"
Chris Lattner2c0f36b2007-03-19 00:09:00 +00005
6target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
7target triple = "i686-apple-darwin8"
8 %struct.bar = type { %struct.foo, i64, double }
9 %struct.foo = type { i32, i32 }
10
Chris Lattner2c0f36b2007-03-19 00:09:00 +000011
12define i32 @test1(%struct.foo* %P) {
13entry:
14 %L = alloca %struct.foo, align 8 ; <%struct.foo*> [#uses=2]
15 %L2 = bitcast %struct.foo* %L to i8* ; <i8*> [#uses=1]
16 %tmp13 = bitcast %struct.foo* %P to i8* ; <i8*> [#uses=1]
Pete Cooper67cf9a72015-11-19 05:56:52 +000017 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %L2, i8* %tmp13, i32 8, i32 4, i1 false)
David Blaikie79e6c742015-02-27 19:29:02 +000018 %tmp4 = getelementptr %struct.foo, %struct.foo* %L, i32 0, i32 0 ; <i32*> [#uses=1]
David Blaikiea79ac142015-02-27 21:17:42 +000019 %tmp5 = load i32, i32* %tmp4 ; <i32> [#uses=1]
Chris Lattner2c0f36b2007-03-19 00:09:00 +000020 ret i32 %tmp5
21}
22
Chris Lattner2c0f36b2007-03-19 00:09:00 +000023
24define i32 @test2() {
25entry:
26 %L = alloca [4 x %struct.foo], align 16 ; <[4 x %struct.foo]*> [#uses=2]
27 %L12 = bitcast [4 x %struct.foo]* %L to i8* ; <i8*> [#uses=1]
Pete Cooper67cf9a72015-11-19 05:56:52 +000028 call void @llvm.memset.p0i8.i32(i8* %L12, i8 0, i32 32, i32 16, i1 false)
David Blaikie79e6c742015-02-27 19:29:02 +000029 %tmp4 = getelementptr [4 x %struct.foo], [4 x %struct.foo]* %L, i32 0, i32 0, i32 0 ; <i32*> [#uses=1]
David Blaikiea79ac142015-02-27 21:17:42 +000030 %tmp5 = load i32, i32* %tmp4 ; <i32> [#uses=1]
Chris Lattner2c0f36b2007-03-19 00:09:00 +000031 ret i32 %tmp5
32}
33
Chris Lattner2c0f36b2007-03-19 00:09:00 +000034
35define i32 @test3() {
36entry:
37 %B = alloca %struct.bar, align 16 ; <%struct.bar*> [#uses=4]
38 %B1 = bitcast %struct.bar* %B to i8* ; <i8*> [#uses=1]
Pete Cooper67cf9a72015-11-19 05:56:52 +000039 call void @llvm.memset.p0i8.i32(i8* %B1, i8 1, i32 24, i32 16, i1 false)
David Blaikie79e6c742015-02-27 19:29:02 +000040 %tmp3 = getelementptr %struct.bar, %struct.bar* %B, i32 0, i32 0, i32 0 ; <i32*> [#uses=1]
Chris Lattner2c0f36b2007-03-19 00:09:00 +000041 store i32 1, i32* %tmp3
David Blaikie79e6c742015-02-27 19:29:02 +000042 %tmp4 = getelementptr %struct.bar, %struct.bar* %B, i32 0, i32 2 ; <double*> [#uses=1]
Chris Lattner2c0f36b2007-03-19 00:09:00 +000043 store double 1.000000e+01, double* %tmp4
David Blaikie79e6c742015-02-27 19:29:02 +000044 %tmp6 = getelementptr %struct.bar, %struct.bar* %B, i32 0, i32 0, i32 1 ; <i32*> [#uses=1]
David Blaikiea79ac142015-02-27 21:17:42 +000045 %tmp7 = load i32, i32* %tmp6 ; <i32> [#uses=1]
Chris Lattner2c0f36b2007-03-19 00:09:00 +000046 ret i32 %tmp7
47}
Chris Lattner6aa6b1f2009-02-03 02:01:43 +000048
49
50 %struct.f = type { i32, i32, i32, i32, i32, i32 }
51
52define i16 @test4() nounwind {
53entry:
54 %A = alloca %struct.f, align 8 ; <%struct.f*> [#uses=3]
David Blaikie79e6c742015-02-27 19:29:02 +000055 %0 = getelementptr %struct.f, %struct.f* %A, i32 0, i32 0 ; <i32*> [#uses=1]
Chris Lattner6aa6b1f2009-02-03 02:01:43 +000056 store i32 1, i32* %0, align 8
David Blaikie79e6c742015-02-27 19:29:02 +000057 %1 = getelementptr %struct.f, %struct.f* %A, i32 0, i32 1 ; <i32*> [#uses=1]
Chris Lattner6aa6b1f2009-02-03 02:01:43 +000058 %2 = bitcast i32* %1 to i8* ; <i8*> [#uses=1]
Pete Cooper67cf9a72015-11-19 05:56:52 +000059 call void @llvm.memset.p0i8.i32(i8* %2, i8 2, i32 12, i32 4, i1 false)
David Blaikie79e6c742015-02-27 19:29:02 +000060 %3 = getelementptr %struct.f, %struct.f* %A, i32 0, i32 2 ; <i32*> [#uses=1]
David Blaikiea79ac142015-02-27 21:17:42 +000061 %4 = load i32, i32* %3, align 8 ; <i32> [#uses=1]
Chris Lattner6aa6b1f2009-02-03 02:01:43 +000062 %retval12 = trunc i32 %4 to i16 ; <i16> [#uses=1]
63 ret i16 %retval12
64}
Pete Cooper67cf9a72015-11-19 05:56:52 +000065declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
Chris Lattner80ed9dc2011-06-18 06:05:24 +000066
Pete Cooper67cf9a72015-11-19 05:56:52 +000067declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) nounwind