[llvm] 706b22e - [SimpleLoopUnswitch] Drop uses of instructions before block deletion

Daniil Suchkov via llvm-commits llvm-commits at lists.llvm.org
Wed May 27 04:26:20 PDT 2020


Author: Daniil Suchkov
Date: 2020-05-27T18:25:18+07:00
New Revision: 706b22e3e446621b20befe1094c26e4eda133bc9

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

LOG: [SimpleLoopUnswitch] Drop uses of instructions before block deletion

Currently if instructions defined in a block are used in unreachable
blocks and SimpleLoopUnswitch attempts deleting the block, it triggers
assertion "Uses remain when a value is destroyed!".
This patch fixes it by replacing all uses of instructions from BB with
undefs before BB deletion.

Reviewed By: asbirlea

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

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
    llvm/test/Transforms/SimpleLoopUnswitch/dead-blocks-uses-in-unreachablel-blocks.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index 914fadc40d74..6c6d6ca9cf65 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -1574,6 +1574,11 @@ static void deleteDeadBlocksFromLoop(Loop &L,
     // Check that the dominator tree has already been updated.
     assert(!DT.getNode(BB) && "Should already have cleared domtree!");
     LI.changeLoopFor(BB, nullptr);
+    // Drop all uses of the instructions to make sure we won't have dangling
+    // uses in other blocks.
+    for (auto &I : *BB)
+      if (!I.use_empty())
+        I.replaceAllUsesWith(UndefValue::get(I.getType()));
     BB->dropAllReferences();
   }
 

diff  --git a/llvm/test/Transforms/SimpleLoopUnswitch/dead-blocks-uses-in-unreachablel-blocks.ll b/llvm/test/Transforms/SimpleLoopUnswitch/dead-blocks-uses-in-unreachablel-blocks.ll
index 4dec9a3919aa..2756e102a67a 100644
--- a/llvm/test/Transforms/SimpleLoopUnswitch/dead-blocks-uses-in-unreachablel-blocks.ll
+++ b/llvm/test/Transforms/SimpleLoopUnswitch/dead-blocks-uses-in-unreachablel-blocks.ll
@@ -1,4 +1,3 @@
-; XFAIL: *
 ; REQUIRES: asserts
 ; RUN: opt < %s -passes='unswitch<nontrivial>' -disable-output
 ; RUN: opt < %s -simple-loop-unswitch -enable-nontrivial-unswitch -disable-output


        


More information about the llvm-commits mailing list