new testcase
[oota-llvm.git] / test / Transforms / InstCombine / load.ll
1 ; This test makes sure that these instructions are properly eliminated.
2 ;
3
4 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep load
5
6 %X = constant int 42
7 %X2 = constant int 47
8 %Y = constant [2 x { int, float }] [ { int, float } { int 12, float 1.0 }, 
9                                      { int, float } { int 37, float 1.2312 } ]
10 %Z = constant [2 x { int, float }] zeroinitializer
11
12 int %test1() {
13         %B = load int* %X
14         ret int %B
15 }
16
17 float %test2() {
18         %A = getelementptr [2 x { int, float}]* %Y, long 0, long 1, ubyte 1
19         %B = load float* %A
20         ret float %B
21 }
22
23
24 int %test3() {
25         %A = getelementptr [2 x { int, float}]* %Y, long 0, long 0, ubyte 0
26         %B = load int* %A
27         ret int %B
28 }
29
30 int %test4() {
31         %A = getelementptr [2 x { int, float}]* %Z, long 0, long 1, ubyte 0
32         %B = load int* %A
33         ret int %B
34 }
35
36 ; load (select (Cond, &V1, &V2))  --> select(Cond, load &V1, load &V2)
37 int %test5(bool %C) {
38         %Y = select bool %C, int* %X, int* %X2
39         %Z = load int* %Y
40         ret int %Z
41 }
42
43 ; load (phi (&V1, &V2, &V3))  --> phi(load &V1, load &V2, load &V3)
44 int %test6(bool %C) {
45 entry:
46         br bool %C, label %cond_true.i, label %cond_continue.i
47
48 cond_true.i:
49         br label %cond_continue.i
50
51 cond_continue.i:
52         %mem_tmp.i.0 = phi int* [ %X, %cond_true.i ], [ %X2, %entry ]
53         %tmp.3 = load int* %mem_tmp.i.0
54         ret int %tmp.3
55 }
56
57 int %test7(int %X) {
58         %V = getelementptr int* null, int %X
59         %R = load int* %V
60         ret int %R
61 }
62
63 int %test8(int* %P) {
64         store int 1, int* %P
65         %X = load int* %P        ;; Trivial store->load forwarding
66         ret int %X
67 }
68
69 int %test9(int* %P) {
70         %X = load int* %P        ;; Trivial load cse
71         %Y = load int* %P
72         %Z = sub int %X, %Y
73         ret int %Z
74 }