[llvm] r203862 - Fix a bug in InstCombine where we would incorrectly attempt to construct a

Owen Anderson resistor at mac.com
Thu Mar 13 15:51:43 PDT 2014


Author: resistor
Date: Thu Mar 13 17:51:43 2014
New Revision: 203862

URL: http://llvm.org/viewvc/llvm-project?rev=203862&view=rev
Log:
Fix a bug in InstCombine where we would incorrectly attempt to construct a
bitcast between pointers of two different address spaces if they happened to have
the same pointer size.

Added:
    llvm/trunk/test/Transforms/InstCombine/load-addrspace-cast.ll
Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=203862&r1=203861&r2=203862&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Thu Mar 13 17:51:43 2014
@@ -335,6 +335,13 @@ static Instruction *InstCombineLoadCast(
         NewLoad->setAlignment(LI.getAlignment());
         NewLoad->setAtomic(LI.getOrdering(), LI.getSynchScope());
         // Now cast the result of the load.
+        PointerType *OldTy = dyn_cast<PointerType>(NewLoad->getType());
+        PointerType *NewTy = dyn_cast<PointerType>(LI.getType());
+        if (OldTy && NewTy &&
+            OldTy->getAddressSpace() != NewTy->getAddressSpace()) {
+          return new AddrSpaceCastInst(NewLoad, LI.getType());
+        }
+
         return new BitCastInst(NewLoad, LI.getType());
       }
     }

Added: llvm/trunk/test/Transforms/InstCombine/load-addrspace-cast.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/load-addrspace-cast.ll?rev=203862&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/load-addrspace-cast.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/load-addrspace-cast.ll Thu Mar 13 17:51:43 2014
@@ -0,0 +1,12 @@
+; RUN: opt -instcombine -S < %s | FileCheck %s
+target datalayout = "e-p:64:64:64-n8:16:32:64"
+
+define i32* @pointer_to_addrspace_pointer(i32 addrspace(1)** %x) nounwind {
+; CHECK-LABEL: @pointer_to_addrspace_pointer(
+; CHECK: load
+; CHECK: addrspacecast
+  %y = bitcast i32 addrspace(1)** %x to i32**
+  %z = load i32** %y
+  ret i32* %z
+}
+





More information about the llvm-commits mailing list