blob: df6c6cfdbcb5d4940a1965ed730237a90694fd35 [file] [log] [blame]
Florian Hahn6c7f0252017-07-18 09:47:06 +00001; RUN: opt < %s -basicaa -loop-interchange -S | FileCheck %s
2;; We test the complete .ll for adjustment in outer loop header/latch and inner loop header/latch.
3
4target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5target triple = "x86_64-unknown-linux-gnu"
6
7@A = common global [100 x [100 x i32]] zeroinitializer
8@C = common global [100 x [100 x i32]] zeroinitializer
9
10;; FIXME:
11;; Test for interchange when we have an lcssa phi. This should ideally be interchanged but it is currently not supported.
12;; for(gi=1;gi<N;gi++)
13;; for(gj=1;gj<M;gj++)
14;; A[gj][gi] = A[gj - 1][gi] + C[gj][gi];
15
16@gi = common global i32 0
17@gj = common global i32 0
18
19define void @interchange_07(i32 %N, i32 %M){
20entry:
21 store i32 1, i32* @gi
22 %cmp21 = icmp sgt i32 %N, 1
23 br i1 %cmp21, label %for.cond1.preheader.lr.ph, label %for.end16
24
25for.cond1.preheader.lr.ph:
26 %cmp218 = icmp sgt i32 %M, 1
27 %gi.promoted = load i32, i32* @gi
28 %0 = add i32 %M, -1
29 %1 = sext i32 %gi.promoted to i64
30 %2 = sext i32 %N to i64
31 %3 = add i32 %gi.promoted, 1
32 %4 = icmp slt i32 %3, %N
33 %smax = select i1 %4, i32 %N, i32 %3
34 br label %for.cond1.preheader
35
36for.cond1.preheader:
37 %indvars.iv25 = phi i64 [ %1, %for.cond1.preheader.lr.ph ], [ %indvars.iv.next26, %for.inc14 ]
38 br i1 %cmp218, label %for.body3, label %for.inc14
39
40for.body3:
41 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3 ], [ 1, %for.cond1.preheader ]
42 %5 = add nsw i64 %indvars.iv, -1
43 %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %5, i64 %indvars.iv25
44 %6 = load i32, i32* %arrayidx5
45 %arrayidx9 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @C, i64 0, i64 %indvars.iv, i64 %indvars.iv25
46 %7 = load i32, i32* %arrayidx9
47 %add = add nsw i32 %7, %6
48 %arrayidx13 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv, i64 %indvars.iv25
49 store i32 %add, i32* %arrayidx13
50 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
51 %lftr.wideiv = trunc i64 %indvars.iv to i32
52 %exitcond = icmp eq i32 %lftr.wideiv, %0
53 br i1 %exitcond, label %for.inc14, label %for.body3
54
55for.inc14:
56 %inc.lcssa23 = phi i32 [ 1, %for.cond1.preheader ], [ %M, %for.body3 ]
57 %indvars.iv.next26 = add nsw i64 %indvars.iv25, 1
58 %cmp = icmp slt i64 %indvars.iv.next26, %2
59 br i1 %cmp, label %for.cond1.preheader, label %for.cond.for.end16_crit_edge
60
61for.cond.for.end16_crit_edge:
62 store i32 %inc.lcssa23, i32* @gj
63 store i32 %smax, i32* @gi
64 br label %for.end16
65
66for.end16:
67 ret void
68}
69
70; CHECK-LABEL: @interchange_07
71; CHECK: for.body3: ; preds = %for.body3.preheader, %for.body3
72; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3 ], [ 1, %for.body3.preheader ]
73; CHECK: %5 = add nsw i64 %indvars.iv, -1
74; CHECK: %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %5, i64 %indvars.iv25
75; CHECK: %6 = load i32, i32* %arrayidx5
76; CHECK: %arrayidx9 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @C, i64 0, i64 %indvars.iv, i64 %indvars.iv25