blob: c2f0c23fe1d3e30831d65c5fb27fddfc6e89919b [file] [log] [blame]
Dan Gohmanb75e8642010-01-04 20:53:54 +00001; 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 Lattner1beaf412010-03-05 06:17:43 +00008; CHECK: test1:
Dan Gohmanb75e8642010-01-04 20:53:54 +00009; CHECK: addl (%rdi), %esi
10; CHECK-NEXT: movl %edx, %eax
11; CHECK-NEXT: cmovnsl %ecx, %eax
12; CHECK-NEXT: ret
13
Chris Lattner1beaf412010-03-05 06:17:43 +000014define i32 @test1(i32* %x, i32 %y, i32 %a, i32 %b) nounwind {
Dan Gohmanb75e8642010-01-04 20:53:54 +000015 %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
22declare 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 Lattner1beaf412010-03-05 06:17:43 +000027; CHECK: test2:
Dan Gohmanb75e8642010-01-04 20:53:54 +000028; CHECK: testb $16, %dil
29
Chris Lattner1beaf412010-03-05 06:17:43 +000030define void @test2(i32 %x) nounwind {
Dan Gohmanb75e8642010-01-04 20:53:54 +000031 %y = and i32 %x, 16
32 %t = icmp eq i32 %y, 0
33 br i1 %t, label %true, label %false
34true:
35 call void @foo(i32 %x)
36 ret void
37false:
38 ret void
39}
40
41; Do use the flags result of the and here, since the and has another use.
42
Chris Lattner1beaf412010-03-05 06:17:43 +000043; CHECK: test3:
Dan Gohmanb75e8642010-01-04 20:53:54 +000044; CHECK: andl $16, %edi
Dan Gohmanc12e9792010-01-04 21:23:34 +000045; CHECK-NEXT: jne
Dan Gohmanb75e8642010-01-04 20:53:54 +000046
Chris Lattner1beaf412010-03-05 06:17:43 +000047define void @test3(i32 %x) nounwind {
Dan Gohmanb75e8642010-01-04 20:53:54 +000048 %y = and i32 %x, 16
49 %t = icmp eq i32 %y, 0
50 br i1 %t, label %true, label %false
51true:
52 call void @foo(i32 %y)
53 ret void
54false:
55 ret void
56}