1 ; RUN: llc -mtriple=aarch64-linux-gnu -verify-machineinstrs < %s | FileCheck %s
2 ; RUN: opt -S -codegenprepare -mtriple=aarch64-linux %s | FileCheck --check-prefix=CHECK-CGP %s
4 @A = global i32 zeroinitializer
5 @B = global i32 zeroinitializer
6 @C = global i32 zeroinitializer
8 ; Test that and is sunk into cmp block to form tbz.
9 define i32 @and_sink1(i32 %a, i1 %c) {
10 ; CHECK-LABEL: and_sink1:
12 ; CHECK: str wzr, [x{{[0-9]+}}, :lo12:A]
13 ; CHECK: tbnz {{w[0-9]+}}, #2
15 ; CHECK-CGP-LABEL: @and_sink1(
16 ; CHECK-CGP-NOT: and i32
18 br i1 %c, label %bb0, label %bb2
20 ; CHECK-CGP-LABEL: bb0:
22 ; CHECK-CGP-NEXT: icmp eq i32
23 ; CHECK-CGP-NEXT: store
25 %cmp = icmp eq i32 %and, 0
27 br i1 %cmp, label %bb1, label %bb2
34 ; Test that both 'and' and cmp get sunk to form tbz.
35 define i32 @and_sink2(i32 %a, i1 %c, i1 %c2) {
36 ; CHECK-LABEL: and_sink2:
37 ; CHECK: str wzr, [x{{[0-9]+}}, :lo12:A]
39 ; CHECK: str wzr, [x{{[0-9]+}}, :lo12:B]
41 ; CHECK: str wzr, [x{{[0-9]+}}, :lo12:C]
42 ; CHECK: tbnz {{w[0-9]+}}, #2
44 ; CHECK-CGP-LABEL: @and_sink2(
45 ; CHECK-CGP-NOT: and i32
48 br i1 %c, label %bb0, label %bb3
50 ; CHECK-CGP-LABEL: bb0:
51 ; CHECK-CGP-NOT: and i32
53 %cmp = icmp eq i32 %and, 0
55 br i1 %c2, label %bb1, label %bb3
57 ; CHECK-CGP-LABEL: bb1:
59 ; CHECK-CGP-NEXT: icmp eq i32
60 ; CHECK-CGP-NEXT: store
63 br i1 %cmp, label %bb2, label %bb0
70 ; Test that 'and' is not sunk since cbz is a better alternative.
71 define i32 @and_sink3(i32 %a) {
72 ; CHECK-LABEL: and_sink3:
73 ; CHECK: and [[REG:w[0-9]+]], w0, #0x3
74 ; CHECK: [[LOOP:.L[A-Z0-9_]+]]:
75 ; CHECK: str wzr, [x{{[0-9]+}}, :lo12:A]
76 ; CHECK: cbz [[REG]], [[LOOP]]
78 ; CHECK-CGP-LABEL: @and_sink3(
79 ; CHECK-CGP-NEXT: and i32
83 ; CHECK-CGP-LABEL: bb0:
84 ; CHECK-CGP-NOT: and i32
85 %cmp = icmp eq i32 %and, 0
87 br i1 %cmp, label %bb0, label %bb2