Skip to content

Commit 91d8624

Browse files
committed
Change legalizeop of FP_ROUND and FP_EXTEND to not fall through
into the ANY_EXTEND/ZERO_EXTEND/SIGN_EXTEND code to simplify it. Unmerge the code for FP_ROUND and FP_EXTEND from each other to make each one simpler. llvm-svn: 46061
1 parent 6e3379c commit 91d8624

File tree

1 file changed

+55
-32
lines changed

1 file changed

+55
-32
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3569,18 +3569,50 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
35693569
}
35703570
break;
35713571

3572-
case ISD::FP_EXTEND:
3572+
case ISD::FP_EXTEND: {
3573+
MVT::ValueType newVT = Op.getValueType();
3574+
MVT::ValueType oldVT = Op.getOperand(0).getValueType();
3575+
if (TLI.getConvertAction(oldVT, newVT) == TargetLowering::Expand) {
3576+
// The only other way we can lower this is to turn it into a STORE,
3577+
// LOAD pair, targetting a temporary ___location (a stack slot).
3578+
3579+
// NOTE: there is a choice here between constantly creating new stack
3580+
// slots and always reusing the same one. We currently always create
3581+
// new ones, as reuse may inhibit scheduling.
3582+
const Type *Ty = MVT::getTypeForValueType(oldVT);
3583+
uint64_t TySize = TLI.getTargetData()->getABITypeSize(Ty);
3584+
unsigned Align = TLI.getTargetData()->getPrefTypeAlignment(Ty);
3585+
MachineFunction &MF = DAG.getMachineFunction();
3586+
int SSFI =
3587+
MF.getFrameInfo()->CreateStackObject(TySize, Align);
3588+
SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy());
3589+
Result = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0),
3590+
StackSlot, NULL, 0);
3591+
Result = DAG.getExtLoad(ISD::EXTLOAD, newVT,
3592+
Result, StackSlot, NULL, 0, oldVT);
3593+
break;
3594+
}
3595+
}
3596+
switch (getTypeAction(Node->getOperand(0).getValueType())) {
3597+
case Expand: assert(0 && "Shouldn't need to expand other operators here!");
3598+
case Legal:
3599+
Tmp1 = LegalizeOp(Node->getOperand(0));
3600+
Result = DAG.UpdateNodeOperands(Result, Tmp1);
3601+
break;
3602+
case Promote:
3603+
Tmp1 = PromoteOp(Node->getOperand(0));
3604+
Result = DAG.getNode(ISD::FP_EXTEND, Op.getValueType(), Tmp1);
3605+
break;
3606+
}
3607+
break;
35733608
case ISD::FP_ROUND: {
35743609
MVT::ValueType newVT = Op.getValueType();
35753610
MVT::ValueType oldVT = Op.getOperand(0).getValueType();
35763611
if (TLI.getConvertAction(oldVT, newVT) == TargetLowering::Expand) {
3577-
if (Node->getOpcode() == ISD::FP_ROUND && oldVT == MVT::ppcf128) {
3612+
if (oldVT == MVT::ppcf128) {
35783613
SDOperand Lo, Hi;
35793614
ExpandOp(Node->getOperand(0), Lo, Hi);
3580-
if (newVT == MVT::f64)
3581-
Result = Hi;
3582-
else
3583-
Result = DAG.getNode(ISD::FP_ROUND, newVT, Hi);
3615+
Result = DAG.getNode(ISD::FP_ROUND, newVT, Hi);
35843616
break;
35853617
} else {
35863618
// The only other way we can lower this is to turn it into a STORE,
@@ -3589,30 +3621,31 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
35893621
// NOTE: there is a choice here between constantly creating new stack
35903622
// slots and always reusing the same one. We currently always create
35913623
// new ones, as reuse may inhibit scheduling.
3592-
MVT::ValueType slotVT =
3593-
(Node->getOpcode() == ISD::FP_EXTEND) ? oldVT : newVT;
3594-
const Type *Ty = MVT::getTypeForValueType(slotVT);
3624+
const Type *Ty = MVT::getTypeForValueType(newVT);
35953625
uint64_t TySize = TLI.getTargetData()->getABITypeSize(Ty);
35963626
unsigned Align = TLI.getTargetData()->getPrefTypeAlignment(Ty);
35973627
MachineFunction &MF = DAG.getMachineFunction();
3598-
int SSFI =
3599-
MF.getFrameInfo()->CreateStackObject(TySize, Align);
3628+
int SSFI = MF.getFrameInfo()->CreateStackObject(TySize, Align);
36003629
SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy());
3601-
if (Node->getOpcode() == ISD::FP_EXTEND) {
3602-
Result = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0),
3603-
StackSlot, NULL, 0);
3604-
Result = DAG.getExtLoad(ISD::EXTLOAD, newVT,
3605-
Result, StackSlot, NULL, 0, oldVT);
3606-
} else {
3607-
Result = DAG.getTruncStore(DAG.getEntryNode(), Node->getOperand(0),
3608-
StackSlot, NULL, 0, newVT);
3609-
Result = DAG.getLoad(newVT, Result, StackSlot, NULL, 0);
3610-
}
3630+
Result = DAG.getTruncStore(DAG.getEntryNode(), Node->getOperand(0),
3631+
StackSlot, NULL, 0, newVT);
3632+
Result = DAG.getLoad(newVT, Result, StackSlot, NULL, 0);
36113633
break;
36123634
}
36133635
}
36143636
}
3615-
// FALL THROUGH
3637+
switch (getTypeAction(Node->getOperand(0).getValueType())) {
3638+
case Expand: assert(0 && "Shouldn't need to expand other operators here!");
3639+
case Legal:
3640+
Tmp1 = LegalizeOp(Node->getOperand(0));
3641+
Result = DAG.UpdateNodeOperands(Result, Tmp1);
3642+
break;
3643+
case Promote:
3644+
Tmp1 = PromoteOp(Node->getOperand(0));
3645+
Result = DAG.getNode(ISD::FP_ROUND, Op.getValueType(), Tmp1);
3646+
break;
3647+
}
3648+
break;
36163649
case ISD::ANY_EXTEND:
36173650
case ISD::ZERO_EXTEND:
36183651
case ISD::SIGN_EXTEND:
@@ -3641,16 +3674,6 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
36413674
Result,
36423675
DAG.getValueType(Node->getOperand(0).getValueType()));
36433676
break;
3644-
case ISD::FP_EXTEND:
3645-
Result = PromoteOp(Node->getOperand(0));
3646-
if (Result.getValueType() != Op.getValueType())
3647-
// Dynamically dead while we have only 2 FP types.
3648-
Result = DAG.getNode(ISD::FP_EXTEND, Op.getValueType(), Result);
3649-
break;
3650-
case ISD::FP_ROUND:
3651-
Result = PromoteOp(Node->getOperand(0));
3652-
Result = DAG.getNode(Node->getOpcode(), Op.getValueType(), Result);
3653-
break;
36543677
}
36553678
}
36563679
break;

0 commit comments

Comments
 (0)