Fix 4366: store to null in non-default addr space should not be
authorChris Lattner <sabre@nondot.org>
Thu, 11 Jun 2009 17:54:56 +0000 (17:54 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 11 Jun 2009 17:54:56 +0000 (17:54 +0000)
turned into unreachable.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73195 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp
test/Transforms/InstCombine/2009-06-11-StoreAddrSpace.ll [new file with mode: 0644]

index 6d2ff0e3e53c5a5f5e7752fff595177d9f430374..03a7317138aaa9bf1af433f4bfc3d7846354b836 100644 (file)
@@ -11824,7 +11824,8 @@ Instruction *InstCombiner::visitStoreInst(StoreInst &SI) {
   if (SI.isVolatile()) return 0;  // Don't hack volatile stores.
 
   // store X, null    -> turns into 'unreachable' in SimplifyCFG
-  if (isa<ConstantPointerNull>(Ptr)) {
+  if (isa<ConstantPointerNull>(Ptr) &&
+      cast<PointerType>(Ptr->getType())->getAddressSpace() == 0) {
     if (!isa<UndefValue>(Val)) {
       SI.setOperand(0, UndefValue::get(Val->getType()));
       if (Instruction *U = dyn_cast<Instruction>(Val))
diff --git a/test/Transforms/InstCombine/2009-06-11-StoreAddrSpace.ll b/test/Transforms/InstCombine/2009-06-11-StoreAddrSpace.ll
new file mode 100644 (file)
index 0000000..e86fed3
--- /dev/null
@@ -0,0 +1,7 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep store
+; PR4366
+
+define void @a() {
+  store i32 0, i32 addrspace(1)* null
+  ret void
+}