1 ; RUN: opt -basicaa -loop-distribute -scoped-noalias -loop-versioning -S < %s | FileCheck %s 2 3 ; Test the metadata generated when versioning an already versioned loop. Here 4 ; we invoke loop distribution to perform the first round of versioning. It 5 ; adds memchecks for accesses that can alias across the distribution boundary. 6 ; Then we further version the distributed loops to fully disambiguate accesses 7 ; within each. 8 ; 9 ; So as an example, we add noalias between C and A during the versioning 10 ; within loop distribution and then add noalias between C and D during the 11 ; 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 metadata 20 ; 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 23 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 24 25 @B = common global i32* null, align 8 26 @A = common global i32* null, align 8 27 @C = common global i32* null, align 8 28 @D = common global i32* null, align 8 29 @E = common global i32* null, align 8 30 31 define void @f() { 32 entry: 33 %a = load i32*, i32** @A, align 8 34 %b = load i32*, i32** @B, align 8 35 %c = load i32*, i32** @C, align 8 36 %d = load i32*, i32** @D, align 8 37 %e = load i32*, i32** @E, align 8 38 br label %for.body 39 40 for.body: ; preds = %for.body, %entry 41 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ] 42 43 %arrayidxA = getelementptr inbounds i32, i32* %a, i64 %ind 44 45 ; CHECK: %loadA.ldist1 = {{.*}} !noalias !25 46 ; A noalias C: !25 -> { 17(15), 18(15), 19(15), 26(24) } 47 ; ^^^^^^ 48 %loadA = load i32, i32* %arrayidxA, align 4 49 50 %arrayidxB = getelementptr inbounds i32, i32* %b, i64 %ind 51 %loadB = load i32, i32* %arrayidxB, align 4 52 53 %mulA = mul i32 %loadB, %loadA 54 55 %add = add nuw nsw i64 %ind, 1 56 %arrayidxA_plus_4 = getelementptr inbounds i32, i32* %a, i64 %add 57 store i32 %mulA, i32* %arrayidxA_plus_4, align 4 58 59 ; CHECK: for.body: 60 61 %arrayidxD = getelementptr inbounds i32, i32* %d, i64 %ind 62 63 ; CHECK: %loadD = {{.*}} !alias.scope !31 64 ; D's scope: !31 -> { 18(15), 32(33) } 65 ; ^^^^^^ 66 %loadD = load i32, i32* %arrayidxD, align 4 67 68 %arrayidxE = getelementptr inbounds i32, i32* %e, i64 %ind 69 70 ; CHECK: %loadE = {{.*}} !alias.scope !34 71 ; E's scope: !34 -> { 19(15), 35(33) } 72 ; ^^^^^^ 73 %loadE = load i32, i32* %arrayidxE, align 4 74 75 %mulC = mul i32 %loadD, %loadE 76 77 %arrayidxC = getelementptr inbounds i32, i32* %c, i64 %ind 78 79 ; CHECK: store i32 %mulC, {{.*}} !alias.scope !36, !noalias !38 80 ; C's scope: !36 -> { 17(15), 37(33) } 81 ; ^^^^^^ 82 ; C noalias D and E: !38 -> { 21(15), 32(33), 35(33) } 83 ; ^^^^^^ ^^^^^^ 84 store i32 %mulC, i32* %arrayidxC, align 4 85 86 %exitcond = icmp eq i64 %add, 20 87 br i1 %exitcond, label %for.end, label %for.body 88 89 for.end: ; preds = %for.body 90 ret void 91 } 92 93 ; Domain for the second loop versioning for the top loop after 94 ; distribution. 95 ; CHECK: !15 = distinct !{!15, !"LVerDomain"} 96 ; CHECK: !17 = distinct !{!17, !15} 97 ; CHECK: !25 = !{!17, !18, !19, !26} 98 ; CHECK: !31 = !{!18, !32} 99 ; CHECK: !32 = distinct !{!32, !33} 100 ; Domain for the second loop versioning for the bottom loop after 101 ; distribution. 102 ; CHECK: !33 = distinct !{!33, !"LVerDomain"} 103 ; CHECK: !34 = !{!19, !35} 104 ; CHECK: !35 = distinct !{!35, !33} 105 ; CHECK: !36 = !{!17, !37} 106 ; CHECK: !38 = !{!21, !32, !35} 107