aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-12-23 05:30:37 +0000
committerChris Lattner <sabre@nondot.org>2005-12-23 05:30:37 +0000
commit94683777aee436a0e5f12e08a4b3827a11265fb2 (patch)
tree22c0c6978be35729fe24c813d3d4c2e1d0963a6d /lib/CodeGen/SelectionDAG/SelectionDAG.cpp
parent21f66859e4338c40d29cf54123bab7bfa0a182d0 (diff)
constant fold bits_convert in getNode and in the dag combiner for fp<->int
conversions. This allows V8 to compiles this: void %test() { call float %test2( float 1.000000e+00, float 2.000000e+00, double 3.000000e+00, double* null ) ret void } into: test: save -96, %o6, %o6 sethi 0, %o3 sethi 1049088, %o2 sethi 1048576, %o1 sethi 1040384, %o0 or %g0, %o3, %o4 call test2 nop restore %g0, %g0, %g0 retl nop instead of: test: save -112, %o6, %o6 sethi 0, %o4 sethi 1049088, %l0 st %o4, [%i6+-12] st %l0, [%i6+-16] ld [%i6+-12], %o3 ld [%i6+-16], %o2 sethi 1048576, %o1 sethi 1040384, %o0 call test2 nop restore %g0, %g0, %g0 retl nop git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24980 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/SelectionDAG.cpp')
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAG.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index ec75dfee32..76d983f57e 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -828,6 +828,7 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT) {
SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
SDOperand Operand) {
+ // Constant fold unary operations with an integer constant operand.
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Operand.Val)) {
uint64_t Val = C->getValue();
switch (Opcode) {
@@ -838,13 +839,25 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
case ISD::TRUNCATE: return getConstant(Val, VT);
case ISD::SINT_TO_FP: return getConstantFP(C->getSignExtended(), VT);
case ISD::UINT_TO_FP: return getConstantFP(C->getValue(), VT);
+ case ISD::BIT_CONVERT:
+ if (VT == MVT::f32) {
+ assert(C->getValueType(0) == MVT::i32 && "Invalid bit_convert!");
+ return getConstantFP(BitsToFloat(Val), VT);
+ } else if (VT == MVT::f64) {
+ assert(C->getValueType(0) == MVT::i64 && "Invalid bit_convert!");
+ return getConstantFP(BitsToDouble(Val), VT);
+ }
+ break;
}
}
+ // Constant fold unary operations with an floating point constant operand.
if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(Operand.Val))
switch (Opcode) {
case ISD::FNEG:
return getConstantFP(-C->getValue(), VT);
+ case ISD::FABS:
+ return getConstantFP(fabs(C->getValue()), VT);
case ISD::FP_ROUND:
case ISD::FP_EXTEND:
return getConstantFP(C->getValue(), VT);
@@ -852,6 +865,15 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
return getConstant((int64_t)C->getValue(), VT);
case ISD::FP_TO_UINT:
return getConstant((uint64_t)C->getValue(), VT);
+ case ISD::BIT_CONVERT:
+ if (VT == MVT::i32) {
+ assert(C->getValueType(0) == MVT::f32 && "Invalid bit_convert!");
+ return getConstant(FloatToBits(C->getValue()), VT);
+ } else if (VT == MVT::i64) {
+ assert(C->getValueType(0) == MVT::f64 && "Invalid bit_convert!");
+ return getConstant(DoubleToBits(C->getValue()), VT);
+ }
+ break;
}
unsigned OpOpcode = Operand.Val->getOpcode();