[llvm] 2215dcf - [InstCombine] Remove unreachable blocks before DCE

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 28 13:19:43 PDT 2020


Author: Nikita Popov
Date: 2020-03-28T21:19:16+01:00
New Revision: 2215dcf1d755413d32359563c4dbd3d4f575e5dc

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

LOG: [InstCombine] Remove unreachable blocks before DCE

Dropping unreachable code may reduce use counts on other instructions,
so it's better to do this earlier rather than later.

NFC-ish, may only impact worklist order.

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 30b9b1325cb8..647e46bc6b53 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3685,6 +3685,18 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
       Worklist.push_back(SuccBB);
   } while (!Worklist.empty());
 
+  // Remove instructions inside unreachable blocks. This prevents the
+  // instcombine code from having to deal with some bad special cases, and
+  // reduces use counts of instructions.
+  for (BasicBlock &BB : F) {
+    if (Visited.count(&BB))
+      continue;
+
+    unsigned NumDeadInstInBB = removeAllNonTerminatorAndEHPadInstructions(&BB);
+    MadeIRChange |= NumDeadInstInBB > 0;
+    NumDeadInst += NumDeadInstInBB;
+  }
+
   // Once we've found all of the instructions to add to instcombine's worklist,
   // add them in reverse order.  This way instcombine will visit from the top
   // of the function down.  This jives well with the way that it adds all uses
@@ -3706,18 +3718,6 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
     ICWorklist.push(Inst);
   }
 
-  // Do a quick scan over the function.  If we find any blocks that are
-  // unreachable, remove any instructions inside of them.  This prevents
-  // the instcombine code from having to deal with some bad special cases.
-  for (BasicBlock &BB : F) {
-    if (Visited.count(&BB))
-      continue;
-
-    unsigned NumDeadInstInBB = removeAllNonTerminatorAndEHPadInstructions(&BB);
-    MadeIRChange |= NumDeadInstInBB > 0;
-    NumDeadInst += NumDeadInstInBB;
-  }
-
   return MadeIRChange;
 }
 


        


More information about the llvm-commits mailing list