[llvm] db1176c - Revert "[SimplifyCFG] `markAliveBlocks()`: recognize that normal dest of `invoke`d `noreturn` function is `unreachable`"

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 4 15:30:36 PST 2022


Author: Roman Lebedev
Date: 2022-02-05T02:30:20+03:00
New Revision: db1176ce66cf276b45ac3b90ea6b5ce62de56be7

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

LOG: Revert "[SimplifyCFG] `markAliveBlocks()`: recognize that normal dest of `invoke`d `noreturn` function is `unreachable`"

The normal destination may have other uses.

This reverts commit 598833c987593ce192fa827f162cae8c867c9d43.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/Local.cpp
    llvm/test/CodeGen/X86/catchret-regmask.ll
    llvm/test/Transforms/SimplifyCFG/invoke.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 58eb7d4c6c4d5..9a10535c93101 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -2349,32 +2349,19 @@ static bool markAliveBlocks(Function &F,
           isa<UndefValue>(Callee)) {
         changeToUnreachable(II, false, DTU);
         Changed = true;
-      } else {
-        if (II->doesNotReturn()) {
-          // If we found an invoke of a no-return function,
-          // insert an unreachable instruction after it (on the normal dest).
-          // Make sure there isn't *already* one there though.
-          Instruction *FirstNormalInst = &II->getNormalDest()->front();
-          if (!isa<UnreachableInst>(FirstNormalInst)) {
-            // Don't insert a call to llvm.trap right before the unreachable.
-            changeToUnreachable(FirstNormalInst, false, DTU);
-            Changed = true;
-          }
-        }
-        if (II->doesNotThrow() && canSimplifyInvokeNoUnwind(&F)) {
-          if (II->use_empty() && II->onlyReadsMemory()) {
-            // jump to the normal destination branch.
-            BasicBlock *NormalDestBB = II->getNormalDest();
-            BasicBlock *UnwindDestBB = II->getUnwindDest();
-            BranchInst::Create(NormalDestBB, II);
-            UnwindDestBB->removePredecessor(II->getParent());
-            II->eraseFromParent();
-            if (DTU)
-              DTU->applyUpdates({{DominatorTree::Delete, BB, UnwindDestBB}});
-          } else
-            changeToCall(II, DTU);
-          Changed = true;
-        }
+      } else if (II->doesNotThrow() && canSimplifyInvokeNoUnwind(&F)) {
+        if (II->use_empty() && II->onlyReadsMemory()) {
+          // jump to the normal destination branch.
+          BasicBlock *NormalDestBB = II->getNormalDest();
+          BasicBlock *UnwindDestBB = II->getUnwindDest();
+          BranchInst::Create(NormalDestBB, II);
+          UnwindDestBB->removePredecessor(II->getParent());
+          II->eraseFromParent();
+          if (DTU)
+            DTU->applyUpdates({{DominatorTree::Delete, BB, UnwindDestBB}});
+        } else
+          changeToCall(II, DTU);
+        Changed = true;
       }
     } else if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(Terminator)) {
       // Remove catchpads which cannot be reached.

diff  --git a/llvm/test/CodeGen/X86/catchret-regmask.ll b/llvm/test/CodeGen/X86/catchret-regmask.ll
index 20212a2bf032d..4af57e109f183 100644
--- a/llvm/test/CodeGen/X86/catchret-regmask.ll
+++ b/llvm/test/CodeGen/X86/catchret-regmask.ll
@@ -4,7 +4,7 @@ target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-pc-windows-msvc"
 
 declare i32 @__CxxFrameHandler3(...)
-declare void @throw() uwtable
+declare void @throw() noreturn uwtable
 declare i8* @getval()
 declare void @llvm.trap()
 

diff  --git a/llvm/test/Transforms/SimplifyCFG/invoke.ll b/llvm/test/Transforms/SimplifyCFG/invoke.ll
index dab8eb59a1798..5aabe6f7449cb 100644
--- a/llvm/test/Transforms/SimplifyCFG/invoke.ll
+++ b/llvm/test/Transforms/SimplifyCFG/invoke.ll
@@ -198,7 +198,8 @@ define void @invoke_of_noreturn() personality i8* bitcast (i32 (...)* @__gxx_per
 ; CHECK-NEXT:    invoke void @simple_throw()
 ; CHECK-NEXT:    to label [[INVOKE_CONT:%.*]] unwind label [[LPAD:%.*]]
 ; CHECK:       invoke.cont:
-; CHECK-NEXT:    unreachable
+; CHECK-NEXT:    call void @sideeffect(i32 0)
+; CHECK-NEXT:    ret void
 ; CHECK:       lpad:
 ; CHECK-NEXT:    [[EH:%.*]] = landingpad { i8*, i32 }
 ; CHECK-NEXT:    cleanup


        


More information about the llvm-commits mailing list