For PR1319:
[oota-llvm.git] / test / Transforms / InstCombine / select.ll
1 ; This test makes sure that these instructions are properly eliminated.
2
3 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
4 ; RUN:    not grep select
5 ; END.
6
7 implementation
8
9 int %test1(int %A, int %B) {
10         %C = select bool false, int %A, int %B
11         ret int %C
12 }
13
14 int %test2(int %A, int %B) {
15         %C = select bool true, int %A, int %B
16         ret int %C
17 }
18
19 int %test3(bool %C, int %I) {
20         %V = select bool %C, int %I, int %I         ; V = I
21         ret int %V
22 }
23
24 bool %test4(bool %C) {
25         %V = select bool %C, bool true, bool false  ; V = C
26         ret bool %V
27 }
28
29 bool %test5(bool %C) {
30         %V = select bool %C, bool false, bool true  ; V = !C
31         ret bool %V
32 }
33
34 int %test6(bool %C) {
35         %V = select bool %C, int 1, int 0         ; V = cast C to int
36         ret int %V
37 }
38
39 bool %test7(bool %C, bool %X) {
40         %R = select bool %C, bool true, bool %X    ; R = or C, X
41         ret bool %R
42 }
43
44 bool %test8(bool %C, bool %X) {
45         %R = select bool %C, bool %X, bool false   ; R = and C, X
46         ret bool %R
47 }
48
49 bool %test9(bool %C, bool %X) {
50         %R = select bool %C, bool false, bool %X    ; R = and !C, X
51         ret bool %R
52 }
53
54 bool %test10(bool %C, bool %X) {
55         %R = select bool %C, bool %X, bool true   ; R = or !C, X
56         ret bool %R
57 }
58
59 int %test11(int %a) {
60         %C = seteq int %a, 0
61         %R = select bool %C, int 0, int 1
62         ret int %R
63 }
64
65 int %test12(bool %cond, int %a) {
66         %b = or int %a, 1
67         %c = select bool %cond, int %b, int %a
68         ret int %c
69 }
70
71 int %test12a(bool %cond, int %a) {
72         %b = shr int %a, ubyte 1
73         %c = select bool %cond, int %b, int %a
74         ret int %c
75 }
76
77 int %test12b(bool %cond, int %a) {
78         %b = shr int %a, ubyte 1
79         %c = select bool %cond, int %a, int %b
80         ret int %c
81 }
82
83 int %test13(int %a, int %b) {
84         %C = seteq int %a, %b
85         %V = select bool %C, int %a, int %b
86         ret int %V
87 }
88
89 int %test13a(int %a, int %b) {
90         %C = setne int %a, %b
91         %V = select bool %C, int %a, int %b
92         ret int %V
93 }
94
95 int %test13b(int %a, int %b) {
96         %C = seteq int %a, %b
97         %V = select bool %C, int %b, int %a
98         ret int %V
99 }
100
101 bool %test14a(bool %C, int %X) {
102         %V = select bool %C, int %X, int 0
103         %R = setlt int %V, 1                  ; (X < 1) | !C
104         ret bool %R
105 }
106
107 bool %test14b(bool %C, int %X) {
108         %V = select bool %C, int 0, int %X
109         %R = setlt int %V, 1                  ; (X < 1) | C
110         ret bool %R
111 }
112
113 int %test15a(int %X) {       ;; Code sequence for (X & 16) ? 16 : 0
114         %t1 = and int %X, 16
115         %t2 = seteq int %t1, 0
116         %t3 = select bool %t2, int 0, int 16 ;; X & 16
117         ret int %t3
118 }
119
120 int %test15b(int %X) {       ;; Code sequence for (X & 32) ? 0 : 24
121         %t1 = and int %X, 32
122         %t2 = seteq int %t1, 0
123         %t3 = select bool %t2, int 32, int 0 ;; ~X & 32
124         ret int %t3
125 }
126
127 int %test15c(int %X) {       ;; Alternate code sequence for (X & 16) ? 16 : 0
128         %t1 = and int %X, 16
129         %t2 = seteq int %t1, 16
130         %t3 = select bool %t2, int 16, int 0 ;; X & 16
131         ret int %t3
132 }
133
134 int %test15d(int %X) {       ;; Alternate code sequence for (X & 16) ? 16 : 0
135         %t1 = and int %X, 16
136         %t2 = setne int %t1, 0
137         %t3 = select bool %t2, int 16, int 0 ;; X & 16
138         ret int %t3
139 }
140
141 int %test16(bool %C, int* %P) {
142         %P2 = select bool %C, int* %P, int* null
143         %V = load int* %P2
144         ret int %V
145 }
146
147 bool %test17(int* %X, bool %C) {
148         %R = select bool %C, int* %X, int* null
149         %RV = seteq int* %R, null
150         ret bool %RV
151 }
152
153 int %test18(int %X, int %Y, bool %C) {
154         %R = select bool %C, int %X, int 0
155         %V = div int %Y, %R   ; div Y,X
156         ret int %V
157 }
158
159 int %test19(uint %x) {
160         %tmp = setgt uint %x, 2147483647
161         %retval = select bool %tmp, int -1, int 0
162         ret int %retval
163 }
164
165 int %test20(int %x) {
166         %tmp = setlt int %x, 0
167         %retval = select bool %tmp, int -1, int 0
168         ret int %retval
169 }
170
171 long %test21(int %x) {
172         %tmp = setlt int %x, 0
173         %retval = select bool %tmp, long -1, long 0
174         ret long %retval
175 }
176
177 short %test22(int %x) {
178         %tmp = setlt int %x, 0
179         %retval = select bool %tmp, short -1, short 0
180         ret short %retval
181 }
182