Repository: llvm/llvm-project
File: llvm/lib/Target/RISCV/RISCVMoveMerger.cpp (C++)

Code before:
      std::swap(Sreg1, Sreg2);
  } else {
    Sreg1 = FirstPair.Destination;
    Sreg2 = PairedRegs.Destination;
    if (FirstPair.Source->getReg() != RISCV::X10)
      std::swap(Sreg1, Sreg2);
  }

  if (!ST->hasStdExtZcmp() && !ST->hasVendorXqccmp()) {
    Register SrcReg1, SrcReg2, DestReg;

    SrcReg1 =
        TRI->getMatchingSuperReg(FirstPair.Source->getReg(),
                                 RISCV::sub_gpr_even, &RISCV::GPRPairRegClass);
    SrcReg2 = ST->hasStdExtZdinx() ? SrcReg1 : Register(RISCV::X0_Pair);
    DestReg =
        TRI->getMatchingSuperReg(FirstPair.Destination->getReg(),
                                 RISCV::sub_gpr_even, &RISCV::GPRPairRegClass);

    BuildMI(*I->getParent(), I, DL, TII->get(Opcode), DestReg)
        .addReg(SrcReg1, getKillRegState(PairedSource.isKill() &&
                                         FirstPair.Source->isKill()))
        .addReg(SrcReg2, getKillRegState(PairedSource.isKill() &&
                                         FirstPair.Source->isKill()));
  } else
    BuildMI(*I->getParent(), I, DL, TII->get(Opcode)).add(*Sreg1).add(*Sreg2);

  I->eraseFromParent();
  Paired->eraseFromParent();
  return NextI;
}

MachineBasicBlock::iterator
RISCVMoveMerge::findMatchingInstPair(MachineBasicBlock::iterator &MBBI,
                                     const DestSourcePair &RegPair) {
  MachineBasicBlock::iterator E = MBBI->getParent()->end();
  ModifiedRegUnits.clear();
  UsedRegUnits.clear();

  for (MachineBasicBlock::iterator I = next_nodbg(MBBI, E); I != E;
       I = next_nodbg(I, E)) {

    MachineInstr &MI = *I;

    if (auto SecondPair = TII->isCopyInstrImpl(MI)) {
      Register SourceReg = SecondPair->Source->getReg();
      Register DestReg = SecondPair->Destination->getReg();

      if (RegPair.Destination->getReg() == DestReg ||
          RegPair.Source->getReg() == SourceReg)
        return E;

Review comment (suggestion):
If the `if` has `{}`, then the `else` should have them too.

Code after:
      std::swap(Sreg1, Sreg2);
  } else {
    Sreg1 = FirstPair.Destination;
    Sreg2 = PairedRegs.Destination;
    if (FirstPair.Source->getReg() != RISCV::X10)
      std::swap(Sreg1, Sreg2);
  }

  if (!ST->hasStdExtZcmp() && !ST->hasVendorXqccmp()) {
    Register SrcReg1, SrcReg2, DestReg;

    SrcReg1 =
        TRI->getMatchingSuperReg(FirstPair.Source->getReg(),
                                 RISCV::sub_gpr_even, &RISCV::GPRPairRegClass);
    SrcReg2 = ST->hasStdExtZdinx() ? SrcReg1 : Register(RISCV::X0_Pair);
    DestReg =
        TRI->getMatchingSuperReg(FirstPair.Destination->getReg(),
                                 RISCV::sub_gpr_even, &RISCV::GPRPairRegClass);

    BuildMI(*I->getParent(), I, DL, TII->get(Opcode), DestReg)
        .addReg(SrcReg1, getKillRegState(PairedSource.isKill() &&
                                         FirstPair.Source->isKill()))
        .addReg(SrcReg2, getKillRegState(PairedSource.isKill() &&
                                         FirstPair.Source->isKill()));
  } else {
    BuildMI(*I->getParent(), I, DL, TII->get(Opcode)).add(*Sreg1).add(*Sreg2);
  }

  I->eraseFromParent();
  Paired->eraseFromParent();
  return NextI;
}

MachineBasicBlock::iterator
RISCVMoveMerge::findMatchingInstPair(MachineBasicBlock::iterator &MBBI,
                                     const DestSourcePair &RegPair) {
  MachineBasicBlock::iterator E = MBBI->getParent()->end();
  ModifiedRegUnits.clear();
  UsedRegUnits.clear();

  for (MachineBasicBlock::iterator I = next_nodbg(MBBI, E); I != E;
       I = next_nodbg(I, E)) {

    MachineInstr &MI = *I;

    if (auto SecondPair = TII->isCopyInstrImpl(MI)) {
      Register SourceReg = SecondPair->Source->getReg();
      Register DestReg = SecondPair->Destination->getReg();

      if (RegPair.Destination->getReg() == DestReg ||
          RegPair.Source->getReg() == SourceReg)