Preserve 'nonnull' when changing type of the load.
authorPhilip Reames <listmail@philipreames.com>
Tue, 21 Oct 2014 21:00:03 +0000 (21:00 +0000)
committerPhilip Reames <listmail@philipreames.com>
Tue, 21 Oct 2014 21:00:03 +0000 (21:00 +0000)
When changing the type of a load in Chandler's recent InstCombine changes, we can preserve the new 'nonnull' metadata.

I considered adding an assert since 'nonnull' is only valid on pointer types, but casting a pointer to a non-pointer would involve more than a bitcast anyways.  If someone extends this transform to handle more than bitcasts, the verifier will report the malformed IR, so a separate assertion isn't needed.  Also, the fpmath flags would have the same problem.

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

lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

index 95ca1a6ff7ae97b4134bac09bf1dbf97ffe834dc..c0df914cb669b6c4cc58bcb19a14d9efb17e1cd1 100644 (file)
@@ -331,6 +331,7 @@ static LoadInst *combineLoadToNewType(InstCombiner &IC, LoadInst &LI, Type *NewT
     case LLVMContext::MD_noalias:
     case LLVMContext::MD_nontemporal:
     case LLVMContext::MD_mem_parallel_loop_access:
     case LLVMContext::MD_noalias:
     case LLVMContext::MD_nontemporal:
     case LLVMContext::MD_mem_parallel_loop_access:
+    case LLVMContext::MD_nonnull:
       // All of these directly apply.
       NewLoad->setMetadata(ID, N);
       break;
       // All of these directly apply.
       NewLoad->setMetadata(ID, N);
       break;