@@ -1005,48 +1005,48 @@ RISCVCC::CondCode RISCVCC::getOppositeBranchCondition(RISCVCC::CondCode CC) {
10051005 }
10061006}
10071007
1008- bool RISCVInstrInfo::trySimplifyCondBr (
1009- MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB,
1010- SmallVectorImpl<MachineOperand> &Cond) const {
1008+ // Return true if MO definitely contains the value one.
1009+ static bool isOne (MachineOperand &MO) {
1010+ if (MO.isImm () && MO.getImm () == 1 )
1011+ return true ;
10111012
1012- if (!TBB || Cond. size () != 3 )
1013+ if (!MO. isReg () || !MO. getReg (). isVirtual () )
10131014 return false ;
10141015
1015- RISCVCC::CondCode CC = static_cast <RISCVCC::CondCode>(Cond[0 ].getImm ());
1016- auto LHS = Cond[1 ];
1017- auto RHS = Cond[2 ];
1016+ MachineRegisterInfo &MRI =
1017+ MO.getParent ()->getParent ()->getParent ()->getRegInfo ();
1018+ MachineInstr *DefMI = MRI.getUniqueVRegDef (MO.getReg ());
1019+ if (!DefMI)
1020+ return false ;
10181021
1019- // Return true if MO definitely contains the value one.
1020- auto isOne = [](MachineOperand &MO) -> bool {
1021- if (MO.isImm () && MO.getImm () == 1 )
1022- return true ;
1022+ // For now, just check the canonical one value.
1023+ if (DefMI->getOpcode () == RISCV::ADDI &&
1024+ DefMI->getOperand (1 ).getReg () == RISCV::X0 &&
1025+ DefMI->getOperand (2 ).getImm () == 1 )
1026+ return true ;
10231027
1024- if (!MO. isReg () || !MO. getReg (). isVirtual ())
1025- return false ;
1028+ return false ;
1029+ }
10261030
1027- MachineRegisterInfo &MRI =
1028- MO.getParent ()->getParent ()->getParent ()->getRegInfo ();
1029- MachineInstr *DefMI = MRI.getUniqueVRegDef (MO.getReg ());
1030- if (!DefMI)
1031- return false ;
1031+ // Return true if MO definitely contains the value zero.
1032+ static bool isZero (MachineOperand &MO) {
1033+ if (MO.isImm () && MO.getImm () == 0 )
1034+ return true ;
1035+ if (MO.isReg () && MO.getReg () == RISCV::X0)
1036+ return true ;
1037+ return false ;
1038+ }
10321039
1033- // For now, just check the canonical one value.
1034- if (DefMI->getOpcode () == RISCV::ADDI &&
1035- DefMI->getOperand (1 ).getReg () == RISCV::X0 &&
1036- DefMI->getOperand (2 ).getImm () == 1 )
1037- return true ;
1040+ bool RISCVInstrInfo::trySimplifyCondBr (
1041+ MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB,
1042+ SmallVectorImpl<MachineOperand> &Cond) const {
10381043
1044+ if (!TBB || Cond.size () != 3 )
10391045 return false ;
1040- };
10411046
1042- // Return true if MO definitely contains the value zero.
1043- auto isZero = [](MachineOperand &MO) -> bool {
1044- if (MO.isImm () && MO.getImm () == 0 )
1045- return true ;
1046- if (MO.isReg () && MO.getReg () == RISCV::X0)
1047- return true ;
1048- return false ;
1049- };
1047+ RISCVCC::CondCode CC = static_cast <RISCVCC::CondCode>(Cond[0 ].getImm ());
1048+ auto LHS = Cond[1 ];
1049+ auto RHS = Cond[2 ];
10501050
10511051 MachineBasicBlock *Folded = nullptr ;
10521052 switch (CC) {
0 commit comments