fix a FileCheck bug where:
[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 -> i8 partial redundancy load forwarding.
145 define i8 @coerce_mustalias_pre0(i32* %P, i1 %cond) {
146   %P3 = bitcast i32* %P to i8*
147   br i1 %cond, label %T, label %F
148 T:
149   store i32 42, i32* %P
150   br label %Cont
151   
152 F:
153   br label %Cont
154
155 Cont:
156   %A = load i8* %P3
157   ret i8 %A
158
159 ; CHECK: @coerce_mustalias_pre0
160 ; CHECK: F:
161 ; CHECK:   load i8* %P3
162 ; CHECK: Cont:
163 ; CHECK:   %A = phi i8 [
164 ; CHECK-NOT: load
165 ; CHECK: ret i8 %A
166 }
167