consecutive-access.ll 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. ; RUN: opt < %s -basicaa -slp-vectorizer -S | FileCheck %s
  2. target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
  3. target triple = "x86_64-apple-macosx10.9.0"
  4. @A = common global [2000 x double] zeroinitializer, align 16
  5. @B = common global [2000 x double] zeroinitializer, align 16
  6. @C = common global [2000 x float] zeroinitializer, align 16
  7. @D = common global [2000 x float] zeroinitializer, align 16
  8. ; Currently SCEV isn't smart enough to figure out that accesses
  9. ; A[3*i], A[3*i+1] and A[3*i+2] are consecutive, but in future
  10. ; that would hopefully be fixed. For now, check that this isn't
  11. ; vectorized.
  12. ; CHECK-LABEL: foo_3double
  13. ; CHECK-NOT: x double>
  14. ; Function Attrs: nounwind ssp uwtable
  15. define void @foo_3double(i32 %u) #0 {
  16. entry:
  17. %u.addr = alloca i32, align 4
  18. store i32 %u, i32* %u.addr, align 4
  19. %mul = mul nsw i32 %u, 3
  20. %idxprom = sext i32 %mul to i64
  21. %arrayidx = getelementptr inbounds [2000 x double], [2000 x double]* @A, i32 0, i64 %idxprom
  22. %0 = load double, double* %arrayidx, align 8
  23. %arrayidx4 = getelementptr inbounds [2000 x double], [2000 x double]* @B, i32 0, i64 %idxprom
  24. %1 = load double, double* %arrayidx4, align 8
  25. %add5 = fadd double %0, %1
  26. store double %add5, double* %arrayidx, align 8
  27. %add11 = add nsw i32 %mul, 1
  28. %idxprom12 = sext i32 %add11 to i64
  29. %arrayidx13 = getelementptr inbounds [2000 x double], [2000 x double]* @A, i32 0, i64 %idxprom12
  30. %2 = load double, double* %arrayidx13, align 8
  31. %arrayidx17 = getelementptr inbounds [2000 x double], [2000 x double]* @B, i32 0, i64 %idxprom12
  32. %3 = load double, double* %arrayidx17, align 8
  33. %add18 = fadd double %2, %3
  34. store double %add18, double* %arrayidx13, align 8
  35. %add24 = add nsw i32 %mul, 2
  36. %idxprom25 = sext i32 %add24 to i64
  37. %arrayidx26 = getelementptr inbounds [2000 x double], [2000 x double]* @A, i32 0, i64 %idxprom25
  38. %4 = load double, double* %arrayidx26, align 8
  39. %arrayidx30 = getelementptr inbounds [2000 x double], [2000 x double]* @B, i32 0, i64 %idxprom25
  40. %5 = load double, double* %arrayidx30, align 8
  41. %add31 = fadd double %4, %5
  42. store double %add31, double* %arrayidx26, align 8
  43. ret void
  44. }
  45. ; SCEV should be able to tell that accesses A[C1 + C2*i], A[C1 + C2*i], ...
  46. ; A[C1 + C2*i] are consecutive, if C2 is a power of 2, and C2 > C1 > 0.
  47. ; Thus, the following code should be vectorized.
  48. ; CHECK-LABEL: foo_2double
  49. ; CHECK: x double>
  50. ; Function Attrs: nounwind ssp uwtable
  51. define void @foo_2double(i32 %u) #0 {
  52. entry:
  53. %u.addr = alloca i32, align 4
  54. store i32 %u, i32* %u.addr, align 4
  55. %mul = mul nsw i32 %u, 2
  56. %idxprom = sext i32 %mul to i64
  57. %arrayidx = getelementptr inbounds [2000 x double], [2000 x double]* @A, i32 0, i64 %idxprom
  58. %0 = load double, double* %arrayidx, align 8
  59. %arrayidx4 = getelementptr inbounds [2000 x double], [2000 x double]* @B, i32 0, i64 %idxprom
  60. %1 = load double, double* %arrayidx4, align 8
  61. %add5 = fadd double %0, %1
  62. store double %add5, double* %arrayidx, align 8
  63. %add11 = add nsw i32 %mul, 1
  64. %idxprom12 = sext i32 %add11 to i64
  65. %arrayidx13 = getelementptr inbounds [2000 x double], [2000 x double]* @A, i32 0, i64 %idxprom12
  66. %2 = load double, double* %arrayidx13, align 8
  67. %arrayidx17 = getelementptr inbounds [2000 x double], [2000 x double]* @B, i32 0, i64 %idxprom12
  68. %3 = load double, double* %arrayidx17, align 8
  69. %add18 = fadd double %2, %3
  70. store double %add18, double* %arrayidx13, align 8
  71. ret void
  72. }
  73. ; Similar to the previous test, but with different datatype.
  74. ; CHECK-LABEL: foo_4float
  75. ; CHECK: x float>
  76. ; Function Attrs: nounwind ssp uwtable
  77. define void @foo_4float(i32 %u) #0 {
  78. entry:
  79. %u.addr = alloca i32, align 4
  80. store i32 %u, i32* %u.addr, align 4
  81. %mul = mul nsw i32 %u, 4
  82. %idxprom = sext i32 %mul to i64
  83. %arrayidx = getelementptr inbounds [2000 x float], [2000 x float]* @C, i32 0, i64 %idxprom
  84. %0 = load float, float* %arrayidx, align 4
  85. %arrayidx4 = getelementptr inbounds [2000 x float], [2000 x float]* @D, i32 0, i64 %idxprom
  86. %1 = load float, float* %arrayidx4, align 4
  87. %add5 = fadd float %0, %1
  88. store float %add5, float* %arrayidx, align 4
  89. %add11 = add nsw i32 %mul, 1
  90. %idxprom12 = sext i32 %add11 to i64
  91. %arrayidx13 = getelementptr inbounds [2000 x float], [2000 x float]* @C, i32 0, i64 %idxprom12
  92. %2 = load float, float* %arrayidx13, align 4
  93. %arrayidx17 = getelementptr inbounds [2000 x float], [2000 x float]* @D, i32 0, i64 %idxprom12
  94. %3 = load float, float* %arrayidx17, align 4
  95. %add18 = fadd float %2, %3
  96. store float %add18, float* %arrayidx13, align 4
  97. %add24 = add nsw i32 %mul, 2
  98. %idxprom25 = sext i32 %add24 to i64
  99. %arrayidx26 = getelementptr inbounds [2000 x float], [2000 x float]* @C, i32 0, i64 %idxprom25
  100. %4 = load float, float* %arrayidx26, align 4
  101. %arrayidx30 = getelementptr inbounds [2000 x float], [2000 x float]* @D, i32 0, i64 %idxprom25
  102. %5 = load float, float* %arrayidx30, align 4
  103. %add31 = fadd float %4, %5
  104. store float %add31, float* %arrayidx26, align 4
  105. %add37 = add nsw i32 %mul, 3
  106. %idxprom38 = sext i32 %add37 to i64
  107. %arrayidx39 = getelementptr inbounds [2000 x float], [2000 x float]* @C, i32 0, i64 %idxprom38
  108. %6 = load float, float* %arrayidx39, align 4
  109. %arrayidx43 = getelementptr inbounds [2000 x float], [2000 x float]* @D, i32 0, i64 %idxprom38
  110. %7 = load float, float* %arrayidx43, align 4
  111. %add44 = fadd float %6, %7
  112. store float %add44, float* %arrayidx39, align 4
  113. ret void
  114. }
  115. ; Similar to the previous tests, but now we are dealing with AddRec SCEV.
  116. ; CHECK-LABEL: foo_loop
  117. ; CHECK: x double>
  118. ; Function Attrs: nounwind ssp uwtable
  119. define i32 @foo_loop(double* %A, i32 %n) #0 {
  120. entry:
  121. %A.addr = alloca double*, align 8
  122. %n.addr = alloca i32, align 4
  123. %sum = alloca double, align 8
  124. %i = alloca i32, align 4
  125. store double* %A, double** %A.addr, align 8
  126. store i32 %n, i32* %n.addr, align 4
  127. store double 0.000000e+00, double* %sum, align 8
  128. store i32 0, i32* %i, align 4
  129. %cmp1 = icmp slt i32 0, %n
  130. br i1 %cmp1, label %for.body.lr.ph, label %for.end
  131. for.body.lr.ph: ; preds = %entry
  132. br label %for.body
  133. for.body: ; preds = %for.body.lr.ph, %for.body
  134. %0 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
  135. %1 = phi double [ 0.000000e+00, %for.body.lr.ph ], [ %add7, %for.body ]
  136. %mul = mul nsw i32 %0, 2
  137. %idxprom = sext i32 %mul to i64
  138. %arrayidx = getelementptr inbounds double, double* %A, i64 %idxprom
  139. %2 = load double, double* %arrayidx, align 8
  140. %mul1 = fmul double 7.000000e+00, %2
  141. %add = add nsw i32 %mul, 1
  142. %idxprom3 = sext i32 %add to i64
  143. %arrayidx4 = getelementptr inbounds double, double* %A, i64 %idxprom3
  144. %3 = load double, double* %arrayidx4, align 8
  145. %mul5 = fmul double 7.000000e+00, %3
  146. %add6 = fadd double %mul1, %mul5
  147. %add7 = fadd double %1, %add6
  148. store double %add7, double* %sum, align 8
  149. %inc = add nsw i32 %0, 1
  150. store i32 %inc, i32* %i, align 4
  151. %cmp = icmp slt i32 %inc, %n
  152. br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
  153. for.cond.for.end_crit_edge: ; preds = %for.body
  154. %split = phi double [ %add7, %for.body ]
  155. br label %for.end
  156. for.end: ; preds = %for.cond.for.end_crit_edge, %entry
  157. %.lcssa = phi double [ %split, %for.cond.for.end_crit_edge ], [ 0.000000e+00, %entry ]
  158. %conv = fptosi double %.lcssa to i32
  159. ret i32 %conv
  160. }
  161. attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
  162. !llvm.ident = !{!0}
  163. !0 = !{!"clang version 3.5.0 "}