1 ; RUN: opt -basicaa -loop-distribute -verify-loop-info -verify-dom-info -S \ 2 ; RUN: < %s | FileCheck %s 3 4 ; RUN: opt -basicaa -loop-distribute -verify-loop-info -verify-dom-info \ 5 ; RUN: -loop-accesses -analyze < %s | FileCheck %s --check-prefix=ANALYSIS 6 7 ; RUN: opt -basicaa -loop-distribute -loop-vectorize -force-vector-width=4 -S \ 8 ; RUN: < %s | FileCheck %s --check-prefix=VECTORIZE 9 10 ; We should distribute this loop into a safe (2nd statement) and unsafe loop 11 ; (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 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 19 target triple = "x86_64-apple-macosx10.10.0" 20 21 define void @f(i32* noalias %a, 22 i32* noalias %b, 23 i32* noalias %c, 24 i32* noalias %d, 25 i32* noalias %e) { 26 entry: 27 br label %for.body 28 29 ; Verify the two distributed loops. 30 31 ; CHECK: entry.split.ldist1: 32 ; CHECK: br label %for.body.ldist1 33 ; CHECK: for.body.ldist1: 34 ; CHECK: %mulA.ldist1 = mul i32 %loadB.ldist1, %loadA.ldist1 35 ; CHECK: br i1 %exitcond.ldist1, label %entry.split, label %for.body.ldist1 36 37 ; CHECK: entry.split: 38 ; CHECK: br label %for.body 39 ; CHECK: for.body: 40 ; CHECK: %mulC = mul i32 %loadD, %loadE 41 ; CHECK: for.end: 42 43 44 ; ANALYSIS: for.body: 45 ; ANALYSIS-NEXT: Memory dependences are safe{{$}} 46 ; ANALYSIS: for.body.ldist1: 47 ; ANALYSIS-NEXT: Report: unsafe dependent memory operations in loop 48 49 50 ; VECTORIZE: mul <4 x i32> 51 52 for.body: ; preds = %for.body, %entry 53 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ] 54 55 %arrayidxA = getelementptr inbounds i32, i32* %a, i64 %ind 56 %loadA = load i32, i32* %arrayidxA, align 4 57 58 %arrayidxB = getelementptr inbounds i32, i32* %b, i64 %ind 59 %loadB = load i32, i32* %arrayidxB, align 4 60 61 %mulA = mul i32 %loadB, %loadA 62 63 %add = add nuw nsw i64 %ind, 1 64 %arrayidxA_plus_4 = getelementptr inbounds i32, i32* %a, i64 %add 65 store i32 %mulA, i32* %arrayidxA_plus_4, align 4 66 67 %arrayidxD = getelementptr inbounds i32, i32* %d, i64 %ind 68 %loadD = load i32, i32* %arrayidxD, align 4 69 70 %arrayidxE = getelementptr inbounds i32, i32* %e, i64 %ind 71 %loadE = load i32, i32* %arrayidxE, align 4 72 73 %mulC = mul i32 %loadD, %loadE 74 75 %arrayidxC = getelementptr inbounds i32, i32* %c, i64 %ind 76 store i32 %mulC, i32* %arrayidxC, align 4 77 78 %exitcond = icmp eq i64 %add, 20 79 br i1 %exitcond, label %for.end, label %for.body 80 81 for.end: ; preds = %for.body 82 ret void 83 } 84