1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=aarch64-unknown-unknown | FileCheck %s
4 target datalayout = "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128"
6 ; we need to generate post index load for this case
7 define i32 @test(i32 %c, ptr %a, ptr %b) {
9 ; CHECK: // %bb.0: // %entry
10 ; CHECK-NEXT: cmp w0, #1
11 ; CHECK-NEXT: b.lt .LBB0_4
12 ; CHECK-NEXT: // %bb.1: // %for.body.preheader
13 ; CHECK-NEXT: mov w8, w0
14 ; CHECK-NEXT: .LBB0_2: // %for.body
15 ; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
16 ; CHECK-NEXT: ldr w9, [x1], #4
17 ; CHECK-NEXT: cbnz w9, .LBB0_5
18 ; CHECK-NEXT: // %bb.3: // %for.cond
19 ; CHECK-NEXT: // in Loop: Header=BB0_2 Depth=1
20 ; CHECK-NEXT: subs x8, x8, #1
21 ; CHECK-NEXT: b.ne .LBB0_2
22 ; CHECK-NEXT: .LBB0_4:
23 ; CHECK-NEXT: mov w0, wzr
25 ; CHECK-NEXT: .LBB0_5:
26 ; CHECK-NEXT: mov w0, #1 // =0x1
29 %cmp13 = icmp sgt i32 %c, 0
30 br i1 %cmp13, label %for.body.preheader, label %return
32 for.body.preheader: ; preds = %entry
33 %wide.trip.count = zext i32 %c to i64
36 for.cond: ; preds = %for.body
37 %iv.next = add nuw nsw i64 %iv, 1
38 %exitcond.not = icmp eq i64 %iv.next, %wide.trip.count
39 br i1 %exitcond.not, label %return, label %for.body
41 for.body: ; preds = %for.body.preheader, %for.cond
42 %iv = phi i64 [ 0, %for.body.preheader ], [ %iv.next, %for.cond ]
43 %arrayidx = getelementptr inbounds i32, ptr %a, i64 %iv
44 %val = load i32, ptr %arrayidx, align 4
45 %tobool3.not = icmp eq i32 %val, 0
46 br i1 %tobool3.not, label %for.cond, label %return
48 return: ; preds = %for.cond, %for.body, %entry
49 %retval.1 = phi i32 [ 0, %entry ], [ 0, %for.cond ], [ 1, %for.body ]
53 ; negative case: %arrayidx.b is not in header
55 define i64 @IVIncHoist_not_all_user_in_header(i32 %c, ptr %a, ptr %b) {
56 ; CHECK-LABEL: IVIncHoist_not_all_user_in_header:
57 ; CHECK: // %bb.0: // %entry
58 ; CHECK-NEXT: cmp w0, #1
59 ; CHECK-NEXT: b.lt .LBB1_5
60 ; CHECK-NEXT: // %bb.1: // %for.body.preheader
61 ; CHECK-NEXT: mov x8, xzr
62 ; CHECK-NEXT: mov w9, w0
63 ; CHECK-NEXT: add x10, x1, #4
64 ; CHECK-NEXT: add x11, x2, #8
65 ; CHECK-NEXT: mov w0, #1 // =0x1
66 ; CHECK-NEXT: .LBB1_2: // %for.body
67 ; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
68 ; CHECK-NEXT: ldr w12, [x10, x8, lsl #2]
69 ; CHECK-NEXT: cbnz w12, .LBB1_7
70 ; CHECK-NEXT: // %bb.3: // %if.then
71 ; CHECK-NEXT: // in Loop: Header=BB1_2 Depth=1
72 ; CHECK-NEXT: ldr w12, [x11, x8, lsl #2]
73 ; CHECK-NEXT: cbnz w12, .LBB1_6
74 ; CHECK-NEXT: // %bb.4: // %for.cond
75 ; CHECK-NEXT: // in Loop: Header=BB1_2 Depth=1
76 ; CHECK-NEXT: add x8, x8, #1
77 ; CHECK-NEXT: cmp x9, x8
78 ; CHECK-NEXT: b.ne .LBB1_2
79 ; CHECK-NEXT: .LBB1_5:
80 ; CHECK-NEXT: mov x0, xzr
82 ; CHECK-NEXT: .LBB1_6: // %if.then.return.loopexit_crit_edge
83 ; CHECK-NEXT: add x0, x8, #3
84 ; CHECK-NEXT: .LBB1_7: // %return
87 %cmp13 = icmp sgt i32 %c, 0
88 br i1 %cmp13, label %for.body.preheader, label %return
90 for.body.preheader: ; preds = %entry
91 %wide.trip.count = zext i32 %c to i64
94 for.cond: ; preds = %for.body
95 %iv.next = add nuw nsw i64 %iv, 1
96 %exitcond.not = icmp eq i64 %iv.next, %wide.trip.count
97 br i1 %exitcond.not, label %return, label %for.body
99 for.body: ; preds = %for.body.preheader, %for.cond
100 %iv = phi i64 [ 0, %for.body.preheader ], [ %iv.next, %for.cond ]
101 %iv.a = phi i64 [ 1, %for.body.preheader ], [ %iv.next.a, %for.cond ]
102 %iv.b = phi i64 [ 2, %for.body.preheader ], [ %iv.next.b, %for.cond ]
103 %arrayidx.a = getelementptr inbounds i32, ptr %a, i64 %iv.a
104 %iv.next.a = add nuw nsw i64 %iv.a, 1
105 %val.a = load i32, ptr %arrayidx.a, align 4
106 %tobool3.not = icmp eq i32 %val.a, 0
107 br i1 %tobool3.not, label %if.then, label %return
110 %arrayidx.b = getelementptr inbounds i32, ptr %b, i64 %iv.b
111 %iv.next.b = add nuw nsw i64 %iv.b, 1
112 %val.b = load i32, ptr %arrayidx.b, align 4
113 %tobool4.not = icmp eq i32 %val.b, 0
114 br i1 %tobool4.not, label %for.cond, label %return
116 return: ; preds = %for.cond, %for.body, %entry
117 %retval.1 = phi i64 [ 0, %entry ], [ 0, %for.cond ], [ 1, %for.body ], [ %iv.next.b, %if.then ]
121 %struct.A = type { i32 }
123 ; this used to crash because the load type is struct
125 define i32 @negative_test_type_is_struct(i32 %c, ptr %a, ptr %b) {
126 ; CHECK-LABEL: negative_test_type_is_struct:
127 ; CHECK: // %bb.0: // %entry
128 ; CHECK-NEXT: cmp w0, #1
129 ; CHECK-NEXT: b.lt .LBB2_4
130 ; CHECK-NEXT: // %bb.1: // %for.body.preheader
131 ; CHECK-NEXT: mov w8, w0
132 ; CHECK-NEXT: .LBB2_2: // %for.body
133 ; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
134 ; CHECK-NEXT: ldr w9, [x1]
135 ; CHECK-NEXT: cbnz w9, .LBB2_5
136 ; CHECK-NEXT: // %bb.3: // %for.cond
137 ; CHECK-NEXT: // in Loop: Header=BB2_2 Depth=1
138 ; CHECK-NEXT: subs x8, x8, #1
139 ; CHECK-NEXT: add x1, x1, #4
140 ; CHECK-NEXT: b.ne .LBB2_2
141 ; CHECK-NEXT: .LBB2_4:
142 ; CHECK-NEXT: mov w0, wzr
144 ; CHECK-NEXT: .LBB2_5:
145 ; CHECK-NEXT: mov w0, #1 // =0x1
148 %cmp13 = icmp sgt i32 %c, 0
149 br i1 %cmp13, label %for.body.preheader, label %return
151 for.body.preheader: ; preds = %entry
152 %wide.trip.count = zext i32 %c to i64
155 for.cond: ; preds = %for.body
156 %iv.next = add nuw nsw i64 %iv, 1
157 %exitcond.not = icmp eq i64 %iv.next, %wide.trip.count
158 br i1 %exitcond.not, label %return, label %for.body
160 for.body: ; preds = %for.body.preheader, %for.cond
161 %iv = phi i64 [ 0, %for.body.preheader ], [ %iv.next, %for.cond ]
162 %arrayidx = getelementptr inbounds i32, ptr %a, i64 %iv
163 %str.val = load %struct.A, ptr %arrayidx
164 %val = extractvalue %struct.A %str.val, 0
165 %tobool3.not = icmp eq i32 %val, 0
166 br i1 %tobool3.not, label %for.cond, label %return
168 return: ; preds = %for.cond, %for.body, %entry
169 %retval.1 = phi i32 [ 0, %entry ], [ 0, %for.cond ], [ 1, %for.body ]