blob: 2dd2a4adac559b155a5ae7d68367ef08c9083eda [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
8; CHECK: add_zf:
9; CHECK: addl (%rdi), %esi
10; CHECK-NEXT: movl %edx, %eax
11; CHECK-NEXT: cmovnsl %ecx, %eax
12; CHECK-NEXT: ret
13
14define i32 @add_zf(i32* %x, i32 %y, i32 %a, i32 %b) nounwind {
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
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
27; CHECK: bar:
28; CHECK: testb $16, %dil
29
30define void @bar(i32 %x) nounwind {
31 %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
43; CHECK: qux:
44; CHECK: andl $16, %edi
Dan Gohmanc12e9792010-01-04 21:23:34 +000045; CHECK-NEXT: jne
Dan Gohmanb75e8642010-01-04 20:53:54 +000046
47define void @qux(i32 %x) nounwind {
48 %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}