[llvm-commits] Fix for MachineSink creating zombie defines

Eli Friedman eli.friedman at gmail.com
Fri Jul 29 11:35:17 PDT 2011


On Fri, Jul 29, 2011 at 10:26 AM, Jan Sjodin <jan_sjodin at yahoo.com> wrote:
> This patch fixes a problem with MachineSink. After a critical edge split the flags of the successor were not reflected in the new block, which allowed later instructions to sink even though they write the EFLAGS.
> The example below shows the problem. Unfortunately there is a test that relies on this bug, although the problem is that the EFLAGS are live-in when they should not be. The patch disables this test for now.


Index: lib/CodeGen/MachineSink.cpp
===================================================================
--- lib/CodeGen/MachineSink.cpp	(revision 136462)
+++ lib/CodeGen/MachineSink.cpp	(working copy)
@@ -375,7 +375,16 @@
     }
   }

-  return FromBB->SplitCriticalEdge(ToBB, this);
+  MachineBasicBlock *result = FromBB->SplitCriticalEdge(ToBB, this);
+
+  // The live-ins from the successor must be copied to the new BB
+  // or later sinks may create "zombie" defines.
+  if (!ToBB->livein_empty())
+    for (MachineBasicBlock::livein_iterator I = ToBB->livein_begin(),
+	   E = ToBB->livein_end(); I != E; ++I)
+      result->addLiveIn(*I);
+
+  return result;
 }

 static bool AvoidsSinking(MachineInstr *MI, MachineRegisterInfo *MRI) {

Is there some reason you're putting this into MachineSink.cpp instead
of changing MachineBasicBlock::SplitCriticalEdge?

Missing a null check for result.

-Eli



More information about the llvm-commits mailing list