[llvm-commits] CVS: llvm/lib/Target/X86/X86ISelDAGToDAG.cpp

Evan Cheng evan.cheng at apple.com
Mon Dec 12 12:32:30 PST 2005



Changes in directory llvm/lib/Target/X86:

X86ISelDAGToDAG.cpp updated: 1.8 -> 1.9
---
Log message:

For ISD::RET, if # of operands >= 2, try selection the real data dep. operand
first before the chain.
e.g.
int X;

int foo(int x)
{
  x += X + 37;
  return x;
}

If chain operand is selected first, we would generate:
	movl X, %eax
	movl 4(%esp), %ecx
	leal 37(%ecx,%eax), %eax

rather than 
	movl $37, %eax
	addl 4(%esp), %eax
	addl X, %eax

which does not require %ecx. (Due to ADD32rm not matching.)


---
Diffs of the changes:  (+10 -2)

 X86ISelDAGToDAG.cpp |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
diff -u llvm/lib/Target/X86/X86ISelDAGToDAG.cpp:1.8 llvm/lib/Target/X86/X86ISelDAGToDAG.cpp:1.9
--- llvm/lib/Target/X86/X86ISelDAGToDAG.cpp:1.8	Fri Dec  9 18:48:20 2005
+++ llvm/lib/Target/X86/X86ISelDAGToDAG.cpp	Mon Dec 12 14:32:18 2005
@@ -356,15 +356,22 @@
       break;
 
     case ISD::RET: {
-      SDOperand Chain = Select(N->getOperand(0));     // Token chain.
-      switch (N->getNumOperands()) {
+      SDOperand Chain = N->getOperand(0);     // Token chain.
+      unsigned NumOps = N->getNumOperands();
+
+      // Note: A bit of a hack / optimization... Try to delay chain selection
+      // as much as possible. So it's more likely it has already been selected
+      // for a  real use.
+      switch (NumOps) {
         default:
           assert(0 && "Unknown return instruction!");
         case 3:
+          Chain = Select(Chain);
           assert(0 && "Not yet handled return instruction!");
           break;
         case 2: {
           SDOperand Val = Select(N->getOperand(1));
+          Chain = Select(Chain);
           switch (N->getOperand(1).getValueType()) {
             default:
               assert(0 && "All other types should have been promoted!!");
@@ -378,6 +385,7 @@
           }
         }
         case 1:
+          Chain = Select(Chain);
           break;
       }
       if (X86Lowering.getBytesToPopOnReturn() == 0)






More information about the llvm-commits mailing list