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. |
| 4 | ; RUN: llvm-as < %s | llc -march=x86 | grep {\\(and\\)\\|\\(test.*\\\$1\\)} | \ |
| 5 | ; RUN: wc -l | grep 6 |
| 6 | |
Reid Spencer | f234bed | 2007-07-19 23:13:04 +0000 | [diff] [blame] | 7 | define i1 @test1(i32 %X) zeroext { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 8 | %Y = trunc i32 %X to i1 |
| 9 | ret i1 %Y |
| 10 | } |
| 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 | } |
| 23 | |
| 24 | define i32 @test3(i8* %ptr) { |
| 25 | %val = load i8* %ptr |
| 26 | %tmp = trunc i8 %val to i1 |
| 27 | br i1 %tmp, label %cond_true, label %cond_false |
| 28 | cond_true: |
| 29 | ret i32 21 |
| 30 | cond_false: |
| 31 | ret i32 42 |
| 32 | } |
| 33 | |
| 34 | define i32 @test4(i8* %ptr) { |
| 35 | %tmp = ptrtoint i8* %ptr to i1 |
| 36 | br i1 %tmp, label %cond_true, label %cond_false |
| 37 | cond_true: |
| 38 | ret i32 21 |
| 39 | cond_false: |
| 40 | ret i32 42 |
| 41 | } |
| 42 | |
| 43 | define i32 @test5(float %f) { |
| 44 | %tmp = fptoui float %f to i1 |
| 45 | br i1 %tmp, label %cond_true, label %cond_false |
| 46 | cond_true: |
| 47 | ret i32 21 |
| 48 | cond_false: |
| 49 | ret i32 42 |
| 50 | } |
| 51 | |
| 52 | define i32 @test6(double %d) { |
| 53 | %tmp = fptosi double %d to i1 |
| 54 | br i1 %tmp, label %cond_true, label %cond_false |
| 55 | cond_true: |
| 56 | ret i32 21 |
| 57 | cond_false: |
| 58 | ret i32 42 |
| 59 | } |
| 60 | |