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