2006-11-27 01:05:10 +00:00
|
|
|
; 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.
|
2006-12-31 06:02:00 +00:00
|
|
|
; RUN: llvm-as < %s | llc -march=x86 &&
|
|
|
|
; RUN: llvm-as < %s | llc -march=x86 | grep '\(and\)\|\(test.*\$1\)' | \
|
|
|
|
; RUN: wc -l | grep 6
|
|
|
|
|
2007-01-05 18:35:52 +00:00
|
|
|
define bool %test1(i32 %X) zext {
|
2006-12-31 06:02:00 +00:00
|
|
|
%Y = trunc i32 %X to bool
|
2006-11-27 01:05:10 +00:00
|
|
|
ret bool %Y
|
|
|
|
}
|
|
|
|
|
2006-12-31 06:02:00 +00:00
|
|
|
define bool %test2(i32 %val, i32 %mask) {
|
2006-11-27 01:05:10 +00:00
|
|
|
entry:
|
2006-12-31 06:02:00 +00:00
|
|
|
%mask = trunc i32 %mask to i8
|
|
|
|
%shifted = ashr i32 %val, i8 %mask
|
|
|
|
%anded = and i32 %shifted, 1
|
|
|
|
%trunced = trunc i32 %anded to bool
|
2006-11-27 01:05:10 +00:00
|
|
|
br bool %trunced, label %ret_true, label %ret_false
|
|
|
|
ret_true:
|
|
|
|
ret bool true
|
|
|
|
ret_false:
|
|
|
|
ret bool false
|
|
|
|
}
|
|
|
|
|
2006-12-31 06:02:00 +00:00
|
|
|
define i32 %test3(i8* %ptr) {
|
|
|
|
%val = load i8* %ptr
|
|
|
|
%tmp = trunc i8 %val to bool
|
2006-11-27 01:05:10 +00:00
|
|
|
br bool %tmp, label %cond_true, label %cond_false
|
|
|
|
cond_true:
|
2006-12-31 06:02:00 +00:00
|
|
|
ret i32 21
|
2006-11-27 01:05:10 +00:00
|
|
|
cond_false:
|
2006-12-31 06:02:00 +00:00
|
|
|
ret i32 42
|
2006-11-27 01:05:10 +00:00
|
|
|
}
|
2006-11-27 19:54:23 +00:00
|
|
|
|
2006-12-31 06:02:00 +00:00
|
|
|
define i32 %test4(i8* %ptr) {
|
|
|
|
%tmp = ptrtoint i8* %ptr to bool
|
2006-11-27 19:54:23 +00:00
|
|
|
br bool %tmp, label %cond_true, label %cond_false
|
|
|
|
cond_true:
|
2006-12-31 06:02:00 +00:00
|
|
|
ret i32 21
|
2006-11-27 19:54:23 +00:00
|
|
|
cond_false:
|
2006-12-31 06:02:00 +00:00
|
|
|
ret i32 42
|
2006-11-27 19:54:23 +00:00
|
|
|
}
|
|
|
|
|
2006-12-31 06:02:00 +00:00
|
|
|
define i32 %test5(float %f) {
|
2006-11-27 19:54:23 +00:00
|
|
|
%tmp = fptoui float %f to bool
|
|
|
|
br bool %tmp, label %cond_true, label %cond_false
|
|
|
|
cond_true:
|
2006-12-31 06:02:00 +00:00
|
|
|
ret i32 21
|
2006-11-27 19:54:23 +00:00
|
|
|
cond_false:
|
2006-12-31 06:02:00 +00:00
|
|
|
ret i32 42
|
2006-11-27 19:54:23 +00:00
|
|
|
}
|
|
|
|
|
2006-12-31 06:02:00 +00:00
|
|
|
define i32 %test6(double %d) {
|
2006-11-27 19:54:23 +00:00
|
|
|
%tmp = fptosi double %d to bool
|
|
|
|
br bool %tmp, label %cond_true, label %cond_false
|
|
|
|
cond_true:
|
2006-12-31 06:02:00 +00:00
|
|
|
ret i32 21
|
2006-11-27 19:54:23 +00:00
|
|
|
cond_false:
|
2006-12-31 06:02:00 +00:00
|
|
|
ret i32 42
|
2006-11-27 19:54:23 +00:00
|
|
|
}
|
2006-12-31 06:02:00 +00:00
|
|
|
|