Work around a FileCheck bug, for now.
[oota-llvm.git] / test / Transforms / GVN / rle.ll
1 ; RUN: opt < %s -gvn -S | FileCheck %s
2
3 ; 32-bit little endian target.
4 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-f80:128:128"
5
6 ;; Trivial RLE test.
7 define i32 @test0(i32 %V, i32* %P) {
8   store i32 %V, i32* %P
9
10   %A = load i32* %P
11   ret i32 %A
12 ; CHECK: @test0
13 ; CHECK: ret i32 %V
14 }
15
16 ;;===----------------------------------------------------------------------===;;
17 ;; Store -> Load  and  Load -> Load forwarding where src and dst are different
18 ;; types, but where the base pointer is a must alias.
19 ;;===----------------------------------------------------------------------===;;
20
21 ;; i32 -> f32 forwarding.
22 define float @coerce_mustalias1(i32 %V, i32* %P) {
23   store i32 %V, i32* %P
24    
25   %P2 = bitcast i32* %P to float*
26
27   %A = load float* %P2
28   ret float %A
29 ; CHECK: @coerce_mustalias1
30 ; CHECK-NOT: load
31 ; CHECK: ret float 
32 }
33
34 ;; i32* -> float forwarding.
35 define float @coerce_mustalias2(i32* %V, i32** %P) {
36   store i32* %V, i32** %P
37    
38   %P2 = bitcast i32** %P to float*
39
40   %A = load float* %P2
41   ret float %A
42 ; CHECK: @coerce_mustalias2
43 ; CHECK-NOT: load
44 ; CHECK: ret float 
45 }
46
47 ;; float -> i32* forwarding.
48 define i32* @coerce_mustalias3(float %V, float* %P) {
49   store float %V, float* %P
50    
51   %P2 = bitcast float* %P to i32**
52
53   %A = load i32** %P2
54   ret i32* %A
55 ; CHECK: @coerce_mustalias3
56 ; CHECK-NOT: load
57 ; CHECK: ret i32* 
58 }
59
60 ;; i32 -> f32 load forwarding.
61 define float @coerce_mustalias4(i32* %P, i1 %cond) {
62   %A = load i32* %P
63   
64   %P2 = bitcast i32* %P to float*
65   %B = load float* %P2
66   br i1 %cond, label %T, label %F
67 T:
68   ret float %B
69   
70 F:
71   %X = bitcast i32 %A to float
72   ret float %X
73
74 ; CHECK: @coerce_mustalias4
75 ; CHECK: %A = load i32* %P
76 ; CHECK: bitcast
77 ; CHECK-NOT: load
78 ; CHECK: ret float
79 ; CHECK: F:
80 }
81
82 ;; i32 -> i8 forwarding
83 define i8 @coerce_mustalias5(i32 %V, i32* %P) {
84   store i32 %V, i32* %P
85    
86   %P2 = bitcast i32* %P to i8*
87
88   %A = load i8* %P2
89   ret i8 %A
90 ; CHECK: @coerce_mustalias5
91 ; CHECK-NOT: load
92 ; CHECK: ret i8
93 }
94
95 ;; i64 -> float forwarding
96 define float @coerce_mustalias6(i64 %V, i64* %P) {
97   store i64 %V, i64* %P
98    
99   %P2 = bitcast i64* %P to float*
100
101   %A = load float* %P2
102   ret float %A
103 ; CHECK: @coerce_mustalias6
104 ; CHECK-NOT: load
105 ; CHECK: ret float
106 }
107
108 ;; i64 -> i8* (32-bit) forwarding
109 define i8* @coerce_mustalias7(i64 %V, i64* %P) {
110   store i64 %V, i64* %P
111    
112   %P2 = bitcast i64* %P to i8**
113
114   %A = load i8** %P2
115   ret i8* %A
116 ; CHECK: @coerce_mustalias7
117 ; CHECK-NOT: load
118 ; CHECK: ret i8*
119 }
120
121 ;; non-local i32/float -> i8 load forwarding.
122 define i8 @coerce_mustalias_nonlocal0(i32* %P, i1 %cond) {
123   %P2 = bitcast i32* %P to float*
124   %P3 = bitcast i32* %P to i8*
125   br i1 %cond, label %T, label %F
126 T:
127   store i32 42, i32* %P
128   br label %Cont
129   
130 F:
131   store float 1.0, float* %P2
132   br label %Cont
133
134 Cont:
135   %A = load i8* %P3
136   ret i8 %A
137
138 ; CHECK: @coerce_mustalias_nonlocal0
139 ; CHECK: Cont:
140 ; CHECK:   %A = phi i8 [
141 ; CHECK-NOT: load
142 ; CHECK: ret i8 %A
143 }
144
145 ;; non-local i32 -> i8 partial redundancy load forwarding.
146 define i8 @coerce_mustalias_pre0(i32* %P, i1 %cond) {
147   %P3 = bitcast i32* %P to i8*
148   br i1 %cond, label %T, label %F
149 T:
150   store i32 42, i32* %P
151   br label %Cont
152   
153 F:
154   br label %Cont
155
156 Cont:
157   %A = load i8* %P3
158   ret i8 %A
159
160 ; CHECK: @coerce_mustalias_pre0
161 ; CHECK: F:
162 ; CHECK:   load i8* %P3
163 ; CHECK: Cont:
164 ; CHECK:   %A = phi i8 [
165 ; CHECK-NOT: load
166 ; CHECK: ret i8 %A
167 }
168