test for and-tst peephole optimization
[oota-llvm.git] / test / CodeGen / ARM / arm-and-tst-peephole.ll
1 ; RUN: llc < %s -mtriple=arm-apple-darwin | FileCheck %s
2 ; RUN: llc < %s -mtriple=thumbv6-apple-darwin | FileCheck -check-prefix=T2 %s
3
4 %struct.Foo = type { i8* }
5
6 define %struct.Foo* @_ZN3Foo7collectEj(%struct.Foo* %this, i32 %acc) nounwind readonly align 2 {
7 entry:
8   %scevgep = getelementptr %struct.Foo* %this, i32 1
9   br label %tailrecurse
10
11 tailrecurse:                                      ; preds = %sw.bb, %entry
12   %lsr.iv2 = phi %struct.Foo* [ %scevgep3, %sw.bb ], [ %scevgep, %entry ]
13   %lsr.iv = phi i32 [ %lsr.iv.next, %sw.bb ], [ 1, %entry ]
14   %acc.tr = phi i32 [ %or, %sw.bb ], [ %acc, %entry ]
15   %lsr.iv24 = bitcast %struct.Foo* %lsr.iv2 to i8**
16   %scevgep5 = getelementptr i8** %lsr.iv24, i32 -1
17   %tmp2 = load i8** %scevgep5
18   %0 = ptrtoint i8* %tmp2 to i32
19
20 ; CHECK:      and lr, r12, #3
21 ; CHECK-NEXT: tst r12, #3
22 ; CHECK-NEXT: beq LBB0_4
23
24 ; T2:      movs r5, #3
25 ; T2-NEXT: mov r6, r4
26 ; T2-NEXT: ands r6, r5
27 ; T2-NEXT: tst r4, r5
28 ; T2-NEXT: beq LBB0_5
29
30   %and = and i32 %0, 3
31   %tst = icmp eq i32 %and, 0
32   br i1 %tst, label %sw.bb, label %tailrecurse.switch
33
34 tailrecurse.switch:                               ; preds = %tailrecurse
35   switch i32 %and, label %sw.epilog [
36     i32 1, label %sw.bb
37     i32 3, label %sw.bb6
38     i32 2, label %sw.bb8
39   ]
40
41 sw.bb:                                            ; preds = %tailrecurse.switch, %tailrecurse
42   %shl = shl i32 %acc.tr, 1
43   %or = or i32 %and, %shl
44   %lsr.iv.next = add i32 %lsr.iv, 1
45   %scevgep3 = getelementptr %struct.Foo* %lsr.iv2, i32 1
46   br label %tailrecurse
47
48 sw.bb6:                                           ; preds = %tailrecurse.switch
49   ret %struct.Foo* %lsr.iv2
50
51 sw.bb8:                                           ; preds = %tailrecurse.switch
52   %tmp1 = add i32 %acc.tr, %lsr.iv
53   %add.ptr11 = getelementptr inbounds %struct.Foo* %this, i32 %tmp1
54   ret %struct.Foo* %add.ptr11
55
56 sw.epilog:                                        ; preds = %tailrecurse.switch
57   ret %struct.Foo* undef
58 }