fix rdar://9289583 - fast isel should handle non-canonical commutative binops
[oota-llvm.git] / test / Transforms / ScalarRepl / memset-aggregate.ll
1 ; PR1226
2 ; RUN: opt < %s -scalarrepl -S | grep {ret i32 16843009}
3 ; RUN: opt < %s -scalarrepl -S | not grep alloca
4 ; RUN: opt < %s -scalarrepl -instcombine -S | grep {ret i16 514}
5
6 target 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"
7 target triple = "i686-apple-darwin8"
8         %struct.bar = type { %struct.foo, i64, double }
9         %struct.foo = type { i32, i32 }
10
11
12 define i32 @test1(%struct.foo* %P) {
13 entry:
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]
17         call void @llvm.memcpy.i32( i8* %L2, i8* %tmp13, i32 8, i32 4 )
18         %tmp4 = getelementptr %struct.foo* %L, i32 0, i32 0             ; <i32*> [#uses=1]
19         %tmp5 = load i32* %tmp4         ; <i32> [#uses=1]
20         ret i32 %tmp5
21 }
22
23 declare void @llvm.memcpy.i32(i8*, i8*, i32, i32)
24
25 define i32 @test2() {
26 entry:
27         %L = alloca [4 x %struct.foo], align 16         ; <[4 x %struct.foo]*> [#uses=2]
28         %L12 = bitcast [4 x %struct.foo]* %L to i8*             ; <i8*> [#uses=1]
29         call void @llvm.memset.i32( i8* %L12, i8 0, i32 32, i32 16 )
30         %tmp4 = getelementptr [4 x %struct.foo]* %L, i32 0, i32 0, i32 0                ; <i32*> [#uses=1]
31         %tmp5 = load i32* %tmp4         ; <i32> [#uses=1]
32         ret i32 %tmp5
33 }
34
35 declare void @llvm.memset.i32(i8*, i8, i32, i32)
36
37 define i32 @test3() {
38 entry:
39         %B = alloca %struct.bar, align 16               ; <%struct.bar*> [#uses=4]
40         %B1 = bitcast %struct.bar* %B to i8*            ; <i8*> [#uses=1]
41         call void @llvm.memset.i32( i8* %B1, i8 1, i32 24, i32 16 )
42         %tmp3 = getelementptr %struct.bar* %B, i32 0, i32 0, i32 0              ; <i32*> [#uses=1]
43         store i32 1, i32* %tmp3
44         %tmp4 = getelementptr %struct.bar* %B, i32 0, i32 2             ; <double*> [#uses=1]
45         store double 1.000000e+01, double* %tmp4
46         %tmp6 = getelementptr %struct.bar* %B, i32 0, i32 0, i32 1              ; <i32*> [#uses=1]
47         %tmp7 = load i32* %tmp6         ; <i32> [#uses=1]
48         ret i32 %tmp7
49 }
50
51
52         %struct.f = type { i32, i32, i32, i32, i32, i32 }
53
54 define i16 @test4() nounwind {
55 entry:
56         %A = alloca %struct.f, align 8          ; <%struct.f*> [#uses=3]
57         %0 = getelementptr %struct.f* %A, i32 0, i32 0          ; <i32*> [#uses=1]
58         store i32 1, i32* %0, align 8
59         %1 = getelementptr %struct.f* %A, i32 0, i32 1          ; <i32*> [#uses=1]
60         %2 = bitcast i32* %1 to i8*             ; <i8*> [#uses=1]
61         call void @llvm.memset.i32(i8* %2, i8 2, i32 12, i32 4)
62         %3 = getelementptr %struct.f* %A, i32 0, i32 2          ; <i32*> [#uses=1]
63         %4 = load i32* %3, align 8              ; <i32> [#uses=1]
64         %retval12 = trunc i32 %4 to i16         ; <i16> [#uses=1]
65         ret i16 %retval12
66 }