@@ -110,12 +110,18 @@ XtensaTargetLowering::XtensaTargetLowering(const TargetMachine &TM,
110110
111111 setOperationAction (ISD::BR_CC, MVT::i32 , Legal);
112112 setOperationAction (ISD::BR_CC, MVT::i64 , Expand);
113- setOperationAction (ISD::BR_CC, MVT::f32 , Expand);
114113
115114 setOperationAction (ISD::SELECT, MVT::i32 , Expand);
116115 setOperationAction (ISD::SELECT, MVT::f32 , Expand);
117116 setOperationAction (ISD::SELECT_CC, MVT::i32 , Custom);
118- setOperationAction (ISD::SELECT_CC, MVT::f32 , Expand);
117+
118+ if (Subtarget.hasSingleFloat ()) {
119+ setOperationAction (ISD::BR_CC, MVT::f32 , Legal);
120+ setOperationAction (ISD::SELECT_CC, MVT::f32 , Custom);
121+ } else {
122+ setOperationAction (ISD::BR_CC, MVT::f32 , Expand);
123+ setOperationAction (ISD::SELECT_CC, MVT::f32 , Expand);
124+ }
119125
120126 setOperationAction (ISD::SETCC, MVT::i32 , Expand);
121127 setOperationAction (ISD::SETCC, MVT::f32 , Expand);
@@ -841,21 +847,68 @@ static unsigned getBranchOpcode(ISD::CondCode Cond) {
841847 }
842848}
843849
850+ static std::pair<unsigned , unsigned > getFPBranchKind (ISD::CondCode Cond) {
851+ switch (Cond) {
852+ case ISD::SETUNE:
853+ return std::make_pair (Xtensa::BF, Xtensa::OEQ_S);
854+ case ISD::SETUO:
855+ return std::make_pair (Xtensa::BT, Xtensa::UN_S);
856+ case ISD::SETO:
857+ return std::make_pair (Xtensa::BF, Xtensa::UN_S);
858+ case ISD::SETUEQ:
859+ return std::make_pair (Xtensa::BT, Xtensa::UEQ_S);
860+ case ISD::SETULE:
861+ return std::make_pair (Xtensa::BT, Xtensa::ULE_S);
862+ case ISD::SETULT:
863+ return std::make_pair (Xtensa::BT, Xtensa::ULT_S);
864+ case ISD::SETEQ:
865+ case ISD::SETOEQ:
866+ return std::make_pair (Xtensa::BT, Xtensa::OEQ_S);
867+ case ISD::SETNE:
868+ return std::make_pair (Xtensa::BF, Xtensa::OEQ_S);
869+ case ISD::SETLE:
870+ case ISD::SETOLE:
871+ return std::make_pair (Xtensa::BT, Xtensa::OLE_S);
872+ case ISD::SETLT:
873+ case ISD::SETOLT:
874+ return std::make_pair (Xtensa::BT, Xtensa::OLT_S);
875+ case ISD::SETGE:
876+ return std::make_pair (Xtensa::BF, Xtensa::OLT_S);
877+ case ISD::SETGT:
878+ return std::make_pair (Xtensa::BF, Xtensa::OLE_S);
879+ default :
880+ llvm_unreachable (" Invalid condition!" );
881+ }
882+ }
883+
844884SDValue XtensaTargetLowering::LowerSELECT_CC (SDValue Op,
845885 SelectionDAG &DAG) const {
846886 SDLoc DL (Op);
847- EVT Ty = Op.getOperand ( 0 ). getValueType ();
887+ EVT Ty = Op.getValueType ();
848888 SDValue LHS = Op.getOperand (0 );
849889 SDValue RHS = Op.getOperand (1 );
850890 SDValue TrueValue = Op.getOperand (2 );
851891 SDValue FalseValue = Op.getOperand (3 );
852892 ISD::CondCode CC = cast<CondCodeSDNode>(Op->getOperand (4 ))->get ();
853893
854- unsigned BrOpcode = getBranchOpcode (CC);
855- SDValue TargetCC = DAG.getConstant (BrOpcode, DL, MVT::i32 );
894+ if (LHS.getValueType () == MVT::i32 ) {
895+ unsigned BrOpcode = getBranchOpcode (CC);
896+ SDValue TargetCC = DAG.getConstant (BrOpcode, DL, MVT::i32 );
856897
857- return DAG.getNode (XtensaISD::SELECT_CC, DL, Ty, LHS, RHS, TrueValue,
858- FalseValue, TargetCC);
898+ SDValue Res = DAG.getNode (XtensaISD::SELECT_CC, DL, Ty, LHS, RHS, TrueValue,
899+ FalseValue, TargetCC, Op->getFlags ());
900+ return Res;
901+ }
902+ assert (LHS.getValueType () == MVT::f32 &&
903+ " We expect MVT::f32 type of the LHS Operand in SELECT_CC" );
904+ unsigned BrOpcode;
905+ unsigned CmpOpCode;
906+ std::tie (BrOpcode, CmpOpCode) = getFPBranchKind (CC);
907+ SDValue TargetCC = DAG.getConstant (CmpOpCode, DL, MVT::i32 );
908+ SDValue TargetBC = DAG.getConstant (BrOpcode, DL, MVT::i32 );
909+ return DAG.getNode (XtensaISD::SELECT_CC_FP, DL, Ty,
910+ {LHS, RHS, TrueValue, FalseValue, TargetCC, TargetBC},
911+ Op->getFlags ());
859912}
860913
861914SDValue XtensaTargetLowering::LowerRETURNADDR (SDValue Op,
@@ -1408,6 +1461,8 @@ const char *XtensaTargetLowering::getTargetNodeName(unsigned Opcode) const {
14081461 return " XtensaISD::RETW" ;
14091462 case XtensaISD::SELECT_CC:
14101463 return " XtensaISD::SELECT_CC" ;
1464+ case XtensaISD::SELECT_CC_FP:
1465+ return " XtensaISD::SELECT_CC_FP" ;
14111466 case XtensaISD::SRCL:
14121467 return " XtensaISD::SRCL" ;
14131468 case XtensaISD::SRCR:
@@ -1450,7 +1505,6 @@ XtensaTargetLowering::emitSelectCC(MachineInstr &MI,
14501505 MachineOperand &RHS = MI.getOperand (2 );
14511506 MachineOperand &TrueValue = MI.getOperand (3 );
14521507 MachineOperand &FalseValue = MI.getOperand (4 );
1453- unsigned BrKind = MI.getOperand (5 ).getImm ();
14541508
14551509 // To "insert" a SELECT_CC instruction, we actually have to insert
14561510 // CopyMBB and SinkMBB blocks and add branch to MBB. We build phi
@@ -1482,10 +1536,25 @@ XtensaTargetLowering::emitSelectCC(MachineInstr &MI,
14821536 MBB->addSuccessor (CopyMBB);
14831537 MBB->addSuccessor (SinkMBB);
14841538
1485- BuildMI (MBB, DL, TII.get (BrKind))
1486- .addReg (LHS.getReg ())
1487- .addReg (RHS.getReg ())
1488- .addMBB (SinkMBB);
1539+ if (MI.getOpcode () == Xtensa::SELECT_CC_FP_FP ||
1540+ MI.getOpcode () == Xtensa::SELECT_CC_FP_INT) {
1541+ unsigned CmpKind = MI.getOperand (5 ).getImm ();
1542+ unsigned BrKind = MI.getOperand (6 ).getImm ();
1543+ MCPhysReg BReg = Xtensa::B0;
1544+
1545+ BuildMI (MBB, DL, TII.get (CmpKind), BReg)
1546+ .addReg (LHS.getReg ())
1547+ .addReg (RHS.getReg ());
1548+ BuildMI (MBB, DL, TII.get (BrKind))
1549+ .addReg (BReg, RegState::Kill)
1550+ .addMBB (SinkMBB);
1551+ } else {
1552+ unsigned BrKind = MI.getOperand (5 ).getImm ();
1553+ BuildMI (MBB, DL, TII.get (BrKind))
1554+ .addReg (LHS.getReg ())
1555+ .addReg (RHS.getReg ())
1556+ .addMBB (SinkMBB);
1557+ }
14891558
14901559 CopyMBB->addSuccessor (SinkMBB);
14911560
@@ -1510,6 +1579,30 @@ MachineBasicBlock *XtensaTargetLowering::EmitInstrWithCustomInserter(
15101579 const XtensaInstrInfo &TII = *Subtarget.getInstrInfo ();
15111580
15121581 switch (MI.getOpcode ()) {
1582+ case Xtensa::BRCC_FP: {
1583+ MachineOperand &Cond = MI.getOperand (0 );
1584+ MachineOperand &LHS = MI.getOperand (1 );
1585+ MachineOperand &RHS = MI.getOperand (2 );
1586+ MachineBasicBlock *TargetBB = MI.getOperand (3 ).getMBB ();
1587+ unsigned BrKind = 0 ;
1588+ unsigned CmpKind = 0 ;
1589+ ISD::CondCode CondCode = (ISD::CondCode)Cond.getImm ();
1590+ MCPhysReg BReg = Xtensa::B0;
1591+
1592+ std::tie (BrKind, CmpKind) = getFPBranchKind (CondCode);
1593+ BuildMI (*MBB, MI, DL, TII.get (CmpKind), BReg)
1594+ .addReg (LHS.getReg ())
1595+ .addReg (RHS.getReg ());
1596+ BuildMI (*MBB, MI, DL, TII.get (BrKind))
1597+ .addReg (BReg, RegState::Kill)
1598+ .addMBB (TargetBB);
1599+
1600+ MI.eraseFromParent ();
1601+ return MBB;
1602+ }
1603+ case Xtensa::SELECT_CC_FP_FP:
1604+ case Xtensa::SELECT_CC_FP_INT:
1605+ case Xtensa::SELECT_CC_INT_FP:
15131606 case Xtensa::SELECT:
15141607 return emitSelectCC (MI, MBB);
15151608 case Xtensa::S8I:
0 commit comments