2 ; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -verify-loop-info \
3 ; RUN: -S -debug 2>&1 | FileCheck %s
5 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6 target triple = "x86_64-unknown-linux-gnu"
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
13 ;; Loops not tightly nested are not interchanged
14 ;; for(int j=0;j<N;j++) {
16 ;; for(int i=0;i<N;i++)
17 ;; A[j][i] = A[j][i]+B[j];
20 ; CHECK: Not interchanging loops. Cannot prove legality.
22 define void @interchange_05(i32 %k, i32 %N){
24 %cmp30 = icmp sgt i32 %N, 0
25 br i1 %cmp30, label %for.body.lr.ph, label %for.end17
29 %1 = zext i32 %k to i64
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
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
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
61 declare void @foo(...) readnone
63 ;; Loops not tightly nested are not interchanged
64 ;; for(int j=0;j<N;j++) {
66 ;; for(int i=2;i<N;i++)
67 ;; A[j][i] = A[j][i]+k;
70 ; CHECK: Not interchanging loops. Cannot prove legality.
72 define void @interchange_06(i32 %k, i32 %N) {
74 %cmp22 = icmp sgt i32 %N, 0
75 br i1 %cmp22, label %for.body.lr.ph, label %for.end12
82 %indvars.iv24 = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next25, %for.inc10 ]
83 tail call void (...) @foo()
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
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