1 ;; This test was created to ensure that the LoopFlatten pass can
2 ;; operate on loops that are not in simplified form before applying the pass.
4 ; RUN: opt < %s -S -loop-flatten -simplifycfg -verify-loop-info -verify-dom-info -verify-scev -verify | FileCheck %s
6 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
8 define void @test(i64 %N, i64* %A, i64 %val) {
11 ; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i64 [[N:%.*]], 0
12 ; CHECK-NEXT: br i1 [[CMP_NOT]], label [[FOR_END:%.*]], label [[FOR_COND_PREHEADER_PREHEADER:%.*]]
13 ; CHECK: for.cond.preheader.preheader:
14 ; CHECK-NEXT: [[FLATTEN_TRIPCOUNT:%.*]] = mul i64 [[N]], [[N]]
15 ; CHECK-NEXT: br label [[FOR_COND_PREHEADER:%.*]]
16 ; CHECK: for.cond.preheader:
17 ; CHECK-NEXT: [[I:%.*]] = phi i64 [ [[INC6:%.*]], [[FOR_COND_PREHEADER]] ], [ 0, [[FOR_COND_PREHEADER_PREHEADER]] ]
18 ; CHECK-NEXT: [[MUL:%.*]] = mul i64 [[I]], [[N]]
19 ; CHECK-NEXT: [[ADD:%.*]] = add i64 0, [[MUL]]
20 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, i64* [[A:%.*]], i64 [[I]]
21 ; CHECK-NEXT: [[TMP0:%.*]] = load i64, i64* [[ARRAYIDX]], align 4
22 ; CHECK-NEXT: [[ADD4:%.*]] = add nsw i64 [[TMP0]], [[VAL:%.*]]
23 ; CHECK-NEXT: store i64 [[ADD4]], i64* [[ARRAYIDX]], align 4
24 ; CHECK-NEXT: [[INC:%.*]] = add nuw nsw i64 0, 1
25 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i64 [[INC]], [[N]]
26 ; CHECK-NEXT: [[INC6]] = add nuw nsw i64 [[I]], 1
27 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[INC6]], [[FLATTEN_TRIPCOUNT]]
28 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_COND_PREHEADER]], label [[FOR_END]]
30 ; CHECK-NEXT: ret void
33 %cmp.not = icmp eq i64 %N, 0
34 br i1 %cmp.not, label %for.end, label %for.cond.preheader
37 %i= phi i64 [ %inc6, %for.cond.for.inc_crit_edge ], [ 0, %entry ]
42 %j = phi i64 [ 0, %for.cond.preheader ], [ %inc, %for.body ]
43 %add = add i64 %j, %mul
44 %arrayidx = getelementptr inbounds i64, i64* %A, i64 %add
45 %0 = load i64, i64* %arrayidx, align 4
46 %add4 = add nsw i64 %0, %val
47 store i64 %add4, i64* %arrayidx, align 4
48 %inc = add nuw nsw i64 %j, 1
49 %cmp2 = icmp ult i64 %inc, %N
50 br i1 %cmp2, label %for.body, label %for.cond.for.inc_crit_edge
52 for.cond.for.inc_crit_edge:
53 %inc6 = add nuw nsw i64 %i, 1
54 %cmp = icmp ult i64 %inc6, %N
55 br i1 %cmp, label %for.cond.preheader, label %for.end