@@ -110,12 +110,18 @@ XtensaTargetLowering::XtensaTargetLowering(const TargetMachine &TM,
110
110
111
111
setOperationAction (ISD::BR_CC, MVT::i32 , Legal);
112
112
setOperationAction (ISD::BR_CC, MVT::i64 , Expand);
113
- setOperationAction (ISD::BR_CC, MVT::f32 , Expand);
114
113
115
114
setOperationAction (ISD::SELECT, MVT::i32 , Expand);
116
115
setOperationAction (ISD::SELECT, MVT::f32 , Expand);
117
116
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
+ }
119
125
120
126
setOperationAction (ISD::SETCC, MVT::i32 , Expand);
121
127
setOperationAction (ISD::SETCC, MVT::f32 , Expand);
@@ -841,21 +847,68 @@ static unsigned getBranchOpcode(ISD::CondCode Cond) {
841
847
}
842
848
}
843
849
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
+
844
884
SDValue XtensaTargetLowering::LowerSELECT_CC (SDValue Op,
845
885
SelectionDAG &DAG) const {
846
886
SDLoc DL (Op);
847
- EVT Ty = Op.getOperand ( 0 ). getValueType ();
887
+ EVT Ty = Op.getValueType ();
848
888
SDValue LHS = Op.getOperand (0 );
849
889
SDValue RHS = Op.getOperand (1 );
850
890
SDValue TrueValue = Op.getOperand (2 );
851
891
SDValue FalseValue = Op.getOperand (3 );
852
892
ISD::CondCode CC = cast<CondCodeSDNode>(Op->getOperand (4 ))->get ();
853
893
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 );
856
897
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 ());
859
912
}
860
913
861
914
SDValue XtensaTargetLowering::LowerRETURNADDR (SDValue Op,
@@ -1408,6 +1461,8 @@ const char *XtensaTargetLowering::getTargetNodeName(unsigned Opcode) const {
1408
1461
return " XtensaISD::RETW" ;
1409
1462
case XtensaISD::SELECT_CC:
1410
1463
return " XtensaISD::SELECT_CC" ;
1464
+ case XtensaISD::SELECT_CC_FP:
1465
+ return " XtensaISD::SELECT_CC_FP" ;
1411
1466
case XtensaISD::SRCL:
1412
1467
return " XtensaISD::SRCL" ;
1413
1468
case XtensaISD::SRCR:
@@ -1450,7 +1505,6 @@ XtensaTargetLowering::emitSelectCC(MachineInstr &MI,
1450
1505
MachineOperand &RHS = MI.getOperand (2 );
1451
1506
MachineOperand &TrueValue = MI.getOperand (3 );
1452
1507
MachineOperand &FalseValue = MI.getOperand (4 );
1453
- unsigned BrKind = MI.getOperand (5 ).getImm ();
1454
1508
1455
1509
// To "insert" a SELECT_CC instruction, we actually have to insert
1456
1510
// CopyMBB and SinkMBB blocks and add branch to MBB. We build phi
@@ -1482,10 +1536,25 @@ XtensaTargetLowering::emitSelectCC(MachineInstr &MI,
1482
1536
MBB->addSuccessor (CopyMBB);
1483
1537
MBB->addSuccessor (SinkMBB);
1484
1538
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
+ }
1489
1558
1490
1559
CopyMBB->addSuccessor (SinkMBB);
1491
1560
@@ -1510,6 +1579,30 @@ MachineBasicBlock *XtensaTargetLowering::EmitInstrWithCustomInserter(
1510
1579
const XtensaInstrInfo &TII = *Subtarget.getInstrInfo ();
1511
1580
1512
1581
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:
1513
1606
case Xtensa::SELECT:
1514
1607
return emitSelectCC (MI, MBB);
1515
1608
case Xtensa::S8I:
0 commit comments