736a7e40ecc3ee93c90a4c9175fa74a38e68a205
[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-NOT: load
77 ; CHECK: ret float
78 ; CHECK: F:
79 }
80
81 ;; i32 -> i8 forwarding
82 define i8 @coerce_mustalias5(i32 %V, i32* %P) {
83   store i32 %V, i32* %P
84    
85   %P2 = bitcast i32* %P to i8*
86
87   %A = load i8* %P2
88   ret i8 %A
89 ; CHECK: @coerce_mustalias5
90 ; CHECK-NOT: load
91 ; CHECK: ret i8
92 }
93
94 ;; i64 -> float forwarding
95 define float @coerce_mustalias6(i64 %V, i64* %P) {
96   store i64 %V, i64* %P
97    
98   %P2 = bitcast i64* %P to float*
99
100   %A = load float* %P2
101   ret float %A
102 ; CHECK: @coerce_mustalias6
103 ; CHECK-NOT: load
104 ; CHECK: ret float
105 }
106
107 ;; i64 -> i8* (32-bit) forwarding
108 define i8* @coerce_mustalias7(i64 %V, i64* %P) {
109   store i64 %V, i64* %P
110    
111   %P2 = bitcast i64* %P to i8**
112
113   %A = load i8** %P2
114   ret i8* %A
115 ; CHECK: @coerce_mustalias7
116 ; CHECK-NOT: load
117 ; CHECK: ret i8*
118 }
119
120 ;; non-local i32/float -> i8 load forwarding.
121 define i8 @coerce_mustalias_nonlocal0(i32* %P, i1 %cond) {
122   %P2 = bitcast i32* %P to float*
123   %P3 = bitcast i32* %P to i8*
124   br i1 %cond, label %T, label %F
125 T:
126   store i32 42, i32* %P
127   br label %Cont
128   
129 F:
130   store float 1.0, float* %P2
131   br label %Cont
132
133 Cont:
134   %A = load i8* %P3
135   ret i8 %A
136
137 ; CHECK: @coerce_mustalias_nonlocal0
138 ; CHECK: Cont:
139 ; CHECK:   %A = phi i8 [
140 ; CHECK-NOT: load
141 ; CHECK: ret i8 %A
142 }
143
144 ;; non-local i32/float -> i8 load forwarding.  This also tests that the "P3"
145 ;; bitcast equivalence can be properly phi translated.
146 define i8 @coerce_mustalias_nonlocal1(i32* %P, i1 %cond) {
147   %P2 = bitcast i32* %P to float*
148   br i1 %cond, label %T, label %F
149 T:
150   store i32 42, i32* %P
151   br label %Cont
152   
153 F:
154   store float 1.0, float* %P2
155   br label %Cont
156
157 Cont:
158   %P3 = bitcast i32* %P to i8*
159   %A = load i8* %P3
160   ret i8 %A
161
162 ;; FIXME: This is disabled because this caused a miscompile in the llvm-gcc
163 ;; bootstrap, see r82411
164 ;
165 ; HECK: @coerce_mustalias_nonlocal1
166 ; HECK: Cont:
167 ; HECK:   %A = phi i8 [
168 ; HECK-NOT: load
169 ; HECK: ret i8 %A
170 }
171
172
173 ;; non-local i32 -> i8 partial redundancy load forwarding.
174 define i8 @coerce_mustalias_pre0(i32* %P, i1 %cond) {
175   %P3 = bitcast i32* %P to i8*
176   br i1 %cond, label %T, label %F
177 T:
178   store i32 42, i32* %P
179   br label %Cont
180   
181 F:
182   br label %Cont
183
184 Cont:
185   %A = load i8* %P3
186   ret i8 %A
187
188 ; CHECK: @coerce_mustalias_pre0
189 ; CHECK: F:
190 ; CHECK:   load i8* %P3
191 ; CHECK: Cont:
192 ; CHECK:   %A = phi i8 [
193 ; CHECK-NOT: load
194 ; CHECK: ret i8 %A
195 }
196
197 ;;===----------------------------------------------------------------------===;;
198 ;; Store -> Load  and  Load -> Load forwarding where src and dst are different
199 ;; types, and the reload is an offset from the store pointer.
200 ;;===----------------------------------------------------------------------===;;
201
202 ;; i32 -> f32 forwarding.
203 define i8 @coerce_offset0(i32 %V, i32* %P) {
204   store i32 %V, i32* %P
205    
206   %P2 = bitcast i32* %P to i8*
207   %P3 = getelementptr i8* %P2, i32 2
208
209   %A = load i8* %P3
210   ret i8 %A
211 ; CHECK: @coerce_offset0
212 ; CHECK-NOT: load
213 ; CHECK: ret i8
214 }
215
216
217