outside-use.ll 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ; RUN: opt -loop-distribute -verify-loop-info -verify-dom-info -S < %s \
  2. ; RUN: | FileCheck %s
  3. ; Check that definitions used outside the loop are handled correctly: (1) they
  4. ; are not dropped (2) when version the loop, a phi is added to merge the value
  5. ; from the non-distributed loop and the distributed loop.
  6. ;
  7. ; for (i = 0; i < n; i++) {
  8. ; A[i + 1] = A[i] * B[i];
  9. ; ==========================
  10. ; sum += C[i];
  11. ; }
  12. target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
  13. target triple = "x86_64-apple-macosx10.10.0"
  14. @B = common global i32* null, align 8
  15. @A = common global i32* null, align 8
  16. @C = common global i32* null, align 8
  17. @D = common global i32* null, align 8
  18. @E = common global i32* null, align 8
  19. @SUM = common global i32 0, align 8
  20. define void @f() {
  21. entry:
  22. %a = load i32*, i32** @A, align 8
  23. %b = load i32*, i32** @B, align 8
  24. %c = load i32*, i32** @C, align 8
  25. %d = load i32*, i32** @D, align 8
  26. %e = load i32*, i32** @E, align 8
  27. br label %for.body
  28. ; CHECK: for.body.ldist1:
  29. ; CHECK: %mulA.ldist1 = mul i32 %loadB.ldist1, %loadA.ldist1
  30. ; CHECK: for.body.ph:
  31. ; CHECK: for.body:
  32. ; CHECK: %sum_add = add nuw nsw i32 %sum, %loadC
  33. ; CHECK: for.end:
  34. ; CHECK: %sum_add.lver = phi i32 [ %sum_add, %for.body ], [ %sum_add.lver.orig, %for.body.lver.orig ]
  35. for.body: ; preds = %for.body, %entry
  36. %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
  37. %sum = phi i32 [ 0, %entry ], [ %sum_add, %for.body ]
  38. %arrayidxA = getelementptr inbounds i32, i32* %a, i64 %ind
  39. %loadA = load i32, i32* %arrayidxA, align 4
  40. %arrayidxB = getelementptr inbounds i32, i32* %b, i64 %ind
  41. %loadB = load i32, i32* %arrayidxB, align 4
  42. %mulA = mul i32 %loadB, %loadA
  43. %add = add nuw nsw i64 %ind, 1
  44. %arrayidxA_plus_4 = getelementptr inbounds i32, i32* %a, i64 %add
  45. store i32 %mulA, i32* %arrayidxA_plus_4, align 4
  46. %arrayidxC = getelementptr inbounds i32, i32* %c, i64 %ind
  47. %loadC = load i32, i32* %arrayidxC, align 4
  48. %sum_add = add nuw nsw i32 %sum, %loadC
  49. %exitcond = icmp eq i64 %add, 20
  50. br i1 %exitcond, label %for.end, label %for.body
  51. for.end: ; preds = %for.body
  52. store i32 %sum_add, i32* @SUM, align 4
  53. ret void
  54. }