1; RUN: opt -S -loop-fusion -loop-fusion-peel-max-count=3 < %s | FileCheck %s 2 3; Tests if we are able to fuse two guarded loops which have constant but 4; different trip counts. The first two iterations of the first loop should be 5; peeled off, and then the loops should be fused together. 6 7@B = common global [1024 x i32] zeroinitializer, align 16 8 9; CHECK-LABEL: void @main(i32* noalias %A) 10; CHECK-NEXT: entry: 11; CHECK: br i1 %cmp4, label %for.first.entry, label %for.end 12; CHECK: for.first.entry 13; CHECK-NEXT: br label %for.first.peel.begin 14; CHECK: for.first.peel.begin: 15; CHECK-NEXT: br label %for.first.peel 16; CHECK: for.first.peel: 17; CHECK: br label %for.first.peel.next 18; CHECK: for.first.peel.next: 19; CHECK-NEXT: br label %for.first.peel2 20; CHECK: for.first.peel2: 21; CHECK: br label %for.first.peel.next1 22; CHECK: for.first.peel.next1: 23; CHECK-NEXT: br label %for.first.peel.next11 24; CHECK: for.first.peel.next11: 25; CHECK-NEXT: br label %for.first.entry.peel.newph 26; CHECK: for.first.entry.peel.newph: 27; CHECK: br label %for.first 28; CHECK: for.first: 29; CHECK: br i1 %cmp3, label %for.first, label %for.second.exit 30; CHECK: for.second.exit: 31; CHECK: br label %for.end 32; CHECK: for.end: 33; CHECK-NEXT: ret void 34 35define void @main(i32* noalias %A) { 36entry: 37 %cmp4 = icmp slt i64 0, 45 38 br i1 %cmp4, label %for.first.entry, label %for.second.guard 39 40for.first.entry: ; preds = %entry 41 br label %for.first 42 43for.first: ; preds = %for.first.entry, %for.first 44 %i.05 = phi i64 [ %inc, %for.first ], [ 0, %for.first.entry ] 45 %sub = sub nsw i64 %i.05, 3 46 %add = add nsw i64 %i.05, 3 47 %mul = mul nsw i64 %sub, %add 48 %rem = srem i64 %mul, %i.05 49 %conv = trunc i64 %rem to i32 50 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %i.05 51 store i32 %conv, i32* %arrayidx, align 4 52 %inc = add nsw i64 %i.05, 1 53 %cmp = icmp slt i64 %inc, 45 54 br i1 %cmp, label %for.first, label %for.first.exit 55 56for.first.exit: ; preds = %for.first 57 br label %for.second.guard 58 59for.second.guard: ; preds = %for.first.exit, %entry 60 %cmp31 = icmp slt i64 2, 45 61 br i1 %cmp31, label %for.second.entry, label %for.end 62 63for.second.entry: ; preds = %for.second.guard 64 br label %for.second 65 66for.second: ; preds = %for.second.entry, %for.second 67 %i1.02 = phi i64 [ %inc14, %for.second ], [ 2, %for.second.entry ] 68 %sub7 = sub nsw i64 %i1.02, 3 69 %add8 = add nsw i64 %i1.02, 3 70 %mul9 = mul nsw i64 %sub7, %add8 71 %rem10 = srem i64 %mul9, %i1.02 72 %conv11 = trunc i64 %rem10 to i32 73 %arrayidx12 = getelementptr inbounds [1024 x i32], [1024 x i32]* @B, i64 0, i64 %i1.02 74 store i32 %conv11, i32* %arrayidx12, align 4 75 %inc14 = add nsw i64 %i1.02, 1 76 %cmp3 = icmp slt i64 %inc14, 45 77 br i1 %cmp3, label %for.second, label %for.second.exit 78 79for.second.exit: ; preds = %for.second 80 br label %for.end 81 82for.end: ; preds = %for.second.exit, %for.second.guard 83 ret void 84} 85