2 ; RUN: opt < %s -basicaa -loop-interchange -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"
7 target triple = "x86_64-unknown-linux-gnu"
9 @A = common global [100 x [100 x i32]] zeroinitializer
11 declare void @foo(i64 %a)
12 declare void @bar(i64 %a) readnone
14 ;;--------------------------------------Test case 01------------------------------------
15 ;; Not safe to interchange, because the called function `foo` is not marked as
16 ;; readnone, so it could introduce dependences.
18 ;; for(int i=0;i<100;i++) {
19 ;; for(int j=1;j<100;j++) {
21 ;; A[j][i] = A[j][i]+k;
26 ; CHECK-NEXT: Pass: loop-interchange
27 ; CHECK-NEXT: Name: CallInst
28 ; CHECK-NEXT: Function: interchange_01
30 ; CHECK-NEXT - String: Cannot interchange loops due to call instruction.
32 define void @interchange_01(i32 %k) {
37 %indvars.iv23 = phi i64 [ 0, %entry ], [ %indvars.iv.next24, %for1.inc10 ]
41 %indvars.iv = phi i64 [ %indvars.iv.next, %for2 ], [ 1, %for1.header ]
42 call void @foo(i64 %indvars.iv23)
43 %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv, i64 %indvars.iv23
44 %lv = load i32, i32* %arrayidx5
45 %add = add nsw i32 %lv, %k
46 store i32 %add, i32* %arrayidx5
47 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
48 %exitcond = icmp eq i64 %indvars.iv, 99
49 br i1 %exitcond, label %for2.loopexit , label %for2
55 %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
56 %exitcond26 = icmp eq i64 %indvars.iv23, 99
57 br i1 %exitcond26, label %for1.loopexit, label %for1.header
66 ;;--------------------------------------Test case 02------------------------------------
67 ;; Safe to interchange, because the called function `bar` is marked as readnone,
68 ;; so it cannot introduce dependences.
70 ;; for(int i=0;i<100;i++) {
71 ;; for(int j=1;j<100;j++) {
73 ;; A[j][i] = A[j][i]+k;
78 ; CHECK-NEXT: Pass: loop-interchange
79 ; CHECK-NEXT: Name: Interchanged
80 ; CHECK-NEXT: Function: interchange_02
82 ; CHECK-NEXT: - String: Loop interchanged with enclosing loop.
85 define void @interchange_02(i32 %k) {
90 %indvars.iv23 = phi i64 [ 0, %entry ], [ %indvars.iv.next24, %for1.inc10 ]
94 %indvars.iv = phi i64 [ %indvars.iv.next, %for2 ], [ 1, %for1.header ]
95 call void @bar(i64 %indvars.iv23)
96 %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv, i64 %indvars.iv23
97 %lv = load i32, i32* %arrayidx5
98 %add = add nsw i32 %lv, %k
99 store i32 %add, i32* %arrayidx5
100 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
101 %exitcond = icmp eq i64 %indvars.iv, 99
102 br i1 %exitcond, label %for2.loopexit , label %for2
108 %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
109 %exitcond26 = icmp eq i64 %indvars.iv23, 99
110 br i1 %exitcond26, label %for1.loopexit, label %for1.header
119 ; Check stats, we interchanged 1 out of 2 loops.
120 ; STATS: 1 loop-interchange - Number of loops interchanged