[llvm] b51c613 - Use PoisonValue instead of UndefValue when RAUWing unreachable code [NFC]

Nuno Lopes via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 10 06:28:37 PDT 2022


Author: Manuel Brito
Date: 2022-09-10T14:28:01+01:00
New Revision: b51c6130efac2afd183ad71b81c16c713c10a1b5

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

LOG: Use PoisonValue instead of UndefValue when RAUWing unreachable code [NFC]

Replacing the following instances of UndefValue with PoisonValue, where the UndefValue is used as an arbitrary value:

- llvm/lib/CodeGen/WinEHPrepare.cpp
`demotePHIsOnFunclets`: RAUW arbitrary value for lingering uses of removed PHI nodes

 - llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
`FoldSingleEntryPHINodes`: Removes a self-referential single entry phi node.

 - llvm/lib/Transforms/Utils/CallGraphUpdater.cpp
`finalize`: Remove all references to removed functions.

- llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
`cleanup`: the result is not used then the inserted instructions are removed.

 - llvm/tools/bugpoint/CrashDebugger.cpp
`TestInts`:  the program is cloned and instructions are removed to narrow down source of crash.

Differential Revision: https://reviews.llvm.org/D133640

Added: 
    

Modified: 
    llvm/lib/CodeGen/WinEHPrepare.cpp
    llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
    llvm/lib/Transforms/Utils/CallGraphUpdater.cpp
    llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
    llvm/tools/bugpoint/CrashDebugger.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/WinEHPrepare.cpp b/llvm/lib/CodeGen/WinEHPrepare.cpp
index a71f6572e76f9..baca4109ebf52 100644
--- a/llvm/lib/CodeGen/WinEHPrepare.cpp
+++ b/llvm/lib/CodeGen/WinEHPrepare.cpp
@@ -733,7 +733,7 @@ void WinEHPrepare::demotePHIsOnFunclets(Function &F,
 
   for (auto *PN : PHINodes) {
     // There may be lingering uses on other EH PHIs being removed
-    PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
+    PN->replaceAllUsesWith(PoisonValue::get(PN->getType()));
     PN->eraseFromParent();
   }
 }

diff  --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 9ab8014e60d63..746fe798a7064 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -149,7 +149,7 @@ bool llvm::FoldSingleEntryPHINodes(BasicBlock *BB,
     if (PN->getIncomingValue(0) != PN)
       PN->replaceAllUsesWith(PN->getIncomingValue(0));
     else
-      PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
+      PN->replaceAllUsesWith(PoisonValue::get(PN->getType()));
 
     if (MemDep)
       MemDep->removeInstruction(PN);  // Memdep updates AA itself.

diff  --git a/llvm/lib/Transforms/Utils/CallGraphUpdater.cpp b/llvm/lib/Transforms/Utils/CallGraphUpdater.cpp
index 1840f26add2da..d0b89ba2606ea 100644
--- a/llvm/lib/Transforms/Utils/CallGraphUpdater.cpp
+++ b/llvm/lib/Transforms/Utils/CallGraphUpdater.cpp
@@ -36,7 +36,7 @@ bool CallGraphUpdater::finalize() {
       CallGraphNode *DeadCGN = (*CG)[DeadFn];
       DeadCGN->removeAllCalledFunctions();
       CG->getExternalCallingNode()->removeAnyCallEdgeTo(DeadCGN);
-      DeadFn->replaceAllUsesWith(UndefValue::get(DeadFn->getType()));
+      DeadFn->replaceAllUsesWith(PoisonValue::get(DeadFn->getType()));
     }
 
     // Then remove the node and function from the module.
@@ -51,7 +51,7 @@ bool CallGraphUpdater::finalize() {
     // no call graph was provided.
     for (Function *DeadFn : DeadFunctions) {
       DeadFn->removeDeadConstantUsers();
-      DeadFn->replaceAllUsesWith(UndefValue::get(DeadFn->getType()));
+      DeadFn->replaceAllUsesWith(PoisonValue::get(DeadFn->getType()));
 
       if (LCG && !ReplacedFunctions.count(DeadFn)) {
         // Taken mostly from the inliner:

diff  --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 95e6427077915..3e7e016b99b5e 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -2666,7 +2666,7 @@ void SCEVExpanderCleaner::cleanup() {
 #endif
     assert(!I->getType()->isVoidTy() &&
            "inserted instruction should have non-void types");
-    I->replaceAllUsesWith(UndefValue::get(I->getType()));
+    I->replaceAllUsesWith(PoisonValue::get(I->getType()));
     I->eraseFromParent();
   }
 }

diff  --git a/llvm/tools/bugpoint/CrashDebugger.cpp b/llvm/tools/bugpoint/CrashDebugger.cpp
index a60621b1e0ec3..2724d8c4b3e5e 100644
--- a/llvm/tools/bugpoint/CrashDebugger.cpp
+++ b/llvm/tools/bugpoint/CrashDebugger.cpp
@@ -791,7 +791,7 @@ bool ReduceCrashingInstructions::TestInsts(
             !Inst.isEHPad() && !Inst.getType()->isTokenTy() &&
             !Inst.isSwiftError()) {
           if (!Inst.getType()->isVoidTy())
-            Inst.replaceAllUsesWith(UndefValue::get(Inst.getType()));
+            Inst.replaceAllUsesWith(PoisonValue::get(Inst.getType()));
           Inst.eraseFromParent();
         }
       }


        


More information about the llvm-commits mailing list