summaryrefslogtreecommitdiff
path: root/test/CodeGen/X86/trunc-to-bool.ll
blob: 3e00975b249fd42c59b0f4386c31458529354e06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
; An integer truncation to bool should be done with an and instruction to make
; sure only the LSBit survives. Test that this is the case both for a returned
; value and as the operand of a branch.
; RUN: llvm-upgrade < %s | llvm-as | llc -march=x86 &&
; RUN: llvm-upgrade < %s | llvm-as | llc -march=x86 | grep '\(and\)\|\(test.*\$1\)' | wc -l | grep 6
bool %test1(int %X) {
    %Y = trunc int %X to bool
    ret bool %Y
}

bool %test2(int %val, int %mask) {
entry:
    %mask     = trunc int %mask to ubyte
    %shifted  = ashr int %val, ubyte %mask
    %anded    = and int %shifted, 1
    %trunced  = trunc int %anded to bool
    br bool %trunced, label %ret_true, label %ret_false
ret_true:
    ret bool true
ret_false:
    ret bool false
}

int %test3(sbyte* %ptr) {
    %val = load sbyte* %ptr
    %tmp = trunc sbyte %val to bool             ; %<bool> [#uses=1]
    br bool %tmp, label %cond_true, label %cond_false
cond_true:
    ret int 21
cond_false:
    ret int 42
}

int %test4(sbyte* %ptr) {
    %tmp = ptrtoint sbyte* %ptr to bool
    br bool %tmp, label %cond_true, label %cond_false
cond_true:
    ret int 21
cond_false:
    ret int 42
}

int %test5(float %f) {
    %tmp = fptoui float %f to bool
    br bool %tmp, label %cond_true, label %cond_false
cond_true:
    ret int 21
cond_false:
    ret int 42
}

int %test6(double %d) {
    %tmp = fptosi double %d to bool
    br bool %tmp, label %cond_true, label %cond_false
cond_true:
    ret int 21
cond_false:
    ret int 42
}