Dan Gohman | b75e864 | 2010-01-04 20:53:54 +0000 | [diff] [blame] | 1 | ; RUN: llc < %s -march=x86-64 -o - | FileCheck %s |
| 2 | |
| 3 | ; Reuse the flags value from the add instructions instead of emitting separate |
| 4 | ; testl instructions. |
| 5 | |
| 6 | ; Use the flags on the add. |
| 7 | |
Chris Lattner | 1beaf41 | 2010-03-05 06:17:43 +0000 | [diff] [blame^] | 8 | ; CHECK: test1: |
Dan Gohman | b75e864 | 2010-01-04 20:53:54 +0000 | [diff] [blame] | 9 | ; CHECK: addl (%rdi), %esi |
| 10 | ; CHECK-NEXT: movl %edx, %eax |
| 11 | ; CHECK-NEXT: cmovnsl %ecx, %eax |
| 12 | ; CHECK-NEXT: ret |
| 13 | |
Chris Lattner | 1beaf41 | 2010-03-05 06:17:43 +0000 | [diff] [blame^] | 14 | define i32 @test1(i32* %x, i32 %y, i32 %a, i32 %b) nounwind { |
Dan Gohman | b75e864 | 2010-01-04 20:53:54 +0000 | [diff] [blame] | 15 | %tmp2 = load i32* %x, align 4 ; <i32> [#uses=1] |
| 16 | %tmp4 = add i32 %tmp2, %y ; <i32> [#uses=1] |
| 17 | %tmp5 = icmp slt i32 %tmp4, 0 ; <i1> [#uses=1] |
| 18 | %tmp.0 = select i1 %tmp5, i32 %a, i32 %b ; <i32> [#uses=1] |
| 19 | ret i32 %tmp.0 |
| 20 | } |
| 21 | |
| 22 | declare void @foo(i32) |
| 23 | |
| 24 | ; Don't use the flags result of the and here, since the and has no |
| 25 | ; other use. A simple test is better. |
| 26 | |
Chris Lattner | 1beaf41 | 2010-03-05 06:17:43 +0000 | [diff] [blame^] | 27 | ; CHECK: test2: |
Dan Gohman | b75e864 | 2010-01-04 20:53:54 +0000 | [diff] [blame] | 28 | ; CHECK: testb $16, %dil |
| 29 | |
Chris Lattner | 1beaf41 | 2010-03-05 06:17:43 +0000 | [diff] [blame^] | 30 | define void @test2(i32 %x) nounwind { |
Dan Gohman | b75e864 | 2010-01-04 20:53:54 +0000 | [diff] [blame] | 31 | %y = and i32 %x, 16 |
| 32 | %t = icmp eq i32 %y, 0 |
| 33 | br i1 %t, label %true, label %false |
| 34 | true: |
| 35 | call void @foo(i32 %x) |
| 36 | ret void |
| 37 | false: |
| 38 | ret void |
| 39 | } |
| 40 | |
| 41 | ; Do use the flags result of the and here, since the and has another use. |
| 42 | |
Chris Lattner | 1beaf41 | 2010-03-05 06:17:43 +0000 | [diff] [blame^] | 43 | ; CHECK: test3: |
Dan Gohman | b75e864 | 2010-01-04 20:53:54 +0000 | [diff] [blame] | 44 | ; CHECK: andl $16, %edi |
Dan Gohman | c12e979 | 2010-01-04 21:23:34 +0000 | [diff] [blame] | 45 | ; CHECK-NEXT: jne |
Dan Gohman | b75e864 | 2010-01-04 20:53:54 +0000 | [diff] [blame] | 46 | |
Chris Lattner | 1beaf41 | 2010-03-05 06:17:43 +0000 | [diff] [blame^] | 47 | define void @test3(i32 %x) nounwind { |
Dan Gohman | b75e864 | 2010-01-04 20:53:54 +0000 | [diff] [blame] | 48 | %y = and i32 %x, 16 |
| 49 | %t = icmp eq i32 %y, 0 |
| 50 | br i1 %t, label %true, label %false |
| 51 | true: |
| 52 | call void @foo(i32 %y) |
| 53 | ret void |
| 54 | false: |
| 55 | ret void |
| 56 | } |