nonescaping-malloc.ll 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ; REQUIRES: asserts
  2. ; RUN: opt < %s -basicaa -gvn -stats -disable-output 2>&1 | grep "Number of loads deleted"
  3. ; rdar://7363102
  4. ; GVN should be able to eliminate load %tmp22.i, because it is redundant with
  5. ; load %tmp8.i. This requires being able to prove that %tmp7.i doesn't
  6. ; alias the malloc'd value %tmp.i20.i.i, which it can do since %tmp7.i
  7. ; is derived from %tmp5.i which is computed from a load, and %tmp.i20.i.i
  8. ; is never stored and does not escape.
  9. 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"
  10. target triple = "x86_64-apple-darwin10.0"
  11. %"struct.llvm::MallocAllocator" = type <{ i8 }>
  12. %"struct.llvm::StringMap<void*,llvm::MallocAllocator>" = type { %"struct.llvm::StringMapImpl", %"struct.llvm::MallocAllocator" }
  13. %"struct.llvm::StringMapEntry<void*>" = type { %"struct.llvm::StringMapEntryBase", i8* }
  14. %"struct.llvm::StringMapEntryBase" = type { i32 }
  15. %"struct.llvm::StringMapImpl" = type { %"struct.llvm::StringMapImpl::ItemBucket"*, i32, i32, i32, i32 }
  16. %"struct.llvm::StringMapImpl::ItemBucket" = type { i32, %"struct.llvm::StringMapEntryBase"* }
  17. %"struct.llvm::StringRef" = type { i8*, i64 }
  18. define %"struct.llvm::StringMapEntry<void*>"* @_Z3fooRN4llvm9StringMapIPvNS_15MallocAllocatorEEEPKc(%"struct.llvm::StringMap<void*,llvm::MallocAllocator>"* %X, i8* %P) ssp {
  19. entry:
  20. %tmp = alloca %"struct.llvm::StringRef", align 8
  21. %tmp.i = getelementptr inbounds %"struct.llvm::StringRef", %"struct.llvm::StringRef"* %tmp, i64 0, i32 0
  22. store i8* %P, i8** %tmp.i, align 8
  23. %tmp1.i = call i64 @strlen(i8* %P) nounwind readonly
  24. %tmp2.i = getelementptr inbounds %"struct.llvm::StringRef", %"struct.llvm::StringRef"* %tmp, i64 0, i32 1
  25. store i64 %tmp1.i, i64* %tmp2.i, align 8
  26. %tmp1 = call %"struct.llvm::StringMapEntry<void*>"* @_ZN4llvm9StringMapIPvNS_15MallocAllocatorEE16GetOrCreateValueERKNS_9StringRefE(%"struct.llvm::StringMap<void*,llvm::MallocAllocator>"* %X, %"struct.llvm::StringRef"* %tmp) ssp
  27. ret %"struct.llvm::StringMapEntry<void*>"* %tmp1
  28. }
  29. declare i64 @strlen(i8* nocapture) nounwind readonly
  30. declare noalias i8* @malloc(i64) nounwind
  31. declare i32 @_ZN4llvm13StringMapImpl15LookupBucketForENS_9StringRefE(%"struct.llvm::StringMapImpl"*, i64, i64)
  32. define linkonce_odr %"struct.llvm::StringMapEntry<void*>"* @_ZN4llvm9StringMapIPvNS_15MallocAllocatorEE16GetOrCreateValueERKNS_9StringRefE(%"struct.llvm::StringMap<void*,llvm::MallocAllocator>"* %this, %"struct.llvm::StringRef"* nocapture %Key) ssp align 2 {
  33. entry:
  34. %elt = bitcast %"struct.llvm::StringRef"* %Key to i64*
  35. %val = load i64, i64* %elt
  36. %tmp = getelementptr inbounds %"struct.llvm::StringRef", %"struct.llvm::StringRef"* %Key, i64 0, i32 1
  37. %val2 = load i64, i64* %tmp
  38. %tmp2.i = getelementptr inbounds %"struct.llvm::StringMap<void*,llvm::MallocAllocator>", %"struct.llvm::StringMap<void*,llvm::MallocAllocator>"* %this, i64 0, i32 0
  39. %tmp3.i = tail call i32 @_ZN4llvm13StringMapImpl15LookupBucketForENS_9StringRefE(%"struct.llvm::StringMapImpl"* %tmp2.i, i64 %val, i64 %val2)
  40. %tmp4.i = getelementptr inbounds %"struct.llvm::StringMap<void*,llvm::MallocAllocator>", %"struct.llvm::StringMap<void*,llvm::MallocAllocator>"* %this, i64 0, i32 0, i32 0
  41. %tmp5.i = load %"struct.llvm::StringMapImpl::ItemBucket"*, %"struct.llvm::StringMapImpl::ItemBucket"** %tmp4.i, align 8
  42. %tmp6.i = zext i32 %tmp3.i to i64
  43. %tmp7.i = getelementptr inbounds %"struct.llvm::StringMapImpl::ItemBucket", %"struct.llvm::StringMapImpl::ItemBucket"* %tmp5.i, i64 %tmp6.i, i32 1
  44. %tmp8.i = load %"struct.llvm::StringMapEntryBase"*, %"struct.llvm::StringMapEntryBase"** %tmp7.i, align 8
  45. %tmp9.i = icmp eq %"struct.llvm::StringMapEntryBase"* %tmp8.i, null
  46. %tmp13.i = icmp eq %"struct.llvm::StringMapEntryBase"* %tmp8.i, inttoptr (i64 -1 to %"struct.llvm::StringMapEntryBase"*)
  47. %or.cond.i = or i1 %tmp9.i, %tmp13.i
  48. br i1 %or.cond.i, label %bb4.i, label %bb6.i
  49. bb4.i: ; preds = %entry
  50. %tmp41.i = inttoptr i64 %val to i8*
  51. %tmp4.i35.i = getelementptr inbounds i8, i8* %tmp41.i, i64 %val2
  52. %tmp.i.i = ptrtoint i8* %tmp4.i35.i to i64
  53. %tmp1.i.i = trunc i64 %tmp.i.i to i32
  54. %tmp3.i.i = trunc i64 %val to i32
  55. %tmp4.i.i = sub i32 %tmp1.i.i, %tmp3.i.i
  56. %tmp5.i.i = add i32 %tmp4.i.i, 17
  57. %tmp8.i.i = zext i32 %tmp5.i.i to i64
  58. %tmp.i20.i.i = tail call noalias i8* @malloc(i64 %tmp8.i.i) nounwind
  59. %tmp10.i.i = bitcast i8* %tmp.i20.i.i to %"struct.llvm::StringMapEntry<void*>"*
  60. %tmp12.i.i = icmp eq i8* %tmp.i20.i.i, null
  61. br i1 %tmp12.i.i, label %_ZN4llvm14StringMapEntryIPvE6CreateINS_15MallocAllocatorES1_EEPS2_PKcS7_RT_T0_.exit.i, label %bb.i.i
  62. bb.i.i: ; preds = %bb4.i
  63. %tmp.i.i.i.i = bitcast i8* %tmp.i20.i.i to i32*
  64. store i32 %tmp4.i.i, i32* %tmp.i.i.i.i, align 4
  65. %tmp1.i19.i.i = getelementptr inbounds i8, i8* %tmp.i20.i.i, i64 8
  66. %0 = bitcast i8* %tmp1.i19.i.i to i8**
  67. store i8* null, i8** %0, align 8
  68. br label %_ZN4llvm14StringMapEntryIPvE6CreateINS_15MallocAllocatorES1_EEPS2_PKcS7_RT_T0_.exit.i
  69. _ZN4llvm14StringMapEntryIPvE6CreateINS_15MallocAllocatorES1_EEPS2_PKcS7_RT_T0_.exit.i: ; preds = %bb.i.i, %bb4.i
  70. %tmp.i18.i.i = getelementptr inbounds i8, i8* %tmp.i20.i.i, i64 16
  71. %tmp15.i.i = zext i32 %tmp4.i.i to i64
  72. tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp.i18.i.i, i8* %tmp41.i, i64 %tmp15.i.i, i32 1, i1 false)
  73. %tmp.i18.sum.i.i = add i64 %tmp15.i.i, 16
  74. %tmp17.i.i = getelementptr inbounds i8, i8* %tmp.i20.i.i, i64 %tmp.i18.sum.i.i
  75. store i8 0, i8* %tmp17.i.i, align 1
  76. %tmp.i.i.i = getelementptr inbounds i8, i8* %tmp.i20.i.i, i64 8
  77. %1 = bitcast i8* %tmp.i.i.i to i8**
  78. store i8* null, i8** %1, align 8
  79. %tmp22.i = load %"struct.llvm::StringMapEntryBase"*, %"struct.llvm::StringMapEntryBase"** %tmp7.i, align 8
  80. %tmp24.i = icmp eq %"struct.llvm::StringMapEntryBase"* %tmp22.i, inttoptr (i64 -1 to %"struct.llvm::StringMapEntryBase"*)
  81. br i1 %tmp24.i, label %bb9.i, label %_ZN4llvm9StringMapIPvNS_15MallocAllocatorEE16GetOrCreateValueIS1_EERNS_14StringMapEntryIS1_EENS_9StringRefET_.exit
  82. bb6.i: ; preds = %entry
  83. %tmp16.i = bitcast %"struct.llvm::StringMapEntryBase"* %tmp8.i to %"struct.llvm::StringMapEntry<void*>"*
  84. ret %"struct.llvm::StringMapEntry<void*>"* %tmp16.i
  85. bb9.i: ; preds = %_ZN4llvm14StringMapEntryIPvE6CreateINS_15MallocAllocatorES1_EEPS2_PKcS7_RT_T0_.exit.i
  86. %tmp25.i = getelementptr inbounds %"struct.llvm::StringMap<void*,llvm::MallocAllocator>", %"struct.llvm::StringMap<void*,llvm::MallocAllocator>"* %this, i64 0, i32 0, i32 3
  87. %tmp26.i = load i32, i32* %tmp25.i, align 8
  88. %tmp27.i = add i32 %tmp26.i, -1
  89. store i32 %tmp27.i, i32* %tmp25.i, align 8
  90. ret %"struct.llvm::StringMapEntry<void*>"* %tmp10.i.i
  91. _ZN4llvm9StringMapIPvNS_15MallocAllocatorEE16GetOrCreateValueIS1_EERNS_14StringMapEntryIS1_EENS_9StringRefET_.exit: ; preds = %_ZN4llvm14StringMapEntryIPvE6CreateINS_15MallocAllocatorES1_EEPS2_PKcS7_RT_T0_.exit.i
  92. ret %"struct.llvm::StringMapEntry<void*>"* %tmp10.i.i
  93. }
  94. declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind