Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 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. |
Edward O'Callaghan | bebe181 | 2009-11-22 11:45:44 +0000 | [diff] [blame] | 4 | ; RUN: llc < %s -march=x86 | FileCheck %s |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 5 | |
Reid Spencer | f234bed | 2007-07-19 23:13:04 +0000 | [diff] [blame] | 6 | define i1 @test1(i32 %X) zeroext { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | %Y = trunc i32 %X to i1 |
| 8 | ret i1 %Y |
| 9 | } |
Edward O'Callaghan | bebe181 | 2009-11-22 11:45:44 +0000 | [diff] [blame] | 10 | ; CHECK: andl $1, %eax |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 11 | |
| 12 | define i1 @test2(i32 %val, i32 %mask) { |
| 13 | entry: |
| 14 | %shifted = ashr i32 %val, %mask |
| 15 | %anded = and i32 %shifted, 1 |
| 16 | %trunced = trunc i32 %anded to i1 |
| 17 | br i1 %trunced, label %ret_true, label %ret_false |
| 18 | ret_true: |
| 19 | ret i1 true |
| 20 | ret_false: |
| 21 | ret i1 false |
| 22 | } |
Edward O'Callaghan | bebe181 | 2009-11-22 11:45:44 +0000 | [diff] [blame] | 23 | ; CHECK: testb $1, %al |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 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 | } |
Edward O'Callaghan | bebe181 | 2009-11-22 11:45:44 +0000 | [diff] [blame] | 34 | ; CHECK: testb $1, %al |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 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 | } |
Edward O'Callaghan | bebe181 | 2009-11-22 11:45:44 +0000 | [diff] [blame] | 44 | ; CHECK: testb $1, %al |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 45 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 46 | define i32 @test6(double %d) { |
| 47 | %tmp = fptosi double %d to i1 |
| 48 | br i1 %tmp, label %cond_true, label %cond_false |
| 49 | cond_true: |
| 50 | ret i32 21 |
| 51 | cond_false: |
| 52 | ret i32 42 |
| 53 | } |
Benjamin Kramer | f6ddf79 | 2009-11-22 15:15:52 +0000 | [diff] [blame] | 54 | ; CHECK: testb $1 |