[llvm] 13e35ac - [NFC][InstCombine] visitUnreachableInst(): enhance comments somewhat

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 2 07:30:28 PDT 2021


Author: Roman Lebedev
Date: 2021-07-02T17:30:01+03:00
New Revision: 13e35ac1249472d4b092d76264dcfc9fe8d7d13b

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

LOG: [NFC][InstCombine] visitUnreachableInst(): enhance comments somewhat

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index d29527f3a0dc..393180306ee8 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2875,8 +2875,18 @@ Instruction *InstCombinerImpl::visitUnreachableInst(UnreachableInst &I) {
   // This includes instructions like stores and "llvm.assume" that may not get
   // removed by simple dead code elimination.
   while (Instruction *Prev = I.getPrevNonDebugInstruction()) {
-    if (Prev->isEHPad() || !isGuaranteedToTransferExecutionToSuccessor(Prev))
+    // While we theoretically can erase EH, that would result in a block that
+    // used to start with an EH no longer starting with EH, which is invalid.
+    // To make it valid, we'd need to fixup predecessors to no longer refer to
+    // this block, but that changes CFG, which is not allowed in InstCombine.
+    if (Prev->isEHPad())
       return nullptr; // Can not drop any more instructions. We're done here.
+
+    if (!isGuaranteedToTransferExecutionToSuccessor(Prev))
+      return nullptr; // Can not drop any more instructions. We're done here.
+    // Otherwise, this instruction can be freely erased,
+    // even if it is not side-effect free.
+
     // Temporarily disable removal of volatile stores preceding unreachable,
     // pending a potential LangRef change permitting volatile stores to trap.
     // TODO: Either remove this code, or properly integrate the check into


        


More information about the llvm-commits mailing list