149 lines · plain
1; RUN: opt -aa-pipeline=basic-aa -passes=loop-distribute -enable-loop-distribute -verify-loop-info -verify-dom-info -S \2; RUN: < %s | FileCheck %s3 4; RUN: opt -aa-pipeline=basic-aa -passes='loop-distribute,print<access-info>' -enable-loop-distribute \5; RUN: -verify-loop-info -verify-dom-info -disable-output < %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS6 7; RUN: opt -aa-pipeline=basic-aa -passes=loop-distribute,loop-vectorize -enable-loop-distribute -force-vector-width=4 -S \8; RUN: < %s | FileCheck %s --check-prefix=VECTORIZE9 10; We should distribute this loop into a safe (2nd statement) and unsafe loop11; (1st statement):12; for (i = 0; i < n; i++) {13; A[i + 1] = A[i] * B[i];14; =======================15; C[i] = D[i] * E[i];16; }17 18; CHECK-LABEL: @f(19define void @f(ptr noalias %a, ptr noalias %b, ptr noalias %c, ptr noalias %d, ptr noalias %e) {20entry:21 br label %for.body22 23; Verify the two distributed loops.24 25; CHECK: entry.split.ldist1:26; CHECK: br label %for.body.ldist127; CHECK: for.body.ldist1:28; CHECK: %mulA.ldist1 = mul i32 %loadB.ldist1, %loadA.ldist129; CHECK: br i1 %exitcond.ldist1, label %entry.split, label %for.body.ldist130 31; CHECK: entry.split:32; CHECK: br label %for.body33; CHECK: for.body:34; CHECK: %mulC = mul i32 %loadD, %loadE35; CHECK: for.end:36 37 38; ANALYSIS: for.body.ldist1:39; ANALYSIS-NEXT: Report: unsafe dependent memory operations in loop40; ANALYSIS: for.body:41; ANALYSIS-NEXT: Memory dependences are safe{{$}}42 43 44; VECTORIZE: mul <4 x i32>45 46for.body: ; preds = %for.body, %entry47 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]48 49 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind50 %loadA = load i32, ptr %arrayidxA, align 451 52 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind53 %loadB = load i32, ptr %arrayidxB, align 454 55 %mulA = mul i32 %loadB, %loadA56 57 %add = add nuw nsw i64 %ind, 158 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add59 store i32 %mulA, ptr %arrayidxA_plus_4, align 460 61 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind62 %loadD = load i32, ptr %arrayidxD, align 463 64 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind65 %loadE = load i32, ptr %arrayidxE, align 466 67 %mulC = mul i32 %loadD, %loadE68 69 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind70 store i32 %mulC, ptr %arrayidxC, align 471 72 %exitcond = icmp eq i64 %add, 2073 br i1 %exitcond, label %for.end, label %for.body74 75for.end: ; preds = %for.body76 ret void77}78 79declare i32 @llvm.convergent(i32) #080 81; It is OK to distribute with a convergent operation, since in each82; new loop the convergent operation has the ssame control dependency.83; CHECK-LABEL: @f_with_convergent(84define void @f_with_convergent(ptr noalias %a, ptr noalias %b, ptr noalias %c, ptr noalias %d, ptr noalias %e) {85entry:86 br label %for.body87 88; Verify the two distributed loops.89 90; CHECK: entry.split.ldist1:91; CHECK: br label %for.body.ldist192; CHECK: for.body.ldist1:93; CHECK: %mulA.ldist1 = mul i32 %loadB.ldist1, %loadA.ldist194; CHECK: br i1 %exitcond.ldist1, label %entry.split, label %for.body.ldist195 96; CHECK: entry.split:97; CHECK: br label %for.body98; CHECK: for.body:99; CHECK: %convergentD = call i32 @llvm.convergent(i32 %loadD)100; CHECK: %mulC = mul i32 %convergentD, %loadE101; CHECK: for.end:102 103 104; ANALYSIS: for.body.ldist1:105; ANALYSIS-NEXT: Report: unsafe dependent memory operations in loop106; ANALYSIS: for.body:107; ANALYSIS-NEXT: Has convergent operation in loop108; ANALYSIS-NEXT: Report: cannot add control dependency to convergent operation109 110; convergent instruction happens to block vectorization111; VECTORIZE: call i32 @llvm.convergent112; VECTORIZE: mul i32113 114for.body: ; preds = %for.body, %entry115 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]116 117 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind118 %loadA = load i32, ptr %arrayidxA, align 4119 120 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind121 %loadB = load i32, ptr %arrayidxB, align 4122 123 %mulA = mul i32 %loadB, %loadA124 125 %add = add nuw nsw i64 %ind, 1126 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add127 store i32 %mulA, ptr %arrayidxA_plus_4, align 4128 129 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind130 %loadD = load i32, ptr %arrayidxD, align 4131 132 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind133 %loadE = load i32, ptr %arrayidxE, align 4134 135 %convergentD = call i32 @llvm.convergent(i32 %loadD)136 %mulC = mul i32 %convergentD, %loadE137 138 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind139 store i32 %mulC, ptr %arrayidxC, align 4140 141 %exitcond = icmp eq i64 %add, 20142 br i1 %exitcond, label %for.end, label %for.body143 144for.end: ; preds = %for.body145 ret void146}147 148attributes #0 = { nounwind readnone convergent }149