[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat May 6 02:30:16 PDT 2006



Changes in directory llvm/lib/CodeGen/SelectionDAG:

DAGCombiner.cpp updated: 1.159 -> 1.160
---
Log message:

Use the new TargetLowering::ComputeNumSignBits method to eliminate 
sign_extend_inreg operations.  Though ComputeNumSignBits is still rudimentary,
this is enough to compile this:

short test(short X, short x) {
  int Y = X+x;
  return (Y >> 1);
}
short test2(short X, short x) {
  int Y = (short)(X+x);
  return Y >> 1;
}

into:

_test:
        add r2, r3, r4
        srawi r3, r2, 1
        blr
_test2:
        add r2, r3, r4
        extsh r2, r2
        srawi r3, r2, 1
        blr

instead of:

_test:
        add r2, r3, r4
        srawi r2, r2, 1
        extsh r3, r2
        blr
_test2:
        add r2, r3, r4
        extsh r2, r2
        srawi r2, r2, 1
        extsh r3, r2
        blr




---
Diffs of the changes:  (+5 -5)

 DAGCombiner.cpp |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.159 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.160
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.159	Fri May  5 17:56:26 2006
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp	Sat May  6 04:30:03 2006
@@ -1937,6 +1937,11 @@
     SDOperand Truncate = DAG.getConstant(N0C->getValue(), EVT);
     return DAG.getNode(ISD::SIGN_EXTEND, VT, Truncate);
   }
+  
+  // If the input is already sign extended, just drop the extend.
+  if (TLI.ComputeNumSignBits(N0) >= MVT::getSizeInBits(VT)-EVTBits+1)
+    return N0;
+  
   // fold (sext_in_reg (sext_in_reg x, VT2), VT1) -> (sext_in_reg x, minVT) pt1
   if (N0.getOpcode() == ISD::SIGN_EXTEND_INREG && 
       cast<VTSDNode>(N0.getOperand(1))->getVT() <= EVT) {
@@ -1947,11 +1952,6 @@
       EVT < cast<VTSDNode>(N0.getOperand(1))->getVT()) {
     return DAG.getNode(ISD::SIGN_EXTEND_INREG, VT, N0.getOperand(0), N1);
   }
-  // fold (sext_in_reg (assert_sext x)) -> (assert_sext x)
-  if (N0.getOpcode() == ISD::AssertSext && 
-      cast<VTSDNode>(N0.getOperand(1))->getVT() <= EVT) {
-    return N0;
-  }
   // fold (sext_in_reg (sextload x)) -> (sextload x)
   if (N0.getOpcode() == ISD::SEXTLOAD && 
       cast<VTSDNode>(N0.getOperand(3))->getVT() <= EVT) {






More information about the llvm-commits mailing list