vectorize-once.ll 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ; RUN: opt < %s -loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -dce -instcombine -S -simplifycfg | 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.8.0"
  4. ;
  5. ; We want to make sure that we are vectorizeing the scalar loop only once
  6. ; even if the pass manager runs the vectorizer multiple times due to inlining.
  7. ; This test checks that we add metadata to vectorized loops
  8. ; CHECK-LABEL: @_Z4foo1Pii(
  9. ; CHECK: <4 x i32>
  10. ; CHECK: llvm.loop
  11. ; CHECK: ret
  12. ; This test comes from the loop:
  13. ;
  14. ;int foo (int *A, int n) {
  15. ; return std::accumulate(A, A + n, 0);
  16. ;}
  17. define i32 @_Z4foo1Pii(i32* %A, i32 %n) #0 {
  18. entry:
  19. %idx.ext = sext i32 %n to i64
  20. %add.ptr = getelementptr inbounds i32, i32* %A, i64 %idx.ext
  21. %cmp3.i = icmp eq i32 %n, 0
  22. br i1 %cmp3.i, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %for.body.i
  23. for.body.i: ; preds = %entry, %for.body.i
  24. %__init.addr.05.i = phi i32 [ %add.i, %for.body.i ], [ 0, %entry ]
  25. %__first.addr.04.i = phi i32* [ %incdec.ptr.i, %for.body.i ], [ %A, %entry ]
  26. %0 = load i32, i32* %__first.addr.04.i, align 4
  27. %add.i = add nsw i32 %0, %__init.addr.05.i
  28. %incdec.ptr.i = getelementptr inbounds i32, i32* %__first.addr.04.i, i64 1
  29. %cmp.i = icmp eq i32* %incdec.ptr.i, %add.ptr
  30. br i1 %cmp.i, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %for.body.i
  31. _ZSt10accumulateIPiiET0_T_S2_S1_.exit: ; preds = %for.body.i, %entry
  32. %__init.addr.0.lcssa.i = phi i32 [ 0, %entry ], [ %add.i, %for.body.i ]
  33. ret i32 %__init.addr.0.lcssa.i
  34. }
  35. ; This test checks that we don't vectorize loops that are marked with the "width" == 1 metadata.
  36. ; CHECK-LABEL: @_Z4foo2Pii(
  37. ; CHECK-NOT: <4 x i32>
  38. ; CHECK: llvm.loop
  39. ; CHECK: ret
  40. define i32 @_Z4foo2Pii(i32* %A, i32 %n) #0 {
  41. entry:
  42. %idx.ext = sext i32 %n to i64
  43. %add.ptr = getelementptr inbounds i32, i32* %A, i64 %idx.ext
  44. %cmp3.i = icmp eq i32 %n, 0
  45. br i1 %cmp3.i, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %for.body.i
  46. for.body.i: ; preds = %entry, %for.body.i
  47. %__init.addr.05.i = phi i32 [ %add.i, %for.body.i ], [ 0, %entry ]
  48. %__first.addr.04.i = phi i32* [ %incdec.ptr.i, %for.body.i ], [ %A, %entry ]
  49. %0 = load i32, i32* %__first.addr.04.i, align 4
  50. %add.i = add nsw i32 %0, %__init.addr.05.i
  51. %incdec.ptr.i = getelementptr inbounds i32, i32* %__first.addr.04.i, i64 1
  52. %cmp.i = icmp eq i32* %incdec.ptr.i, %add.ptr
  53. br i1 %cmp.i, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %for.body.i, !llvm.loop !0
  54. _ZSt10accumulateIPiiET0_T_S2_S1_.exit: ; preds = %for.body.i, %entry
  55. %__init.addr.0.lcssa.i = phi i32 [ 0, %entry ], [ %add.i, %for.body.i ]
  56. ret i32 %__init.addr.0.lcssa.i
  57. }
  58. attributes #0 = { nounwind readonly ssp uwtable "fp-contract-model"="standard" "no-frame-pointer-elim" "no-frame-pointer-elim-non-leaf" "realign-stack" "relocation-model"="pic" "ssp-buffers-size"="8" }
  59. ; CHECK: !0 = distinct !{!0, !1, !2}
  60. ; CHECK: !1 = !{!"llvm.loop.vectorize.width", i32 1}
  61. ; CHECK: !2 = !{!"llvm.loop.interleave.count", i32 1}
  62. ; CHECK: !3 = distinct !{!3, !4, !1, !2}
  63. ; CHECK: !4 = !{!"llvm.loop.unroll.runtime.disable"}
  64. !0 = !{!0, !1}
  65. !1 = !{!"llvm.loop.vectorize.width", i32 1}