a9ac6c1b297c4fc18d664f0470bf07b2b0054aab
[oota-llvm.git] / test / CodeGen / X86 / trunc-to-bool.ll
1 ; An integer truncation to i1 should be done with an and instruction to make
2 ; sure only the LSBit survives. Test that this is the case both for a returned
3 ; value and as the operand of a branch.
4 ; RUN: llvm-as < %s | llc -march=x86 &&
5 ; RUN: llvm-as < %s | llc -march=x86 | grep '\(and\)\|\(test.*\$1\)' | \
6 ; RUN:   wc -l | grep 6
7
8 define i1 %test1(i32 %X) zext {
9     %Y = trunc i32 %X to i1
10     ret i1 %Y
11 }
12
13 define i1 %test2(i32 %val, i32 %mask) {
14 entry:
15     %mask = trunc i32 %mask to i8
16     %shifted = ashr i32 %val, i8 %mask
17     %anded = and i32 %shifted, 1
18     %trunced = trunc i32 %anded to i1
19     br i1 %trunced, label %ret_true, label %ret_false
20 ret_true:
21     ret i1 true
22 ret_false:
23     ret i1 false
24 }
25
26 define i32 %test3(i8* %ptr) {
27     %val = load i8* %ptr
28     %tmp = trunc i8 %val to i1
29     br i1 %tmp, label %cond_true, label %cond_false
30 cond_true:
31     ret i32 21
32 cond_false:
33     ret i32 42
34 }
35
36 define i32 %test4(i8* %ptr) {
37     %tmp = ptrtoint i8* %ptr to i1
38     br i1 %tmp, label %cond_true, label %cond_false
39 cond_true:
40     ret i32 21
41 cond_false:
42     ret i32 42
43 }
44
45 define i32 %test5(float %f) {
46     %tmp = fptoui float %f to i1
47     br i1 %tmp, label %cond_true, label %cond_false
48 cond_true:
49     ret i32 21
50 cond_false:
51     ret i32 42
52 }
53
54 define i32 %test6(double %d) {
55     %tmp = fptosi double %d to i1
56     br i1 %tmp, label %cond_true, label %cond_false
57 cond_true:
58     ret i32 21
59 cond_false:
60     ret i32 42
61 }
62