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

Chris Lattner lattner at cs.uiuc.edu
Wed Mar 9 10:37:28 PST 2005



Changes in directory llvm/lib/CodeGen/SelectionDAG:

SelectionDAG.cpp updated: 1.51 -> 1.52
---
Log message:

constant fold FP_ROUND_INREG, ZERO_EXTEND_INREG, and SIGN_EXTEND_INREG

This allows the alpha backend to compile:

bool %test(uint %P) {
        %c = seteq uint %P, 0
        ret bool %c
}

into:

test:
        ldgp $29, 0($27)
        ZAP $16,240,$0
        CMPEQ $0,0,$0
        AND $0,1,$0
        ret $31,($26),1

instead of:

test:
        ldgp $29, 0($27)
        ZAP $16,240,$0
        ldiq $1,0
        ZAP $1,240,$1
        CMPEQ $0,$1,$0
        AND $0,1,$0
        ret $31,($26),1

... and fixes PR534: http://llvm.cs.uiuc.edu/PR534 .



---
Diffs of the changes:  (+12 -0)

 SelectionDAG.cpp |   12 ++++++++++++
 1 files changed, 12 insertions(+)


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.51 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.52
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.51	Thu Feb 17 14:17:32 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp	Wed Mar  9 12:37:12 2005
@@ -946,6 +946,9 @@
            "Cannot FP_ROUND_INREG integer types");
     if (EVT == VT) return N1;  // Not actually rounding
     assert(EVT < VT && "Not rounding down!");
+
+    if (isa<ConstantFPSDNode>(N1))
+      return getNode(ISD::FP_EXTEND, VT, getNode(ISD::FP_ROUND, EVT, N1));
     break;
   case ISD::ZERO_EXTEND_INREG:
   case ISD::SIGN_EXTEND_INREG:
@@ -955,6 +958,15 @@
     if (EVT == VT) return N1;  // Not actually extending
     assert(EVT < VT && "Not extending!");
 
+    // Extending a constant?  Just return the constant.
+    if (ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.Val)) {
+      SDOperand Tmp = getNode(ISD::TRUNCATE, EVT, N1);
+      if (N1.getOpcode() == ISD::ZERO_EXTEND_INREG)
+        return getNode(ISD::ZERO_EXTEND, VT, Tmp);
+      else
+        return getNode(ISD::SIGN_EXTEND, VT, Tmp);
+    }
+
     // If we are sign extending an extension, use the original source.
     if (N1.getOpcode() == ISD::ZERO_EXTEND_INREG ||
         N1.getOpcode() == ISD::SIGN_EXTEND_INREG) {






More information about the llvm-commits mailing list