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