Avoid dropping the address space when InstCombine optimizes memset
authorMon P Wang <wangmp@apple.com>
Mon, 20 Dec 2010 01:05:30 +0000 (01:05 +0000)
committerMon P Wang <wangmp@apple.com>
Mon, 20 Dec 2010 01:05:30 +0000 (01:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122215 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCalls.cpp

index d53f3291e717cfd69af0f9f4904cbbcbf0f1439b..58c8f5fc460b00fc576056677084e99db81dcabb 100644 (file)
@@ -234,7 +234,9 @@ Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) {
     const Type *ITy = IntegerType::get(MI->getContext(), Len*8);  // n=1 -> i8.
     
     Value *Dest = MI->getDest();
-    Dest = Builder->CreateBitCast(Dest, PointerType::getUnqual(ITy));
+    unsigned DstAddrSp = cast<PointerType>(Dest->getType())->getAddressSpace();
+    Type *NewDstPtrTy = PointerType::get(ITy, DstAddrSp);
+    Dest = Builder->CreateBitCast(Dest, NewDstPtrTy);
 
     // Alignment 0 is identity for alignment 1 for memset, but not store.
     if (Alignment == 0) Alignment = 1;