• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; REQUIRES: asserts
2; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -verify-loop-info \
3; RUN:     -S -debug 2>&1 | FileCheck %s
4
5target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6target triple = "x86_64-unknown-linux-gnu"
7
8@A = common global [100 x [100 x i32]] zeroinitializer
9@B = common global [100 x i32] zeroinitializer
10@C = common global [100 x [100 x i32]] zeroinitializer
11@D = common global [100 x [100 x [100 x i32]]] zeroinitializer
12
13;; Loops not tightly nested are not interchanged
14;;  for(int j=0;j<N;j++) {
15;;    B[j] = j+k;
16;;    for(int i=0;i<N;i++)
17;;      A[j][i] = A[j][i]+B[j];
18;;  }
19
20; CHECK: Not interchanging loops. Cannot prove legality.
21
22define void @interchange_05(i32 %k, i32 %N){
23entry:
24  %cmp30 = icmp sgt i32 %N, 0
25  br i1 %cmp30, label %for.body.lr.ph, label %for.end17
26
27for.body.lr.ph:
28  %0 = add i32 %N, -1
29  %1 = zext i32 %k to i64
30  br label %for.body
31
32for.body:
33  %indvars.iv32 = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next33, %for.inc15 ]
34  %2 = add nsw i64 %indvars.iv32, %1
35  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* @B, i64 0, i64 %indvars.iv32
36  %3 = trunc i64 %2 to i32
37  store i32 %3, i32* %arrayidx
38  br label %for.body3
39
40for.body3:
41  %indvars.iv = phi i64 [ 0, %for.body ], [ %indvars.iv.next, %for.body3 ]
42  %arrayidx7 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv32, i64 %indvars.iv
43  %4 = load i32, i32* %arrayidx7
44  %add10 = add nsw i32 %3, %4
45  store i32 %add10, i32* %arrayidx7
46  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
47  %lftr.wideiv = trunc i64 %indvars.iv to i32
48  %exitcond = icmp eq i32 %lftr.wideiv, %0
49  br i1 %exitcond, label %for.inc15, label %for.body3
50
51for.inc15:
52  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
53  %lftr.wideiv35 = trunc i64 %indvars.iv32 to i32
54  %exitcond36 = icmp eq i32 %lftr.wideiv35, %0
55  br i1 %exitcond36, label %for.end17, label %for.body
56
57for.end17:
58  ret void
59}
60
61declare void @foo(...) readnone
62
63;; Loops not tightly nested are not interchanged
64;;  for(int j=0;j<N;j++) {
65;;    foo();
66;;    for(int i=2;i<N;i++)
67;;      A[j][i] = A[j][i]+k;
68;;  }
69
70; CHECK: Not interchanging loops. Cannot prove legality.
71
72define void @interchange_06(i32 %k, i32 %N) {
73entry:
74  %cmp22 = icmp sgt i32 %N, 0
75  br i1 %cmp22, label %for.body.lr.ph, label %for.end12
76
77for.body.lr.ph:
78  %0 = add i32 %N, -1
79  br label %for.body
80
81for.body:
82  %indvars.iv24 = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next25, %for.inc10 ]
83  tail call void (...) @foo()
84  br label %for.body3
85
86for.body3:
87  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3 ], [ 2, %for.body ]
88  %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv24, i64 %indvars.iv
89  %1 = load i32, i32* %arrayidx5
90  %add = add nsw i32 %1, %k
91  store i32 %add, i32* %arrayidx5
92  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
93  %lftr.wideiv = trunc i64 %indvars.iv to i32
94  %exitcond = icmp eq i32 %lftr.wideiv, %0
95  br i1 %exitcond, label %for.inc10, label %for.body3
96
97for.inc10:
98  %indvars.iv.next25 = add nuw nsw i64 %indvars.iv24, 1
99  %lftr.wideiv26 = trunc i64 %indvars.iv24 to i32
100  %exitcond27 = icmp eq i32 %lftr.wideiv26, %0
101  br i1 %exitcond27, label %for.end12, label %for.body
102
103for.end12:
104  ret void
105}
106