461150f06d7beb4943c1309b780c8999fb17227f
[oota-llvm.git] / test / CodeGen / ARM / arm-and-tst-peephole.ll
1 ; RUN: llc < %s -march=arm | FileCheck -check-prefix=ARM %s
2 ; RUN: llc < %s -march=thumb | FileCheck -check-prefix=THUMB %s
3 ; RUN: llc < %s -march=thumb -mattr=+thumb2 | FileCheck -check-prefix=T2 %s
4
5 ; FIXME: The -march=thumb test doesn't change if -disable-peephole is specified.
6
7 %struct.Foo = type { i8* }
8
9 ; ARM:   foo
10 ; THUMB: foo
11 ; T2:    foo
12 define %struct.Foo* @foo(%struct.Foo* %this, i32 %acc) nounwind readonly align 2 {
13 entry:
14   %scevgep = getelementptr %struct.Foo* %this, i32 1
15   br label %tailrecurse
16
17 tailrecurse:                                      ; preds = %sw.bb, %entry
18   %lsr.iv2 = phi %struct.Foo* [ %scevgep3, %sw.bb ], [ %scevgep, %entry ]
19   %lsr.iv = phi i32 [ %lsr.iv.next, %sw.bb ], [ 1, %entry ]
20   %acc.tr = phi i32 [ %or, %sw.bb ], [ %acc, %entry ]
21   %lsr.iv24 = bitcast %struct.Foo* %lsr.iv2 to i8**
22   %scevgep5 = getelementptr i8** %lsr.iv24, i32 -1
23   %tmp2 = load i8** %scevgep5
24   %0 = ptrtoint i8* %tmp2 to i32
25
26 ; ARM:      ands r12, r12, #3
27 ; ARM-NEXT: beq
28
29 ; THUMB:      movs r5, #3
30 ; THUMB-NEXT: mov r6, r4
31 ; THUMB-NEXT: ands r6, r5
32 ; THUMB-NEXT: tst r4, r5
33 ; THUMB-NEXT: beq
34
35 ; T2:      ands r12, r12, #3
36 ; T2-NEXT: beq
37
38   %and = and i32 %0, 3
39   %tst = icmp eq i32 %and, 0
40   br i1 %tst, label %sw.bb, label %tailrecurse.switch
41
42 tailrecurse.switch:                               ; preds = %tailrecurse
43   switch i32 %and, label %sw.epilog [
44     i32 1, label %sw.bb
45     i32 3, label %sw.bb6
46     i32 2, label %sw.bb8
47   ]
48
49 sw.bb:                                            ; preds = %tailrecurse.switch, %tailrecurse
50   %shl = shl i32 %acc.tr, 1
51   %or = or i32 %and, %shl
52   %lsr.iv.next = add i32 %lsr.iv, 1
53   %scevgep3 = getelementptr %struct.Foo* %lsr.iv2, i32 1
54   br label %tailrecurse
55
56 sw.bb6:                                           ; preds = %tailrecurse.switch
57   ret %struct.Foo* %lsr.iv2
58
59 sw.bb8:                                           ; preds = %tailrecurse.switch
60   %tmp1 = add i32 %acc.tr, %lsr.iv
61   %add.ptr11 = getelementptr inbounds %struct.Foo* %this, i32 %tmp1
62   ret %struct.Foo* %add.ptr11
63
64 sw.epilog:                                        ; preds = %tailrecurse.switch
65   ret %struct.Foo* undef
66 }
67
68 ; Another test that exercises the AND/TST peephole optimization and also
69 ; generates a predicated ANDS instruction. Check that the predicate is printed
70 ; after the "S" modifier on the instruction.
71
72 %struct.S = type { i8* (i8*)*, [1 x i8] }
73
74 ; ARM: bar
75 ; THUMB: bar
76 ; T2: bar
77 define internal zeroext i8 @bar(%struct.S* %x, %struct.S* nocapture %y) nounwind readonly {
78 entry:
79   %0 = getelementptr inbounds %struct.S* %x, i32 0, i32 1, i32 0
80   %1 = load i8* %0, align 1
81   %2 = zext i8 %1 to i32
82 ; ARM: ands
83 ; THUMB: ands
84 ; T2: ands
85   %3 = and i32 %2, 112
86   %4 = icmp eq i32 %3, 0
87   br i1 %4, label %return, label %bb
88
89 bb:                                               ; preds = %entry
90   %5 = getelementptr inbounds %struct.S* %y, i32 0, i32 1, i32 0
91   %6 = load i8* %5, align 1
92   %7 = zext i8 %6 to i32
93 ; ARM: andsne
94 ; THUMB: ands
95 ; T2: andsne
96   %8 = and i32 %7, 112
97   %9 = icmp eq i32 %8, 0
98   br i1 %9, label %return, label %bb2
99
100 bb2:                                              ; preds = %bb
101   %10 = icmp eq i32 %3, 16
102   %11 = icmp eq i32 %8, 16
103   %or.cond = or i1 %10, %11
104   br i1 %or.cond, label %bb4, label %return
105
106 bb4:                                              ; preds = %bb2
107   %12 = ptrtoint %struct.S* %x to i32
108   %phitmp = trunc i32 %12 to i8
109   ret i8 %phitmp
110
111 return:                                           ; preds = %bb2, %bb, %entry
112   ret i8 1
113 }