1 ; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 -verify-dom-info -verify-loop-info \
2 ; RUN: -S -pass-remarks=loop-interchange 2>&1 | FileCheck %s
4 @A10 = local_unnamed_addr global [3 x [3 x i32]] zeroinitializer, align 16
6 ;; Test to make sure we can handle zext instructions introduced by
9 ;; for (int i = 0; i < 2; ++i)
10 ;; for(int j = 0; j < n; ++j) {
14 ; CHECK: Loop interchanged with enclosing loop.
16 @A11 = local_unnamed_addr global [3 x [3 x i32]] zeroinitializer, align 16
18 define void @interchange_11(i32 %n) {
20 br label %for.cond1.preheader
22 for.cond.loopexit: ; preds = %for.body4
23 %exitcond28 = icmp ne i64 %indvars.iv.next27, 2
24 br i1 %exitcond28, label %for.cond1.preheader, label %for.cond.cleanup
26 for.cond1.preheader: ; preds = %for.cond.loopexit, %entry
27 %indvars.iv26 = phi i64 [ 0, %entry ], [ %indvars.iv.next27, %for.cond.loopexit ]
28 %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
31 for.cond.cleanup: ; preds = %for.cond.loopexit
34 for.body4: ; preds = %for.body4, %for.cond1.preheader
35 %indvars.iv = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next, %for.body4 ]
36 ; The store below does not appear in the C snippet above.
37 ; With two stores in the loop there may be WAW dependences, and interchange is illegal.
38 ; %arrayidx6 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* @A10, i64 0, i64 %indvars.iv, i64 %indvars.iv26
39 ; %tmp = trunc i64 %indvars.iv26 to i32
40 ; store i32 %tmp, i32* %arrayidx6, align 4
41 %arrayidx10 = getelementptr inbounds [3 x [3 x i32]], ptr @A10, i64 0, i64 %indvars.iv, i64 %indvars.iv.next27
42 %tmp1 = trunc i64 %indvars.iv to i32
43 store i32 %tmp1, ptr %arrayidx10, align 4
44 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
45 %n.wide = zext i32 %n to i64
46 %exitcond = icmp ne i64 %indvars.iv.next, %n.wide
47 br i1 %exitcond, label %for.body4, label %for.cond.loopexit