This implements the second half of the fix for PR3290, handling
[oota-llvm.git] / test / Transforms / InstCombine / logical-select.ll
1 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis > %t
2 ; RUN: grep select %t | count 5
3 ; RUN: not grep and %t
4 ; RUN: not grep or %t
5
6 define i32 @foo(i32 %a, i32 %b, i32 %c, i32 %d) nounwind {
7   %e = icmp slt i32 %a, %b
8   %f = sext i1 %e to i32
9   %g = and i32 %c, %f
10   %h = xor i32 %f, -1
11   %i = and i32 %d, %h
12   %j = or i32 %g, %i
13   ret i32 %j
14 }
15 define i32 @bar(i32 %a, i32 %b, i32 %c, i32 %d) nounwind {
16   %e = icmp slt i32 %a, %b
17   %f = sext i1 %e to i32
18   %g = and i32 %c, %f
19   %h = xor i32 %f, -1
20   %i = and i32 %d, %h
21   %j = or i32 %i, %g
22   ret i32 %j
23 }
24 define i32 @goo(i32 %a, i32 %b, i32 %c, i32 %d) nounwind {
25 entry:
26   %0 = icmp slt i32 %a, %b
27   %iftmp.0.0 = select i1 %0, i32 -1, i32 0
28   %1 = and i32 %iftmp.0.0, %c
29   %not = xor i32 %iftmp.0.0, -1
30   %2 = and i32 %not, %d
31   %3 = or i32 %1, %2
32   ret i32 %3
33 }
34 define i32 @poo(i32 %a, i32 %b, i32 %c, i32 %d) nounwind {
35 entry:
36   %0 = icmp slt i32 %a, %b
37   %iftmp.0.0 = select i1 %0, i32 -1, i32 0
38   %1 = and i32 %iftmp.0.0, %c
39   %iftmp = select i1 %0, i32 0, i32 -1
40   %2 = and i32 %iftmp, %d
41   %3 = or i32 %1, %2
42   ret i32 %3
43 }
44
45 define i32 @par(i32 %a, i32 %b, i32 %c, i32 %d) nounwind {
46 entry:
47   %0 = icmp slt i32 %a, %b
48   %iftmp.1.0 = select i1 %0, i32 -1, i32 0
49   %1 = and i32 %iftmp.1.0, %c
50   %not = xor i32 %iftmp.1.0, -1
51   %2 = and i32 %not, %d
52   %3 = or i32 %1, %2
53   ret i32 %3
54 }