1 ; RUN: llc -mtriple=arm-eabi -arm-atomic-cfg-tidy=0 %s -o - | FileCheck -check-prefix=ARM %s
2 ; RUN: llc -mtriple=thumb-eabi -arm-atomic-cfg-tidy=0 %s -o - | FileCheck -check-prefix=THUMB %s
3 ; RUN: llc -mtriple=thumb-eabi -arm-atomic-cfg-tidy=0 -mcpu=arm1156t2-s -mattr=+thumb2 %s -o - | FileCheck -check-prefix=T2 %s
4 ; RUN: llc -mtriple=thumbv8-eabi -arm-atomic-cfg-tidy=0 %s -o - | FileCheck -check-prefix=V8 %s
6 ; FIXME: The -mtriple=thumb test doesn't change if -disable-peephole is specified.
8 %struct.Foo = type { i8* }
13 define %struct.Foo* @foo(%struct.Foo* %this, i32 %acc) nounwind readonly align 2 {
15 %scevgep = getelementptr %struct.Foo, %struct.Foo* %this, i32 1
18 tailrecurse: ; preds = %sw.bb, %entry
19 %lsr.iv2 = phi %struct.Foo* [ %scevgep3, %sw.bb ], [ %scevgep, %entry ]
20 %lsr.iv = phi i32 [ %lsr.iv.next, %sw.bb ], [ 1, %entry ]
21 %acc.tr = phi i32 [ %or, %sw.bb ], [ %acc, %entry ]
22 %lsr.iv24 = bitcast %struct.Foo* %lsr.iv2 to i8**
23 %scevgep5 = getelementptr i8*, i8** %lsr.iv24, i32 -1
24 %tmp2 = load i8*, i8** %scevgep5
25 %0 = ptrtoint i8* %tmp2 to i32
27 ; ARM: ands {{r[0-9]+}}, {{r[0-9]+}}, #3
30 ; THUMB: movs r[[R0:[0-9]+]], #3
31 ; THUMB-NEXT: ands r[[R0]], r
34 ; T2: ands {{r[0-9]+}}, {{r[0-9]+}}, #3
38 %tst = icmp eq i32 %and, 0
39 br i1 %tst, label %sw.bb, label %tailrecurse.switch
41 tailrecurse.switch: ; preds = %tailrecurse
42 ; V8-LABEL: %tailrecurse.switch
45 ; V8-NEXT: %tailrecurse.switch
48 ; V8-NEXT: %tailrecurse.switch
52 switch i32 %and, label %sw.epilog [
58 sw.bb: ; preds = %tailrecurse.switch, %tailrecurse
59 %shl = shl i32 %acc.tr, 1
60 %or = or i32 %and, %shl
61 %lsr.iv.next = add i32 %lsr.iv, 1
62 %scevgep3 = getelementptr %struct.Foo, %struct.Foo* %lsr.iv2, i32 1
65 sw.bb6: ; preds = %tailrecurse.switch
66 ret %struct.Foo* %lsr.iv2
68 sw.bb8: ; preds = %tailrecurse.switch
69 %tmp1 = add i32 %acc.tr, %lsr.iv
70 %add.ptr11 = getelementptr inbounds %struct.Foo, %struct.Foo* %this, i32 %tmp1
71 ret %struct.Foo* %add.ptr11
73 sw.epilog: ; preds = %tailrecurse.switch
74 ret %struct.Foo* undef
77 ; Another test that exercises the AND/TST peephole optimization and also
78 ; generates a predicated ANDS instruction. Check that the predicate is printed
79 ; after the "S" modifier on the instruction.
81 %struct.S = type { i8* (i8*)*, [1 x i8] }
87 define internal zeroext i8 @bar(%struct.S* %x, %struct.S* nocapture %y) nounwind readonly {
89 %0 = getelementptr inbounds %struct.S, %struct.S* %x, i32 0, i32 1, i32 0
90 %1 = load i8, i8* %0, align 1
91 %2 = zext i8 %1 to i32
98 %4 = icmp eq i32 %3, 0
99 br i1 %4, label %return, label %bb
103 %5 = getelementptr inbounds %struct.S, %struct.S* %y, i32 0, i32 1, i32 0
104 %6 = load i8, i8* %5, align 1
105 %7 = zext i8 %6 to i32
112 %9 = icmp eq i32 %8, 0
113 br i1 %9, label %return, label %bb2
121 %10 = icmp eq i32 %3, 16
122 %11 = icmp eq i32 %8, 16
123 %or.cond = or i1 %10, %11
124 br i1 %or.cond, label %bb4, label %return
127 %12 = ptrtoint %struct.S* %x to i32
128 %phitmp = trunc i32 %12 to i8
131 return: ; preds = %bb2, %bb, %entry
136 ; We were looking through multiple COPY instructions to find an AND we might
137 ; fold into a TST, but in doing so we changed the register being tested allowing
138 ; folding of unrelated tests (in this case, a TST against r1 was eliminated in
139 ; favour of an AND of r0).
141 define i32 @test_tst_assessment(i32 %a, i32 %b) {
142 ; ARM-LABEL: test_tst_assessment:
144 ; ARM-NEXT: and r0, r0, #1
145 ; ARM-NEXT: tst r1, #1
146 ; ARM-NEXT: subne r0, r0, #1
147 ; ARM-NEXT: mov pc, lr
149 ; THUMB-LABEL: test_tst_assessment:
151 ; THUMB-NEXT: movs r2, r0
152 ; THUMB-NEXT: movs r0, #1
153 ; THUMB-NEXT: ands r0, r2
154 ; THUMB-NEXT: lsls r1, r1, #31
155 ; THUMB-NEXT: beq .LBB2_2
156 ; THUMB-NEXT: @ %bb.1:
157 ; THUMB-NEXT: subs r0, r0, #1
158 ; THUMB-NEXT: .LBB2_2:
161 ; T2-LABEL: test_tst_assessment:
163 ; T2-NEXT: and r0, r0, #1
164 ; T2-NEXT: lsls r1, r1, #31
166 ; T2-NEXT: subne r0, #1
169 ; V8-LABEL: test_tst_assessment:
171 ; V8-NEXT: and r2, r0, #1
172 ; V8-NEXT: subs r0, r2, #1
173 ; V8-NEXT: lsls r1, r1, #31
175 ; V8-NEXT: moveq r0, r2
177 %and1 = and i32 %a, 1
178 %sub = sub i32 %and1, 1
179 %and2 = and i32 %b, 1
180 %cmp = icmp eq i32 %and2, 0
181 %sel = select i1 %cmp, i32 %and1, i32 %sub
185 !1 = !{!"branch_weights", i32 1, i32 1, i32 3, i32 2 }