[LLVMdev] Question about 'DuplicateInstruction' function of TailDuplicatePass in CodeGen

JinGu Kang jingu at codeplay.com
Tue Jun 17 08:00:31 PDT 2014


Hi all,

I have faced a little bit of a strange transformation from the 
TailDuplicatePass In CodeGen. When the pass clones the contents of 
TailBB into PredBB, the bundled instructions in TailBB are not bundled 
in PredBB. I think the reason why it is not bundled is that the 
'DuplicateInstruction' function does not set up the flag of the first 
instruction of the bundle in PredBB when it is cloned from TailBB. If 
the first instruction of the bundle is set up in PredBB, the 
'MachineBasicBlock->insert()' function would automatically put the next 
instructions into the bundle. How do you feel about this?

I did not find the API in order to make the first instruction of the 
bundle. I have added simple code to make bundled instructions from the 
'DuplicateInstruction' function. As a reference, I have attached a 
simple patch. If there is something wrong, please let me know.

Thanks,
JinGu Kang



-------------- next part --------------
Index: lib/CodeGen/TailDuplication.cpp
===================================================================
--- lib/CodeGen/TailDuplication.cpp	(revision 211103)
+++ lib/CodeGen/TailDuplication.cpp	(working copy)
@@ -453,6 +453,11 @@
     }
   }
   PredBB->insert(PredBB->instr_end(), NewMI);
+
+  /// If there is bundled instruction in TailBB,
+  /// make bundled instruction in PredBB.
+  if (MI->isBundled() && MI->isInsideBundle())
+    NewMI->bundleWithPred();
 }
 
 /// UpdateSuccessorsPHIs - After FromBB is tail duplicated into its predecessor


More information about the llvm-dev mailing list