struct_access.ll 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ; RUN: opt < %s -loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -instcombine -S | FileCheck %s
  2. target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
  3. target triple = "x86_64-apple-macosx10.9.0"
  4. %struct.coordinate = type { i32, i32 }
  5. ; Make sure that we don't generate a wide load when accessing the struct.
  6. ; struct coordinate {
  7. ; int x;
  8. ; int y;
  9. ; };
  10. ;
  11. ;
  12. ; int foo(struct coordinate *A, int n) {
  13. ;
  14. ; int sum = 0;
  15. ; for (int i = 0; i < n; ++i)
  16. ; sum += A[i].x;
  17. ;
  18. ; return sum;
  19. ; }
  20. ;CHECK-LABEL: @foo(
  21. ;CHECK-NOT: load <4 x i32>
  22. ;CHECK: ret
  23. define i32 @foo(%struct.coordinate* nocapture %A, i32 %n) nounwind uwtable readonly ssp {
  24. entry:
  25. %cmp4 = icmp sgt i32 %n, 0
  26. br i1 %cmp4, label %for.body, label %for.end
  27. for.body: ; preds = %entry, %for.body
  28. %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
  29. %sum.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
  30. %x = getelementptr inbounds %struct.coordinate, %struct.coordinate* %A, i64 %indvars.iv, i32 0
  31. %0 = load i32, i32* %x, align 4
  32. %add = add nsw i32 %0, %sum.05
  33. %indvars.iv.next = add i64 %indvars.iv, 1
  34. %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  35. %exitcond = icmp eq i32 %lftr.wideiv, %n
  36. br i1 %exitcond, label %for.end, label %for.body
  37. for.end: ; preds = %for.body, %entry
  38. %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.body ]
  39. ret i32 %sum.0.lcssa
  40. }
  41. %struct.lit = type { i32 }
  42. ; Verify that we still vectorize the access if the struct has the same size as
  43. ; the loaded element.
  44. ; struct lit {
  45. ; int x;
  46. ; };
  47. ;
  48. ;
  49. ; int bar(struct lit *A, int n) {
  50. ;
  51. ; int sum = 0;
  52. ; for (int i = 0; i < n; ++i)
  53. ; sum += A[i].x;
  54. ;
  55. ; return sum;
  56. ; }
  57. ;CHECK-LABEL: @bar(
  58. ;CHECK: load <4 x i32>
  59. ;CHECK: ret
  60. define i32 @bar(%struct.lit* nocapture %A, i32 %n) nounwind uwtable readonly ssp {
  61. entry:
  62. %cmp4 = icmp sgt i32 %n, 0
  63. br i1 %cmp4, label %for.body, label %for.end
  64. for.body: ; preds = %entry, %for.body
  65. %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
  66. %sum.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
  67. %x = getelementptr inbounds %struct.lit, %struct.lit* %A, i64 %indvars.iv, i32 0
  68. %0 = load i32, i32* %x, align 4
  69. %add = add nsw i32 %0, %sum.05
  70. %indvars.iv.next = add i64 %indvars.iv, 1
  71. %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  72. %exitcond = icmp eq i32 %lftr.wideiv, %n
  73. br i1 %exitcond, label %for.end, label %for.body
  74. for.end: ; preds = %for.body, %entry
  75. %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.body ]
  76. ret i32 %sum.0.lcssa
  77. }