[llvm] [MachineSink] Fix missing sinks along critical edges (PR #97618)

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 8 09:23:18 PDT 2024


================
@@ -887,6 +899,27 @@ bool MachineSinking::isWorthBreakingCriticalEdge(MachineInstr &MI,
   if (!MI.isCopy() && !TII->isAsCheapAsAMove(MI))
     return true;
 
+  // Check and record the register and the destination block we want to sink
+  // into. Note that we want to do the following before the next check on branch
+  // probability. Because we want to record the initial candidate even if it's
+  // on hot edge, so that other candidates that might not on hot edges can be
+  // sinked as well.
+  for (const auto &MO : MI.all_defs()) {
+    Register Reg = MO.getReg();
+    if (!Reg)
+      continue;
+    Register SrcReg = Reg.isVirtual() ? TRI->lookThruCopyLike(Reg, MRI) : Reg;
+    auto Key = std::make_pair(SrcReg, To);
+    auto Res = CEMergeCandidates.insert(std::make_pair(Key, From));
----------------
mshockwave wrote:

Good point. It's fixed now.

https://github.com/llvm/llvm-project/pull/97618


More information about the llvm-commits mailing list