[PATCH] Remove redundent register mov by improving TwoAddressInstructionPass

Quentin Colombet qcolombet at apple.com
Wed Feb 25 09:53:56 PST 2015


REPOSITORY
  rL LLVM

================
Comment at: lib/CodeGen/TwoAddressInstructionPass.cpp:319
@@ +318,3 @@
+  MachineInstr *ret = NULL;
+  for (MachineOperand &MO : MRI->reg_operands(Reg)) {
+    MachineInstr *MI = MO.getParent();
----------------
Use def_instructions or def_operands instead.
That way, you wouldn’t have to check for isDef in the loop.

================
Comment at: lib/CodeGen/TwoAddressInstructionPass.cpp:342
@@ +341,3 @@
+  // Length limit is to avoid endless searching in a copy chain loop.
+  int Length = 3;
+  for (int i = 0; i < Length; i++) {
----------------
I would rather have a set of visited copies or reg instead of a magic constant.
If it turns out to be too expensive, then we can introduce parametrizable magic constant!

================
Comment at: lib/CodeGen/TwoAddressInstructionPass.cpp:345
@@ +344,3 @@
+    MachineInstr *Def = getSingleDef(TmpReg, MBB, MRI);
+    if (Def && Def->isCopy())
+      TmpReg = Def->getOperand(1).getReg();
----------------
LLVM idiom would be the opposite:
if (!Def || !…)
   return false;

================
Comment at: lib/CodeGen/TwoAddressInstructionPass.cpp:628
@@ +627,3 @@
+  // If there is a reversed copy chain from reg101 to reg103, commute the ADD
+  // to eliminate an otherwise unavoidable copy.
+  // FIXME:
----------------
nitpick:
"to *hopefully* eliminate an otherwise unavoidable copy.”

We do not have guarantee that copy will indeed be eliminated.

================
Comment at: lib/CodeGen/TwoAddressInstructionPass.cpp:635
@@ +634,3 @@
+  // instruction pass should be integrated with register allocation pass where
+  // interference graph is available.
+  if (isRevCopyChain(regC, regA))
----------------
For the record, if you are interested into this, look into the register coalescer pass.

================
Comment at: test/CodeGen/X86/twoaddr-coalesce-3.ll:44
@@ +43,3 @@
+; Function Attrs: nounwind uwtable
+define void @goo() #0 {
+entry:
----------------
No need for #0.

http://reviews.llvm.org/D7806

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list