1; RUN: opt -loop-unroll -S -mtriple aarch64 -mcpu=cortex-a57 %s | FileCheck %s -check-prefix=UNROLL
2; RUN: opt -loop-unroll -unroll-max-upperbound=0 -S -mtriple aarch64 -mcpu=cortex-a57 %s | FileCheck %s -check-prefix=NOUNROLL
3
4; This IR comes from this C code:
5;
6;   for (int i = 0; i < 4; i++) {
7;     if (src[i] == 1) {
8;       *dst = i;
9;       break;
10;     }
11;   }
12;
13; This test is meant to check that this loop is unrolled into four iterations.
14
15; UNROLL-LABEL: @test
16; UNROLL: load i32, i32*
17; UNROLL: load i32, i32*
18; UNROLL: load i32, i32*
19; UNROLL: load i32, i32*
20; UNROLL-NOT: load i32, i32*
21; NOUNROLL-LABEL: @test
22; NOUNROLL: load i32, i32*
23; NOUNROLL-NOT: load i32, i32*
24
25define void @test(i32* %dst, i32* %src) {
26entry:
27  br label %for.body
28
29for.body:                                         ; preds = %entry, %for.body
30  %i = phi i32 [ 0, %entry ], [ %inc, %for.body ]
31  %0 = sext i32 %i to i64
32  %1 = getelementptr inbounds i32, i32* %src, i64 %0
33  %2 = load i32, i32* %1
34  %inc = add nsw i32 %i, 1
35  %cmp1 = icmp slt i32 %inc, 4
36  %cmp3 = icmp eq i32 %2, 1
37  %or.cond = and i1 %cmp3, %cmp1
38  br i1 %or.cond, label %for.body, label %exit
39
40exit:                                          ; preds = %for.body
41  store i32 %i, i32* %dst
42  ret void
43}
44