1 ; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -verify-loop-info \ 2 ; RUN: -S -pass-remarks=loop-interchange 2>&1 | FileCheck %s 3 4 @A10 = local_unnamed_addr global [3 x [3 x i32]] zeroinitializer, align 16 5 6 ;; Test to make sure we can handle zext instructions introduced by 7 ;; IndVarSimplify. 8 ;; 9 ;; for (int i = 0; i < 2; ++i) 10 ;; for(int j = 0; j < n; ++j) { 11 ;; A[j][i] = i; 12 ;; } 13 14 ; CHECK: Loop interchanged with enclosing loop. 15 16 @A11 = local_unnamed_addr global [3 x [3 x i32]] zeroinitializer, align 16 17 18 define void @interchange_11(i32 %n) { 19 entry: 20 br label %for.cond1.preheader 21 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 25 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 29 br label %for.body4 30 31 for.cond.cleanup: ; preds = %for.cond.loopexit 32 ret void 33 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]], [3 x [3 x i32]]* @A10, i64 0, i64 %indvars.iv, i64 %indvars.iv.next27 42 %tmp1 = trunc i64 %indvars.iv to i32 43 store i32 %tmp1, i32* %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 48 } 49