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
3 ; RUN: opt -S -codegenprepare -cgpp-huge-func=0 -mtriple=aarch64-linux %s | FileCheck --check-prefix=CHECK-CGP %s
5 @A = dso_local global i32 zeroinitializer
6 @B = dso_local global i32 zeroinitializer
7 @C = dso_local global i32 zeroinitializer
9 ; Test that and is sunk into cmp block to form tbz.
10 define dso_local i32 @and_sink1(i32 %a, i1 %c) {
11 ; CHECK-LABEL: and_sink1:
13 ; CHECK: str wzr, [x{{[0-9]+}}, :lo12:A]
14 ; CHECK: tbnz {{w[0-9]+}}, #2
16 ; CHECK-CGP-LABEL: @and_sink1(
17 ; CHECK-CGP-NOT: and i32
19 br i1 %c, label %bb0, label %bb2
21 ; CHECK-CGP-LABEL: bb0:
23 ; CHECK-CGP-NEXT: icmp eq i32
24 ; CHECK-CGP-NEXT: store
26 %cmp = icmp eq i32 %and, 0
28 br i1 %cmp, label %bb1, label %bb2
35 ; Test that both 'and' and cmp get sunk to form tbz.
36 define dso_local i32 @and_sink2(i32 %a, i1 %c, i1 %c2) {
37 ; CHECK-LABEL: and_sink2:
38 ; CHECK: str wzr, [x{{[0-9]+}}, :lo12:A]
40 ; CHECK: str wzr, [x{{[0-9]+}}, :lo12:B]
42 ; CHECK: str wzr, [x{{[0-9]+}}, :lo12:C]
43 ; CHECK: tbnz {{w[0-9]+}}, #2
45 ; CHECK-CGP-LABEL: @and_sink2(
46 ; CHECK-CGP-NOT: and i32
49 br i1 %c, label %bb0, label %bb3
51 ; CHECK-CGP-LABEL: bb0:
52 ; CHECK-CGP-NOT: and i32
54 %cmp = icmp eq i32 %and, 0
56 br i1 %c2, label %bb1, label %bb3
58 ; CHECK-CGP-LABEL: bb1:
60 ; CHECK-CGP-NEXT: icmp eq i32
61 ; CHECK-CGP-NEXT: store
64 br i1 %cmp, label %bb2, label %bb0
71 ; Test that 'and' is not sunk since cbz is a better alternative.
72 define dso_local i32 @and_sink3(i32 %a) {
73 ; CHECK-LABEL: and_sink3:
74 ; CHECK: and [[REG:w[0-9]+]], w0, #0x3
75 ; CHECK: [[LOOP:.L[A-Z0-9_]+]]:
76 ; CHECK: str wzr, [x{{[0-9]+}}, :lo12:A]
77 ; CHECK: cbz [[REG]], [[LOOP]]
79 ; CHECK-CGP-LABEL: @and_sink3(
80 ; CHECK-CGP-NEXT: and i32
84 ; CHECK-CGP-LABEL: bb0:
85 ; CHECK-CGP-NOT: and i32
86 %cmp = icmp eq i32 %and, 0
88 br i1 %cmp, label %bb0, label %bb2