blob: 0be572577cb6d9600b4464d44ee8cb647284d734 [file] [log] [blame]
Chris Lattnerfd747f82004-03-12 06:01:00 +00001; This test makes sure that these instructions are properly eliminated.
2;
3
4; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep select
5
6implementation
7
8int %test1(int %A, int %B) {
9 %C = select bool false, int %A, int %B
10 ret int %C
11}
12
13int %test2(int %A, int %B) {
14 %C = select bool true, int %A, int %B
15 ret int %C
16}
17
Chris Lattnerb785d282004-03-30 19:36:54 +000018int %test3(bool %C, int %I) {
19 %V = select bool %C, int %I, int %I ; V = I
20 ret int %V
21}
22
23bool %test4(bool %C) {
24 %V = select bool %C, bool true, bool false ; V = C
25 ret bool %V
26}
27
28bool %test5(bool %C) {
29 %V = select bool %C, bool false, bool true ; V = !C
30 ret bool %V
31}
32
33int %test6(bool %C) {
34 %V = select bool %C, int 1, int 0 ; V = cast C to int
35 ret int %V
36}
Chris Lattnerfd747f82004-03-12 06:01:00 +000037
Chris Lattnerac42fd52004-04-08 04:43:04 +000038bool %test7(bool %C, bool %X) {
39 %R = select bool %C, bool true, bool %X ; R = or C, X
40 ret bool %R
41}
42
43bool %test8(bool %C, bool %X) {
44 %R = select bool %C, bool %X, bool false ; R = and C, X
45 ret bool %R
46}
47
48bool %test9(bool %C, bool %X) {
49 %R = select bool %C, bool false, bool %X ; R = and !C, X
50 ret bool %R
51}
52
53bool %test10(bool %C, bool %X) {
54 %R = select bool %C, bool %X, bool true ; R = or !C, X
55 ret bool %R
56}
Chris Lattner755cab22004-04-09 18:19:29 +000057
58int %test11(int %a) {
59 %C = seteq int %a, 0
60 %R = select bool %C, int 0, int 1
61 ret int %R
62}
63
Chris Lattnerbe68fd02004-04-09 23:43:48 +000064int %test12(bool %cond, int %a) {
65 %b = or int %a, 1
66 %c = select bool %cond, int %b, int %a
67 ret int %c
68}
69
70int %test12a(bool %cond, int %a) {
71 %b = shr int %a, ubyte 1
72 %c = select bool %cond, int %b, int %a
73 ret int %c
74}
75
76int %test12b(bool %cond, int %a) {
77 %b = shr int %a, ubyte 1
78 %c = select bool %cond, int %a, int %b
79 ret int %c
80}
81
Chris Lattner1f99df62004-04-10 22:21:14 +000082int %test13(int %a, int %b) {
83 %C = seteq int %a, %b
84 %V = select bool %C, int %a, int %b
85 ret int %V
86}
87
88int %test13a(int %a, int %b) {
89 %C = setne int %a, %b
90 %V = select bool %C, int %a, int %b
91 ret int %V
92}
93
94int %test13b(int %a, int %b) {
95 %C = seteq int %a, %b
96 %V = select bool %C, int %b, int %a
97 ret int %V
98}
Chris Lattner52d74302004-06-09 04:23:57 +000099
100bool %test14a(bool %C, int %X) {
101 %V = select bool %C, int %X, int 0
102 %R = setlt int %V, 1 ; (X < 1) | !C
103 ret bool %R
104}
105
106bool %test14b(bool %C, int %X) {
107 %V = select bool %C, int 0, int %X
108 %R = setlt int %V, 1 ; (X < 1) | C
109 ret bool %R
110}
111
Chris Lattnerce527c82004-06-09 07:59:40 +0000112int %test15a(int %X) { ;; Code sequence for (X & 16) ? 16 : 0
113 %t1 = and int %X, 16
114 %t2 = seteq int %t1, 0
115 %t3 = select bool %t2, int 0, int 16 ;; X & 16
116 ret int %t3
117}
118
119int %test15b(int %X) { ;; Code sequence for (X & 32) ? 0 : 24
120 %t1 = and int %X, 32
121 %t2 = seteq int %t1, 0
122 %t3 = select bool %t2, int 32, int 0 ;; ~X & 32
123 ret int %t3
124}
125
126int %test15c(int %X) { ;; Alternate code sequence for (X & 16) ? 16 : 0
127 %t1 = and int %X, 16
128 %t2 = seteq int %t1, 16
129 %t3 = select bool %t2, int 16, int 0 ;; X & 16
130 ret int %t3
131}
132
133int %test15d(int %X) { ;; Alternate code sequence for (X & 16) ? 16 : 0
134 %t1 = and int %X, 16
135 %t2 = setne int %t1, 0
136 %t3 = select bool %t2, int 16, int 0 ;; X & 16
137 ret int %t3
138}
Chris Lattnerfb473592004-09-23 15:45:20 +0000139
140int %test16(bool %C, int* %P) {
141 %P2 = select bool %C, int* %P, int* null
142 %V = load int* %P2
143 ret int %V
144}