basic-address-space.ll 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ; RUN: opt -basicaa -loop-idiom < %s -S | FileCheck %s
  2. target datalayout = "e-p:32:32:32-p1:64:64:64-p2:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:32-n8:16:32:64"
  3. target triple = "x86_64-apple-darwin10.0.0"
  4. ; Two dimensional nested loop should be promoted to one big memset.
  5. define void @test10(i8 addrspace(2)* %X) nounwind ssp {
  6. ; CHECK-LABEL: @test10(
  7. ; CHECK: entry:
  8. ; CHECK-NEXT: call void @llvm.memset.p2i8.i16(i8 addrspace(2)* %X, i8 0, i16 10000, i32 1, i1 false)
  9. ; CHECK-NOT: store
  10. ; CHECK: ret void
  11. entry:
  12. br label %bb.nph
  13. bb.nph: ; preds = %entry, %for.inc10
  14. %i.04 = phi i16 [ 0, %entry ], [ %inc12, %for.inc10 ]
  15. br label %for.body5
  16. for.body5: ; preds = %for.body5, %bb.nph
  17. %j.02 = phi i16 [ 0, %bb.nph ], [ %inc, %for.body5 ]
  18. %mul = mul nsw i16 %i.04, 100
  19. %add = add nsw i16 %j.02, %mul
  20. %arrayidx = getelementptr inbounds i8, i8 addrspace(2)* %X, i16 %add
  21. store i8 0, i8 addrspace(2)* %arrayidx, align 1
  22. %inc = add nsw i16 %j.02, 1
  23. %cmp4 = icmp eq i16 %inc, 100
  24. br i1 %cmp4, label %for.inc10, label %for.body5
  25. for.inc10: ; preds = %for.body5
  26. %inc12 = add nsw i16 %i.04, 1
  27. %cmp = icmp eq i16 %inc12, 100
  28. br i1 %cmp, label %for.end13, label %bb.nph
  29. for.end13: ; preds = %for.inc10
  30. ret void
  31. }
  32. define void @test11_pattern(i32 addrspace(2)* nocapture %P) nounwind ssp {
  33. ; CHECK-LABEL: @test11_pattern(
  34. ; CHECK-NOT: memset_pattern
  35. entry:
  36. br label %for.body
  37. for.body: ; preds = %entry, %for.body
  38. %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %for.body ]
  39. %arrayidx = getelementptr i32, i32 addrspace(2)* %P, i64 %indvar
  40. store i32 1, i32 addrspace(2)* %arrayidx, align 4
  41. %indvar.next = add i64 %indvar, 1
  42. %exitcond = icmp eq i64 %indvar.next, 10000
  43. br i1 %exitcond, label %for.end, label %for.body
  44. for.end: ; preds = %for.body
  45. ret void
  46. }
  47. ; PR9815 - This is a partial overlap case that cannot be safely transformed
  48. ; into a memcpy.
  49. @g_50 = addrspace(2) global [7 x i32] [i32 0, i32 0, i32 0, i32 0, i32 1, i32 0, i32 0], align 16
  50. define i32 @test14() nounwind {
  51. ; CHECK-LABEL: @test14(
  52. ; CHECK: for.body:
  53. ; CHECK: load i32
  54. ; CHECK: store i32
  55. ; CHECK: br i1 %cmp
  56. entry:
  57. br label %for.body
  58. for.body: ; preds = %for.inc, %for.body.lr.ph
  59. %tmp5 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
  60. %add = add nsw i32 %tmp5, 4
  61. %idxprom = sext i32 %add to i64
  62. %arrayidx = getelementptr inbounds [7 x i32], [7 x i32] addrspace(2)* @g_50, i32 0, i64 %idxprom
  63. %tmp2 = load i32, i32 addrspace(2)* %arrayidx, align 4
  64. %add4 = add nsw i32 %tmp5, 5
  65. %idxprom5 = sext i32 %add4 to i64
  66. %arrayidx6 = getelementptr inbounds [7 x i32], [7 x i32] addrspace(2)* @g_50, i32 0, i64 %idxprom5
  67. store i32 %tmp2, i32 addrspace(2)* %arrayidx6, align 4
  68. %inc = add nsw i32 %tmp5, 1
  69. %cmp = icmp slt i32 %inc, 2
  70. br i1 %cmp, label %for.body, label %for.end
  71. for.end: ; preds = %for.inc
  72. %tmp8 = load i32, i32 addrspace(2)* getelementptr inbounds ([7 x i32], [7 x i32] addrspace(2)* @g_50, i32 0, i64 6), align 4
  73. ret i32 %tmp8
  74. }