[llvm] 80e0424 - [Mem2Reg] Use poison for unreachable cases

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 21 01:54:21 PDT 2021


Author: Nikita Popov
Date: 2021-06-21T10:54:13+02:00
New Revision: 80e0424b2ce9489bec73dbd3b920c4543a25feb1

URL: https://github.com/llvm/llvm-project/commit/80e0424b2ce9489bec73dbd3b920c4543a25feb1
DIFF: https://github.com/llvm/llvm-project/commit/80e0424b2ce9489bec73dbd3b920c4543a25feb1.diff

LOG: [Mem2Reg] Use poison for unreachable cases

Use poison instead of undef for cases dealing with unreachable
code. This still leaves the more interesting case of "load from
uninitialized memory" as undef.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
    llvm/test/Transforms/Mem2Reg/pr37632-unreachable-list-of-stores.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index be7dd01e2775a..4270280660266 100644
--- a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -399,7 +399,7 @@ static bool rewriteSingleStoreAlloca(AllocaInst *AI, AllocaInfo &Info,
     // If the replacement value is the load, this must occur in unreachable
     // code.
     if (ReplVal == LI)
-      ReplVal = UndefValue::get(LI->getType());
+      ReplVal = PoisonValue::get(LI->getType());
 
     // If the load was marked as nonnull we don't want to lose
     // that information when we erase this Load. So we preserve
@@ -508,7 +508,7 @@ static bool promoteSingleBlockAlloca(AllocaInst *AI, const AllocaInfo &Info,
       // If the replacement value is the load, this must occur in unreachable
       // code.
       if (ReplVal == LI)
-        ReplVal = UndefValue::get(LI->getType());
+        ReplVal = PoisonValue::get(LI->getType());
 
       LI->replaceAllUsesWith(ReplVal);
     }
@@ -672,7 +672,7 @@ void PromoteMem2Reg::run() {
     // unreachable basic blocks that were not processed by walking the dominator
     // tree. Just delete the users now.
     if (!A->use_empty())
-      A->replaceAllUsesWith(UndefValue::get(A->getType()));
+      A->replaceAllUsesWith(PoisonValue::get(A->getType()));
     A->eraseFromParent();
   }
 

diff  --git a/llvm/test/Transforms/Mem2Reg/pr37632-unreachable-list-of-stores.ll b/llvm/test/Transforms/Mem2Reg/pr37632-unreachable-list-of-stores.ll
index ef7a081ead729..e744d80440789 100644
--- a/llvm/test/Transforms/Mem2Reg/pr37632-unreachable-list-of-stores.ll
+++ b/llvm/test/Transforms/Mem2Reg/pr37632-unreachable-list-of-stores.ll
@@ -5,7 +5,7 @@ define void @patatino() {
 ; CHECK-LABEL: @patatino(
 ; CHECK-NEXT:    ret void
 ; CHECK:       cantreachme:
-; CHECK-NEXT:    [[DEC:%.*]] = add nsw i32 undef, -1
+; CHECK-NEXT:    [[DEC:%.*]] = add nsw i32 poison, -1
 ; CHECK-NEXT:    br label [[CANTREACHME:%.*]]
 ;
   %a = alloca i32, align 4


        


More information about the llvm-commits mailing list