2 ; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 -pass-remarks-missed='loop-interchange' -pass-remarks-output=%t -S \
3 ; RUN: -verify-dom-info -verify-loop-info -stats 2>&1 | FileCheck -check-prefix=STATS %s
4 ; RUN: FileCheck --input-file=%t %s
6 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
8 @A = common global [100 x [100 x i32]] zeroinitializer
10 declare void @foo(i64 %a)
11 declare void @bar(i64 %a) readnone
13 ;;--------------------------------------Test case 01------------------------------------
14 ;; Not safe to interchange, because the called function `foo` is not marked as
15 ;; readnone, so it could introduce dependences.
17 ;; for(int i=0;i<100;i++) {
18 ;; for(int j=1;j<100;j++) {
20 ;; A[j][i] = A[j][i]+k;
25 ; CHECK-NEXT: Pass: loop-interchange
26 ; CHECK-NEXT: Name: CallInst
27 ; CHECK-NEXT: Function: interchange_01
29 ; CHECK-NEXT: - String: Cannot interchange loops due to call instruction.
31 define void @interchange_01(i32 %k) {
36 %indvars.iv23 = phi i64 [ 0, %entry ], [ %indvars.iv.next24, %for1.inc10 ]
40 %indvars.iv = phi i64 [ %indvars.iv.next, %for2 ], [ 1, %for1.header ]
41 call void @foo(i64 %indvars.iv23)
42 %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], ptr @A, i64 0, i64 %indvars.iv, i64 %indvars.iv23
43 %lv = load i32, ptr %arrayidx5
44 %add = add nsw i32 %lv, %k
45 store i32 %add, ptr %arrayidx5
46 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
47 %exitcond = icmp eq i64 %indvars.iv, 99
48 br i1 %exitcond, label %for2.loopexit , label %for2
54 %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
55 %exitcond26 = icmp eq i64 %indvars.iv23, 99
56 br i1 %exitcond26, label %for1.loopexit, label %for1.header
65 ;;--------------------------------------Test case 02------------------------------------
66 ;; Safe to interchange, because the called function `bar` is marked as readnone,
67 ;; so it cannot introduce dependences.
69 ;; for(int i=0;i<100;i++) {
70 ;; for(int j=1;j<100;j++) {
72 ;; A[j][i] = A[j][i]+k;
77 ; CHECK-NEXT: Pass: loop-interchange
78 ; CHECK-NEXT: Name: Interchanged
79 ; CHECK-NEXT: Function: interchange_02
81 ; CHECK-NEXT: - String: Loop interchanged with enclosing loop.
84 define void @interchange_02(i32 %k) {
89 %indvars.iv23 = phi i64 [ 0, %entry ], [ %indvars.iv.next24, %for1.inc10 ]
93 %indvars.iv = phi i64 [ %indvars.iv.next, %for2 ], [ 1, %for1.header ]
94 call void @bar(i64 %indvars.iv23)
95 %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], ptr @A, i64 0, i64 %indvars.iv, i64 %indvars.iv23
96 %lv = load i32, ptr %arrayidx5
97 %add = add nsw i32 %lv, %k
98 store i32 %add, ptr %arrayidx5
99 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
100 %exitcond = icmp eq i64 %indvars.iv, 99
101 br i1 %exitcond, label %for2.loopexit , label %for2
107 %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
108 %exitcond26 = icmp eq i64 %indvars.iv23, 99
109 br i1 %exitcond26, label %for1.loopexit, label %for1.header
118 ; Check stats, we interchanged 1 out of 2 loops.
119 ; STATS: 1 loop-interchange - Number of loops interchanged