phi.ll 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. ; RUN: opt < %s -basicaa -slp-vectorizer -slp-threshold=-100 -dce -S -mtriple=i386-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s
  2. target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32-S128"
  3. target triple = "i386-apple-macosx10.9.0"
  4. ;int foo(double *A, int k) {
  5. ; double A0;
  6. ; double A1;
  7. ; if (k) {
  8. ; A0 = 3;
  9. ; A1 = 5;
  10. ; } else {
  11. ; A0 = A[10];
  12. ; A1 = A[11];
  13. ; }
  14. ; A[0] = A0;
  15. ; A[1] = A1;
  16. ;}
  17. ;CHECK: i32 @foo
  18. ;CHECK: load <2 x double>
  19. ;CHECK: phi <2 x double>
  20. ;CHECK: store <2 x double>
  21. ;CHECK: ret i32 undef
  22. define i32 @foo(double* nocapture %A, i32 %k) {
  23. entry:
  24. %tobool = icmp eq i32 %k, 0
  25. br i1 %tobool, label %if.else, label %if.end
  26. if.else: ; preds = %entry
  27. %arrayidx = getelementptr inbounds double, double* %A, i64 10
  28. %0 = load double, double* %arrayidx, align 8
  29. %arrayidx1 = getelementptr inbounds double, double* %A, i64 11
  30. %1 = load double, double* %arrayidx1, align 8
  31. br label %if.end
  32. if.end: ; preds = %entry, %if.else
  33. %A0.0 = phi double [ %0, %if.else ], [ 3.000000e+00, %entry ]
  34. %A1.0 = phi double [ %1, %if.else ], [ 5.000000e+00, %entry ]
  35. store double %A0.0, double* %A, align 8
  36. %arrayidx3 = getelementptr inbounds double, double* %A, i64 1
  37. store double %A1.0, double* %arrayidx3, align 8
  38. ret i32 undef
  39. }
  40. ;int foo(double * restrict B, double * restrict A, int n, int m) {
  41. ; double R=A[1];
  42. ; double G=A[0];
  43. ; for (int i=0; i < 100; i++) {
  44. ; R += 10;
  45. ; G += 10;
  46. ; R *= 4;
  47. ; G *= 4;
  48. ; R += 4;
  49. ; G += 4;
  50. ; }
  51. ; B[0] = G;
  52. ; B[1] = R;
  53. ; return 0;
  54. ;}
  55. ;CHECK: foo2
  56. ;CHECK: load <2 x double>
  57. ;CHECK: phi <2 x double>
  58. ;CHECK: fmul <2 x double>
  59. ;CHECK: store <2 x double>
  60. ;CHECK: ret
  61. define i32 @foo2(double* noalias nocapture %B, double* noalias nocapture %A, i32 %n, i32 %m) #0 {
  62. entry:
  63. %arrayidx = getelementptr inbounds double, double* %A, i64 1
  64. %0 = load double, double* %arrayidx, align 8
  65. %1 = load double, double* %A, align 8
  66. br label %for.body
  67. for.body: ; preds = %for.body, %entry
  68. %i.019 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
  69. %G.018 = phi double [ %1, %entry ], [ %add5, %for.body ]
  70. %R.017 = phi double [ %0, %entry ], [ %add4, %for.body ]
  71. %add = fadd double %R.017, 1.000000e+01
  72. %add2 = fadd double %G.018, 1.000000e+01
  73. %mul = fmul double %add, 4.000000e+00
  74. %mul3 = fmul double %add2, 4.000000e+00
  75. %add4 = fadd double %mul, 4.000000e+00
  76. %add5 = fadd double %mul3, 4.000000e+00
  77. %inc = add nsw i32 %i.019, 1
  78. %exitcond = icmp eq i32 %inc, 100
  79. br i1 %exitcond, label %for.end, label %for.body
  80. for.end: ; preds = %for.body
  81. store double %add5, double* %B, align 8
  82. %arrayidx7 = getelementptr inbounds double, double* %B, i64 1
  83. store double %add4, double* %arrayidx7, align 8
  84. ret i32 0
  85. }
  86. ; float foo3(float *A) {
  87. ;
  88. ; float R = A[0];
  89. ; float G = A[1];
  90. ; float B = A[2];
  91. ; float Y = A[3];
  92. ; float P = A[4];
  93. ; for (int i=0; i < 121; i+=3) {
  94. ; R+=A[i+0]*7;
  95. ; G+=A[i+1]*8;
  96. ; B+=A[i+2]*9;
  97. ; Y+=A[i+3]*10;
  98. ; P+=A[i+4]*11;
  99. ; }
  100. ;
  101. ; return R+G+B+Y+P;
  102. ; }
  103. ;CHECK: foo3
  104. ;CHECK: phi <4 x float>
  105. ;CHECK: fmul <4 x float>
  106. ;CHECK: fadd <4 x float>
  107. ;CHECK-NOT: phi <5 x float>
  108. ;CHECK-NOT: fmul <5 x float>
  109. ;CHECK-NOT: fadd <5 x float>
  110. define float @foo3(float* nocapture readonly %A) #0 {
  111. entry:
  112. %0 = load float, float* %A, align 4
  113. %arrayidx1 = getelementptr inbounds float, float* %A, i64 1
  114. %1 = load float, float* %arrayidx1, align 4
  115. %arrayidx2 = getelementptr inbounds float, float* %A, i64 2
  116. %2 = load float, float* %arrayidx2, align 4
  117. %arrayidx3 = getelementptr inbounds float, float* %A, i64 3
  118. %3 = load float, float* %arrayidx3, align 4
  119. %arrayidx4 = getelementptr inbounds float, float* %A, i64 4
  120. %4 = load float, float* %arrayidx4, align 4
  121. br label %for.body
  122. for.body: ; preds = %for.body, %entry
  123. %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
  124. %P.056 = phi float [ %4, %entry ], [ %add26, %for.body ]
  125. %Y.055 = phi float [ %3, %entry ], [ %add21, %for.body ]
  126. %B.054 = phi float [ %2, %entry ], [ %add16, %for.body ]
  127. %G.053 = phi float [ %1, %entry ], [ %add11, %for.body ]
  128. %R.052 = phi float [ %0, %entry ], [ %add6, %for.body ]
  129. %5 = phi float [ %1, %entry ], [ %11, %for.body ]
  130. %6 = phi float [ %0, %entry ], [ %9, %for.body ]
  131. %mul = fmul float %6, 7.000000e+00
  132. %add6 = fadd float %R.052, %mul
  133. %mul10 = fmul float %5, 8.000000e+00
  134. %add11 = fadd float %G.053, %mul10
  135. %7 = add nsw i64 %indvars.iv, 2
  136. %arrayidx14 = getelementptr inbounds float, float* %A, i64 %7
  137. %8 = load float, float* %arrayidx14, align 4
  138. %mul15 = fmul float %8, 9.000000e+00
  139. %add16 = fadd float %B.054, %mul15
  140. %indvars.iv.next = add nuw nsw i64 %indvars.iv, 3
  141. %arrayidx19 = getelementptr inbounds float, float* %A, i64 %indvars.iv.next
  142. %9 = load float, float* %arrayidx19, align 4
  143. %mul20 = fmul float %9, 1.000000e+01
  144. %add21 = fadd float %Y.055, %mul20
  145. %10 = add nsw i64 %indvars.iv, 4
  146. %arrayidx24 = getelementptr inbounds float, float* %A, i64 %10
  147. %11 = load float, float* %arrayidx24, align 4
  148. %mul25 = fmul float %11, 1.100000e+01
  149. %add26 = fadd float %P.056, %mul25
  150. %12 = trunc i64 %indvars.iv.next to i32
  151. %cmp = icmp slt i32 %12, 121
  152. br i1 %cmp, label %for.body, label %for.end
  153. for.end: ; preds = %for.body
  154. %add28 = fadd float %add6, %add11
  155. %add29 = fadd float %add28, %add16
  156. %add30 = fadd float %add29, %add21
  157. %add31 = fadd float %add30, %add26
  158. ret float %add31
  159. }
  160. ; Make sure the order of phi nodes of different types does not prevent
  161. ; vectorization of same typed phi nodes.
  162. ; CHECK-LABEL: sort_phi_type
  163. ; CHECK: phi <4 x float>
  164. ; CHECK: fmul <4 x float>
  165. define float @sort_phi_type(float* nocapture readonly %A) {
  166. entry:
  167. br label %for.body
  168. for.body: ; preds = %for.body, %entry
  169. %Y = phi float [ 1.000000e+01, %entry ], [ %mul10, %for.body ]
  170. %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
  171. %B = phi float [ 1.000000e+01, %entry ], [ %mul15, %for.body ]
  172. %G = phi float [ 1.000000e+01, %entry ], [ %mul20, %for.body ]
  173. %R = phi float [ 1.000000e+01, %entry ], [ %mul25, %for.body ]
  174. %mul10 = fmul float %Y, 8.000000e+00
  175. %mul15 = fmul float %B, 9.000000e+00
  176. %mul20 = fmul float %R, 10.000000e+01
  177. %mul25 = fmul float %G, 11.100000e+01
  178. %indvars.iv.next = add nsw i64 %indvars.iv, 4
  179. %cmp = icmp slt i64 %indvars.iv.next, 128
  180. br i1 %cmp, label %for.body, label %for.end
  181. for.end: ; preds = %for.body
  182. %add28 = fadd float 1.000000e+01, %mul10
  183. %add29 = fadd float %mul10, %mul15
  184. %add30 = fadd float %add29, %mul20
  185. %add31 = fadd float %add30, %mul25
  186. ret float %add31
  187. }
  188. define void @test(x86_fp80* %i1, x86_fp80* %i2, x86_fp80* %o) {
  189. ; CHECK-LABEL: @test(
  190. ;
  191. ; Test that we correctly recognize the discontiguous memory in arrays where the
  192. ; size is less than the alignment, and through various different GEP formations.
  193. ;
  194. ; We disable the vectorization of x86_fp80 for now.
  195. entry:
  196. %i1.0 = load x86_fp80, x86_fp80* %i1, align 16
  197. %i1.gep1 = getelementptr x86_fp80, x86_fp80* %i1, i64 1
  198. %i1.1 = load x86_fp80, x86_fp80* %i1.gep1, align 16
  199. ; CHECK: load x86_fp80, x86_fp80*
  200. ; CHECK: load x86_fp80, x86_fp80*
  201. ; CHECK-NOT: insertelement <2 x x86_fp80>
  202. ; CHECK-NOT: insertelement <2 x x86_fp80>
  203. br i1 undef, label %then, label %end
  204. then:
  205. %i2.gep0 = getelementptr inbounds x86_fp80, x86_fp80* %i2, i64 0
  206. %i2.0 = load x86_fp80, x86_fp80* %i2.gep0, align 16
  207. %i2.gep1 = getelementptr inbounds x86_fp80, x86_fp80* %i2, i64 1
  208. %i2.1 = load x86_fp80, x86_fp80* %i2.gep1, align 16
  209. ; CHECK: load x86_fp80, x86_fp80*
  210. ; CHECK: load x86_fp80, x86_fp80*
  211. ; CHECK-NOT: insertelement <2 x x86_fp80>
  212. ; CHECK-NOT: insertelement <2 x x86_fp80>
  213. br label %end
  214. end:
  215. %phi0 = phi x86_fp80 [ %i1.0, %entry ], [ %i2.0, %then ]
  216. %phi1 = phi x86_fp80 [ %i1.1, %entry ], [ %i2.1, %then ]
  217. ; CHECK-NOT: phi <2 x x86_fp80>
  218. ; CHECK-NOT: extractelement <2 x x86_fp80>
  219. ; CHECK-NOT: extractelement <2 x x86_fp80>
  220. store x86_fp80 %phi0, x86_fp80* %o, align 16
  221. %o.gep1 = getelementptr inbounds x86_fp80, x86_fp80* %o, i64 1
  222. store x86_fp80 %phi1, x86_fp80* %o.gep1, align 16
  223. ret void
  224. }