667fc2f3d3c8082d84fd479bcab353b6942de54d
[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     %shifted = ashr i32 %val, %mask
16     %anded = and i32 %shifted, 1
17     %trunced = trunc i32 %anded to i1
18     br i1 %trunced, label %ret_true, label %ret_false
19 ret_true:
20     ret i1 true
21 ret_false:
22     ret i1 false
23 }
24
25 define i32 @test3(i8* %ptr) {
26     %val = load i8* %ptr
27     %tmp = trunc i8 %val to i1
28     br i1 %tmp, label %cond_true, label %cond_false
29 cond_true:
30     ret i32 21
31 cond_false:
32     ret i32 42
33 }
34
35 define i32 @test4(i8* %ptr) {
36     %tmp = ptrtoint i8* %ptr to i1
37     br i1 %tmp, label %cond_true, label %cond_false
38 cond_true:
39     ret i32 21
40 cond_false:
41     ret i32 42
42 }
43
44 define i32 @test5(float %f) {
45     %tmp = fptoui float %f to i1
46     br i1 %tmp, label %cond_true, label %cond_false
47 cond_true:
48     ret i32 21
49 cond_false:
50     ret i32 42
51 }
52
53 define i32 @test6(double %d) {
54     %tmp = fptosi double %d to i1
55     br i1 %tmp, label %cond_true, label %cond_false
56 cond_true:
57     ret i32 21
58 cond_false:
59     ret i32 42
60 }
61