1; RUN: opt < %s -S -loop-flatten -verify-loop-info -verify-dom-info -verify-scev -verify | FileCheck %s 2 3target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" 4 5; Test case and IR corresponding to this code: 6; 7; int k = 0; 8; for(int i = 0; i < n; i++) 9; for(int j = 0; j < n; j++) { 10; A[k] = B[k]; 11; k++; 12; } 13; 14; TODO: this case doesn't trigger yet. 15; 16define dso_local void @v0(i32 %n, i32* nocapture %A, i32* nocapture readonly %B) local_unnamed_addr #0 { 17; 18; CHECK-LABEL: @v0 19; CHECK-NOT: %flatten.tripcount = mul i32 %n, %n 20; 21entry: 22 %cmp21 = icmp sgt i32 %n, 0 23 br i1 %cmp21, label %for.cond1.preheader.us.preheader, label %for.cond.cleanup 24 25for.cond1.preheader.us.preheader: 26 br label %for.cond1.preheader.us 27 28for.cond1.preheader.us: 29 %i.023.us = phi i32 [ %inc8.us, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ 0, %for.cond1.preheader.us.preheader ] 30 %k.022.us = phi i32 [ %inc.us.lcssa, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ 0, %for.cond1.preheader.us.preheader ] 31 %0 = add i32 %n, %k.022.us 32 br label %for.body4.us 33 34for.body4.us: 35 %k.119.us = phi i32 [ %k.022.us, %for.cond1.preheader.us ], [ %inc.us, %for.body4.us ] 36 %arrayidx.us = getelementptr inbounds i32, i32* %B, i32 %k.119.us 37 %1 = load i32, i32* %arrayidx.us, align 4 38 %arrayidx5.us = getelementptr inbounds i32, i32* %A, i32 %k.119.us 39 store i32 %1, i32* %arrayidx5.us, align 4 40 %inc.us = add i32 %k.119.us, 1 41 %exitcond = icmp ne i32 %inc.us, %0 42 br i1 %exitcond, label %for.body4.us, label %for.cond1.for.cond.cleanup3_crit_edge.us 43 44for.cond1.for.cond.cleanup3_crit_edge.us: 45 %inc.us.lcssa = phi i32 [ %inc.us, %for.body4.us ] 46 %inc8.us = add nuw nsw i32 %i.023.us, 1 47 %cmp.us = icmp slt i32 %inc8.us, %n 48 br i1 %cmp.us, label %for.cond1.preheader.us, label %for.cond.cleanup.loopexit 49 50for.cond.cleanup.loopexit: 51 br label %for.cond.cleanup 52 53for.cond.cleanup: 54 ret void 55} 56 57; Test case and IR corresponding to this code: 58; 59; for(int i = 0; i < n; i++) 60; for(int j = 0; j < n; j++) { 61; int k = i*n+j; 62; A[k] = B[k]; 63; k++; 64; } 65; 66define dso_local void @v1(i32 %n, i32* nocapture %A, i32* nocapture readonly %B) local_unnamed_addr #0 { 67; 68; CHECK-LABEL: @v1 69; CHECK: for.cond1.preheader.us.preheader: 70; CHECK: %flatten.tripcount = mul i32 %n, %n 71; CHECK: for.cond1.for.cond.cleanup3_crit_edge.us: 72; CHECK: %inc8.us = add nuw nsw i32 %i.024.us, 1 73; CHECK: %cmp.us = icmp slt i32 %inc8.us, %flatten.tripcount 74; 75entry: 76 %cmp23 = icmp sgt i32 %n, 0 77 br i1 %cmp23, label %for.cond1.preheader.us.preheader, label %for.cond.cleanup 78 79for.cond1.preheader.us.preheader: 80 br label %for.cond1.preheader.us 81 82for.cond1.preheader.us: 83 %i.024.us = phi i32 [ %inc8.us, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ 0, %for.cond1.preheader.us.preheader ] 84 %mul.us = mul nsw i32 %i.024.us, %n 85 br label %for.body4.us 86 87for.body4.us: 88 %j.022.us = phi i32 [ 0, %for.cond1.preheader.us ], [ %inc6.us, %for.body4.us ] 89 %add.us = add nsw i32 %j.022.us, %mul.us 90 %arrayidx.us = getelementptr inbounds i32, i32* %B, i32 %add.us 91 %0 = load i32, i32* %arrayidx.us, align 4 92 %arrayidx5.us = getelementptr inbounds i32, i32* %A, i32 %add.us 93 store i32 %0, i32* %arrayidx5.us, align 4 94 %inc6.us = add nuw nsw i32 %j.022.us, 1 95 %exitcond = icmp ne i32 %inc6.us, %n 96 br i1 %exitcond, label %for.body4.us, label %for.cond1.for.cond.cleanup3_crit_edge.us 97 98for.cond1.for.cond.cleanup3_crit_edge.us: 99 %inc8.us = add nuw nsw i32 %i.024.us, 1 100 %cmp.us = icmp slt i32 %inc8.us, %n 101 br i1 %cmp.us, label %for.cond1.preheader.us, label %for.cond.cleanup.loopexit 102 103for.cond.cleanup.loopexit: 104 br label %for.cond.cleanup 105 106for.cond.cleanup: 107 ret void 108} 109