1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -loop-interchange -verify-dom-info -verify-loop-info -verify-scev -verify-loop-lcssa -loop-interchange-threshold=-1000 -S 2>&1 | FileCheck %s
3 ;; Checks the order of the inner phi nodes does not cause havoc.
4 ;; The inner loop has a reduction into c. The IV is not the first phi.
6 target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
7 target triple = "armv8--linux-gnueabihf"
11 ; Function Attrs: norecurse nounwind
12 define void @test(i32 %T, [90 x i32]* noalias nocapture %C, i16* noalias nocapture readonly %A, i16* noalias nocapture readonly %B) local_unnamed_addr #0 {
15 ; CHECK-NEXT: br label [[FOR3_PREHEADER:%.*]]
16 ; CHECK: for1.header.preheader:
17 ; CHECK-NEXT: br label [[FOR1_HEADER:%.*]]
19 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[INC20:%.*]], [[FOR1_INC19:%.*]] ], [ 0, [[FOR1_HEADER_PREHEADER:%.*]] ]
20 ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[I]], 90
21 ; CHECK-NEXT: br label [[FOR2_HEADER_PREHEADER:%.*]]
22 ; CHECK: for2.header.preheader:
23 ; CHECK-NEXT: br label [[FOR2_HEADER:%.*]]
25 ; CHECK-NEXT: [[J:%.*]] = phi i32 [ [[INC17:%.*]], [[FOR2_INC16:%.*]] ], [ 0, [[FOR2_HEADER_PREHEADER]] ]
26 ; CHECK-NEXT: br label [[FOR3_SPLIT1:%.*]]
27 ; CHECK: for3.preheader:
28 ; CHECK-NEXT: br label [[FOR3:%.*]]
30 ; CHECK-NEXT: [[K:%.*]] = phi i32 [ [[INC:%.*]], [[FOR3_SPLIT:%.*]] ], [ 1, [[FOR3_PREHEADER]] ]
31 ; CHECK-NEXT: br label [[FOR1_HEADER_PREHEADER]]
33 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[K]], [[MUL]]
34 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i16, i16* [[A:%.*]], i32 [[ADD]]
35 ; CHECK-NEXT: [[TMP0:%.*]] = load i16, i16* [[ARRAYIDX]], align 2
36 ; CHECK-NEXT: [[ADD15:%.*]] = add nsw i16 [[TMP0]], 1
37 ; CHECK-NEXT: store i16 [[ADD15]], i16* [[ARRAYIDX]]
38 ; CHECK-NEXT: br label [[FOR2_INC16]]
40 ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[K]], 1
41 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], 90
42 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR1_LOOPEXIT:%.*]], label [[FOR3]]
44 ; CHECK-NEXT: [[INC17]] = add nuw nsw i32 [[J]], 1
45 ; CHECK-NEXT: [[EXITCOND47:%.*]] = icmp eq i32 [[INC17]], 90
46 ; CHECK-NEXT: br i1 [[EXITCOND47]], label [[FOR1_INC19]], label [[FOR2_HEADER]]
48 ; CHECK-NEXT: [[INC20]] = add nuw nsw i32 [[I]], 1
49 ; CHECK-NEXT: [[EXITCOND48:%.*]] = icmp eq i32 [[INC20]], 90
50 ; CHECK-NEXT: br i1 [[EXITCOND48]], label [[FOR3_SPLIT]], label [[FOR1_HEADER]]
51 ; CHECK: for1.loopexit:
52 ; CHECK-NEXT: br label [[EXIT:%.*]]
54 ; CHECK-NEXT: ret void
59 for1.header: ; preds = %entry
60 %i = phi i32 [ %inc20, %for1.inc19 ], [ 0, %entry ]
61 %mul = mul nsw i32 %i, 90
64 for2.header: ; preds = %for2.inc16, %for1.header
65 %j = phi i32 [ 0, %for1.header ], [ %inc17, %for2.inc16 ]
68 for3: ; preds = %for3, %for2.header
69 %k = phi i32 [ 1, %for2.header ], [ %inc, %for3 ]
70 %add = add nsw i32 %k, %mul
71 %arrayidx = getelementptr inbounds i16, i16* %A, i32 %add
72 %0 = load i16, i16* %arrayidx, align 2
73 %add15 = add nsw i16 %0, 1
74 store i16 %add15, i16* %arrayidx
75 %inc = add nuw nsw i32 %k, 1
76 %exitcond = icmp eq i32 %inc, 90
77 br i1 %exitcond, label %for2.inc16, label %for3
79 for2.inc16: ; preds = %for.body6
80 %inc17 = add nuw nsw i32 %j, 1
81 %exitcond47 = icmp eq i32 %inc17, 90
82 br i1 %exitcond47, label %for1.inc19, label %for2.header
84 for1.inc19: ; preds = %for2.inc16
85 %inc20 = add nuw nsw i32 %i, 1
86 %exitcond48 = icmp eq i32 %inc20, 90
87 br i1 %exitcond48, label %for1.loopexit, label %for1.header
89 for1.loopexit: ; preds = %for1.inc19
92 exit: ; preds = %for1.loopexit