@@ -517,6 +517,38 @@ XtensaTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
517
517
return DAG.getNode (XtensaISD::RET, DL, MVT::Other, RetOps);
518
518
}
519
519
520
+ static unsigned getBranchOpcode (ISD::CondCode Cond, bool &BrInv) {
521
+ BrInv = false ;
522
+ switch (Cond) {
523
+ case ISD::SETEQ:
524
+ return Xtensa::BEQ;
525
+ case ISD::SETNE:
526
+ return Xtensa::BNE;
527
+ case ISD::SETLT:
528
+ return Xtensa::BLT;
529
+ case ISD::SETLE:
530
+ BrInv = true ;
531
+ return Xtensa::BGE;
532
+ case ISD::SETGT:
533
+ BrInv = true ;
534
+ return Xtensa::BLT;
535
+ case ISD::SETGE:
536
+ return Xtensa::BGE;
537
+ case ISD::SETULT:
538
+ return Xtensa::BLTU;
539
+ case ISD::SETULE:
540
+ BrInv = true ;
541
+ return Xtensa::BGEU;
542
+ case ISD::SETUGT:
543
+ BrInv = true ;
544
+ return Xtensa::BLTU;
545
+ case ISD::SETUGE:
546
+ return Xtensa::BGEU;
547
+ default :
548
+ llvm_unreachable (" Unknown branch kind" );
549
+ }
550
+ }
551
+
520
552
SDValue XtensaTargetLowering::LowerSELECT_CC (SDValue Op,
521
553
SelectionDAG &DAG) const {
522
554
SDLoc DL (Op);
@@ -526,11 +558,19 @@ SDValue XtensaTargetLowering::LowerSELECT_CC(SDValue Op,
526
558
SDValue TrueValue = Op.getOperand (2 );
527
559
SDValue FalseValue = Op.getOperand (3 );
528
560
ISD::CondCode CC = cast<CondCodeSDNode>(Op->getOperand (4 ))->get ();
529
- SDValue TargetCC = DAG.getConstant (CC, DL, MVT::i32);
561
+
562
+ bool BrInv;
563
+ unsigned BrKind = getBranchOpcode (CC, BrInv);
564
+ SDValue TargetCC = DAG.getConstant (BrKind, DL, MVT::i32);
530
565
531
566
// Wrap select nodes
532
- return DAG.getNode (XtensaISD::SELECT_CC, DL, Ty, LHS, RHS, TrueValue,
533
- FalseValue, TargetCC);
567
+ if (BrInv) {
568
+ return DAG.getNode (XtensaISD::SELECT_CC, DL, Ty, RHS, LHS, TrueValue,
569
+ FalseValue, TargetCC);
570
+ } else {
571
+ return DAG.getNode (XtensaISD::SELECT_CC, DL, Ty, LHS, RHS, TrueValue,
572
+ FalseValue, TargetCC);
573
+ }
534
574
}
535
575
536
576
SDValue XtensaTargetLowering::LowerImmediate (SDValue Op,
@@ -728,37 +768,6 @@ const char *XtensaTargetLowering::getTargetNodeName(unsigned Opcode) const {
728
768
// Custom insertion
729
769
// ===----------------------------------------------------------------------===//
730
770
731
- static int GetBranchKind (int Cond, bool &BrInv) {
732
- switch (Cond) {
733
- case ISD::SETEQ:
734
- return Xtensa::BEQ;
735
- case ISD::SETNE:
736
- return Xtensa::BNE;
737
- case ISD::SETLT:
738
- return Xtensa::BLT;
739
- case ISD::SETLE:
740
- BrInv = true ;
741
- return Xtensa::BGE;
742
- case ISD::SETGT:
743
- BrInv = true ;
744
- return Xtensa::BLT;
745
- case ISD::SETGE:
746
- return Xtensa::BGE;
747
- case ISD::SETULT:
748
- return Xtensa::BLTU;
749
- case ISD::SETULE:
750
- BrInv = true ;
751
- return Xtensa::BGEU;
752
- case ISD::SETUGT:
753
- BrInv = true ;
754
- return Xtensa::BLTU;
755
- case ISD::SETUGE:
756
- return Xtensa::BGEU;
757
- default :
758
- return -1 ;
759
- }
760
- }
761
-
762
771
MachineBasicBlock *
763
772
XtensaTargetLowering::emitSelectCC (MachineInstr &MI,
764
773
MachineBasicBlock *MBB) const {
@@ -769,7 +778,7 @@ XtensaTargetLowering::emitSelectCC(MachineInstr &MI,
769
778
MachineOperand &RHS = MI.getOperand (2 );
770
779
MachineOperand &TrueValue = MI.getOperand (3 );
771
780
MachineOperand &FalseValue = MI.getOperand (4 );
772
- MachineOperand &Cond = MI.getOperand (5 );
781
+ unsigned BrKind = MI.getOperand (5 ). getImm ( );
773
782
774
783
// To "insert" a SELECT_CC instruction, we actually have to insert
775
784
// CopyMBB and SinkMBB blocks and add branch to MBB. We build phi
@@ -801,19 +810,10 @@ XtensaTargetLowering::emitSelectCC(MachineInstr &MI,
801
810
MBB->addSuccessor (CopyMBB);
802
811
MBB->addSuccessor (SinkMBB);
803
812
804
- bool BrInv = false ;
805
- int BrKind = GetBranchKind (Cond.getImm (), BrInv);
806
- if (BrInv) {
807
- BuildMI (MBB, DL, TII.get (BrKind))
808
- .addReg (RHS.getReg ())
809
- .addReg (LHS.getReg ())
810
- .addMBB (SinkMBB);
811
- } else {
812
- BuildMI (MBB, DL, TII.get (BrKind))
813
- .addReg (LHS.getReg ())
814
- .addReg (RHS.getReg ())
815
- .addMBB (SinkMBB);
816
- }
813
+ BuildMI (MBB, DL, TII.get (BrKind))
814
+ .addReg (LHS.getReg ())
815
+ .addReg (RHS.getReg ())
816
+ .addMBB (SinkMBB);
817
817
818
818
CopyMBB->addSuccessor (SinkMBB);
819
819
@@ -838,6 +838,6 @@ MachineBasicBlock *XtensaTargetLowering::EmitInstrWithCustomInserter(
838
838
case Xtensa::SELECT:
839
839
return emitSelectCC (MI, MBB);
840
840
default :
841
- report_fatal_error (" Unexpected instr type to insert" );
841
+ llvm_unreachable (" Unexpected instr type to insert" );
842
842
}
843
843
}
0 commit comments