Skip to content

Commit a4bb987

Browse files
committed
[MachineBlockPlacement][X86] Add test for loops with single latch that's not exiting
1 parent c0d1161 commit a4bb987

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

llvm/test/CodeGen/X86/code-align-loops.ll

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,48 @@ exit: ; preds = %bb2, %bb3, %bb4
177177
ret void
178178
}
179179

180+
; test5 is to check if .p2align can be correctly set on loops with a single
181+
; latch that's not the exiting block.
182+
; The test IR is generated from below simple C file:
183+
; $ clang -O0 -S -emit-llvm loop.c
184+
; $ cat loop.c
185+
; int test5(int n) {
186+
; int i = 0;
187+
; [[clang::code_align(64)]]
188+
; while (i < n) {
189+
; i++;
190+
; }
191+
; }
192+
; CHECK-LABEL: test5:
193+
; ALIGN: .p2align 6
194+
; ALIGN-NEXT: .LBB4_1: # %while.cond
195+
define dso_local i32 @test5(i32 %n) #0 {
196+
entry:
197+
%retval = alloca i32, align 4
198+
%n.addr = alloca i32, align 4
199+
%i = alloca i32, align 4
200+
store i32 %n, ptr %n.addr, align 4
201+
store i32 0, ptr %i, align 4
202+
br label %while.cond
203+
204+
while.cond: ; preds = %while.body, %entry
205+
%0 = load i32, ptr %i, align 4
206+
%1 = load i32, ptr %n.addr, align 4
207+
%cmp = icmp slt i32 %0, %1
208+
br i1 %cmp, label %while.body, label %while.end
209+
210+
while.body: ; preds = %while.cond
211+
%2 = load i32, ptr %i, align 4
212+
%inc = add nsw i32 %2, 1
213+
store i32 %inc, ptr %i, align 4
214+
br label %while.cond, !llvm.loop !0
215+
216+
while.end: ; preds = %while.cond
217+
%3 = load i32, ptr %retval, align 4
218+
ret i32 %3
219+
}
220+
221+
180222
declare void @bar()
181223
declare void @var()
182224

0 commit comments

Comments
 (0)