[PATCH] D153337: [MachineLICM][WinEH] Don't hoist register reloads out of funclets

Karl-Johan Johnsson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 20 06:27:00 PDT 2023


kalle-llvm created this revision.
Herald added subscribers: pengfei, asbirlea, hiraditya.
Herald added a project: All.
kalle-llvm requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This fixes https://github.com/llvm/llvm-project/issues/60766

With MSVC style exception-handling (funclets), no registers are alive when entering the funclet so they must be reloaded from the stack.  MachineLICM can sometimes hoist such reloads out of the funclet which is not correct, the register will have been clobbered when entering the funclet.  This can happen in any loop that contains a try-catch.

This has been tested on x86_64-pc-window-msvc.  I'm not sure if funclets work the same on the other windows archs.

(This is my first patch to llvm, so please bear with me.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153337

Files:
  llvm/lib/CodeGen/MachineLICM.cpp


Index: llvm/lib/CodeGen/MachineLICM.cpp
===================================================================
--- llvm/lib/CodeGen/MachineLICM.cpp
+++ llvm/lib/CodeGen/MachineLICM.cpp
@@ -525,6 +525,10 @@
   // Walk the entire region, count number of defs for each register, and
   // collect potential LICM candidates.
   for (MachineBasicBlock *BB : CurLoop->getBlocks()) {
+    // We can't hoist instructions out of a funclet, so if the region
+    // contains a funclet (i.e. the loop contains a try-catch) we give up
+    if (BB->isEHFuncletEntry())
+      return;
     // If the header of the loop containing this basic block is a landing pad,
     // then don't try to hoist instructions out of this loop.
     const MachineLoop *ML = MLI->getLoopFor(BB);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153337.532881.patch
Type: text/x-patch
Size: 761 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230620/222582bd/attachment.bin>


More information about the llvm-commits mailing list