basic.ll 2.5 KB

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