111 lines · plain
1; RUN: opt -passes=loop-distribute,loop-simplify,loop-versioning -enable-loop-distribute -S < %s | FileCheck %s2 3; Test the metadata generated when versioning an already versioned loop. Here4; we invoke loop distribution to perform the first round of versioning. It5; adds memchecks for accesses that can alias across the distribution boundary.6; Then we further version the distributed loops to fully disambiguate accesses7; within each.8;9; So as an example, we add noalias between C and A during the versioning10; within loop distribution and then add noalias between C and D during the11; second explicit versioning step:12;13; for (i = 0; i < n; i++) {14; A[i + 1] = A[i] * B[i];15; -------------------------------16; C[i] = D[i] * E[i];17; }18 19; To see it easier what's going on, I expanded every noalias/scope metadata20; reference below in a comment. For a scope I use the format scope(domain),21; e.g. scope 17 in domain 15 is written as 17(15).22 23target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"24 25@B = common global ptr null, align 826@A = common global ptr null, align 827@C = common global ptr null, align 828@D = common global ptr null, align 829@E = common global ptr null, align 830 31define void @f() {32entry:33 %a = load ptr, ptr @A, align 834 %b = load ptr, ptr @B, align 835 %c = load ptr, ptr @C, align 836 %d = load ptr, ptr @D, align 837 %e = load ptr, ptr @E, align 838 br label %for.body39 40for.body: ; preds = %for.body, %entry41 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]42 43 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind44 45; CHECK: %loadA.ldist1 = {{.*}} !alias.scope !24, !noalias !2746; A noalias C: !33 -> { 19(17), 20(17), 21(17), 28(26) }47; ^^^^^^48 %loadA = load i32, ptr %arrayidxA, align 449 50 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind51 %loadB = load i32, ptr %arrayidxB, align 452 53 %mulA = mul i32 %loadB, %loadA54 55 %add = add nuw nsw i64 %ind, 156 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add57 store i32 %mulA, ptr %arrayidxA_plus_4, align 458 59; CHECK: for.body:60 61 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind62 63; CHECK: %loadD = {{.*}} !alias.scope !3364; D's scope: !33 -> { 20(17), 34(35) }65; ^^^^^^66 %loadD = load i32, ptr %arrayidxD, align 467 68 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind69 70; CHECK: %loadE = {{.*}} !alias.scope !3671; E's scope: !36 -> { 21(17), 37(33) }72; ^^^^^^73 %loadE = load i32, ptr %arrayidxE, align 474 75 %mulC = mul i32 %loadD, %loadE76 77 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind78 79; CHECK: store i32 %mulC, {{.*}} !alias.scope !38, !noalias !4080; C's scope: !38 -> { 19(17), 39(35)81; ^^^^^^82; C noalias D and E: !38 -> { 21(15), 32(33), 35(33) }83; ^^^^^^ ^^^^^^84 store i32 %mulC, ptr %arrayidxC, align 485 86 %exitcond = icmp eq i64 %add, 2087 br i1 %exitcond, label %for.end, label %for.body88 89for.end: ; preds = %for.body90 ret void91}92 93; Domain for the second loop versioning for the top loop after94; distribution.95; CHECK: !17 = distinct !{!17, !"LVerDomain"}96; CHECK: !19 = distinct !{!19, !17}97; CHECK: !20 = distinct !{!20, !17}98; CHECK: !21 = distinct !{!21, !17}99; CHECK: !27 = !{!19, !20, !21, !28}100; CHECK: !28 = distinct !{!28, !26}101; CHECK: !33 = !{!20, !34}102; CHECK: !34 = distinct !{!34, !35}103; Domain for the second loop versioning for the bottom loop after104; distribution.105; CHECK: !35 = distinct !{!35, !"LVerDomain"}106; CHECK: !36 = !{!21, !37}107; CHECK: !37 = distinct !{!37, !35}108; CHECK: !38 = !{!19, !39}109; CHECK: !39 = distinct !{!39, !35}110; CHECK: !40 = !{!23, !34, !37}111