summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-03-09 18:37:12 +0000
committerChris Lattner <sabre@nondot.org>2005-03-09 18:37:12 +0000
commit7f269467093866121f20def83785383c18f9ab89 (patch)
treeb014d6db4aa3800a6f8a1933764e5360f8341334 /llvm/lib/CodeGen
parentb1d901427a13fde2b1efbb25d89f402c26dfb8b6 (diff)
downloadbcm5719-llvm-7f269467093866121f20def83785383c18f9ab89.tar.gz
bcm5719-llvm-7f269467093866121f20def83785383c18f9ab89.zip
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. llvm-svn: 20534
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index a0e5d93f62e..fb52d11bd3d 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -946,6 +946,9 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,SDOperand N1,
"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 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,SDOperand N1,
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) {
OpenPOWER on IntegriCloud