1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2 ; RUN: llc -mtriple=aarch64-linux-gnu -verify-machineinstrs < %s | FileCheck %s
3 ; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' -mtriple=aarch64-linux %s | FileCheck --check-prefix=CHECK-CGP %s
4 ; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' -cgpp-huge-func=0 -mtriple=aarch64-linux %s | FileCheck --check-prefix=CHECK-CGP %s
6 @A = dso_local global i32 zeroinitializer
7 @B = dso_local global i32 zeroinitializer
8 @C = dso_local global i32 zeroinitializer
10 ; Test that and is sunk into cmp block to form tbz.
11 define dso_local i32 @and_sink1(i32 %a, i1 %c) {
12 ; CHECK-LABEL: and_sink1:
14 ; CHECK-NEXT: tbz w1, #0, .LBB0_3
15 ; CHECK-NEXT: // %bb.1: // %bb0
16 ; CHECK-NEXT: adrp x8, A
17 ; CHECK-NEXT: str wzr, [x8, :lo12:A]
18 ; CHECK-NEXT: tbnz w0, #2, .LBB0_3
19 ; CHECK-NEXT: // %bb.2:
20 ; CHECK-NEXT: mov w0, #1 // =0x1
22 ; CHECK-NEXT: .LBB0_3: // %bb2
23 ; CHECK-NEXT: mov w0, wzr
26 ; CHECK-CGP-LABEL: @and_sink1(
27 ; CHECK-CGP-NOT: and i32
29 br i1 %c, label %bb0, label %bb2
31 ; CHECK-CGP-LABEL: bb0:
33 ; CHECK-CGP-NEXT: icmp eq i32
34 ; CHECK-CGP-NEXT: store
36 %cmp = icmp eq i32 %and, 0
38 br i1 %cmp, label %bb1, label %bb2
45 ; Test that both 'and' and cmp get sunk to form tbz.
46 define dso_local i32 @and_sink2(i32 %a, i1 %c, i1 %c2) {
47 ; CHECK-LABEL: and_sink2:
49 ; CHECK-NEXT: adrp x8, A
50 ; CHECK-NEXT: str wzr, [x8, :lo12:A]
51 ; CHECK-NEXT: tbz w1, #0, .LBB1_5
52 ; CHECK-NEXT: // %bb.1: // %bb0.preheader
53 ; CHECK-NEXT: adrp x8, B
54 ; CHECK-NEXT: adrp x9, C
55 ; CHECK-NEXT: .LBB1_2: // %bb0
56 ; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
57 ; CHECK-NEXT: str wzr, [x8, :lo12:B]
58 ; CHECK-NEXT: tbz w2, #0, .LBB1_5
59 ; CHECK-NEXT: // %bb.3: // %bb1
60 ; CHECK-NEXT: // in Loop: Header=BB1_2 Depth=1
61 ; CHECK-NEXT: str wzr, [x9, :lo12:C]
62 ; CHECK-NEXT: tbnz w0, #2, .LBB1_2
63 ; CHECK-NEXT: // %bb.4:
64 ; CHECK-NEXT: mov w0, #1 // =0x1
66 ; CHECK-NEXT: .LBB1_5:
67 ; CHECK-NEXT: mov w0, wzr
70 ; CHECK-CGP-LABEL: @and_sink2(
71 ; CHECK-CGP-NOT: and i32
74 br i1 %c, label %bb0, label %bb3
76 ; CHECK-CGP-LABEL: bb0:
77 ; CHECK-CGP-NOT: and i32
79 %cmp = icmp eq i32 %and, 0
81 br i1 %c2, label %bb1, label %bb3
83 ; CHECK-CGP-LABEL: bb1:
85 ; CHECK-CGP-NEXT: icmp eq i32
86 ; CHECK-CGP-NEXT: store
89 br i1 %cmp, label %bb2, label %bb0
96 ; Test that 'and' is not sunk since cbz is a better alternative.
97 define dso_local i32 @and_sink3(i32 %a) {
98 ; CHECK-LABEL: and_sink3:
100 ; CHECK-NEXT: adrp x8, A
101 ; CHECK-NEXT: and w9, w0, #0x3
102 ; CHECK-NEXT: .LBB2_1: // %bb0
103 ; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
104 ; CHECK-NEXT: str wzr, [x8, :lo12:A]
105 ; CHECK-NEXT: cbz w9, .LBB2_1
106 ; CHECK-NEXT: // %bb.2: // %bb2
107 ; CHECK-NEXT: mov w0, wzr
110 ; CHECK-CGP-LABEL: @and_sink3(
111 ; CHECK-CGP-NEXT: and i32
115 ; CHECK-CGP-LABEL: bb0:
116 ; CHECK-CGP-NOT: and i32
117 %cmp = icmp eq i32 %and, 0
119 br i1 %cmp, label %bb0, label %bb2