Skip to content

Commit

Permalink
Revert "[VENTUS][RISCV][fix] Fix the float COPY instruction bug"
Browse files Browse the repository at this point in the history
This reverts commit 80a3ef9.
  • Loading branch information
zhoujingya committed Oct 8, 2023
1 parent 0a45eab commit 2b376d1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 34 deletions.
29 changes: 7 additions & 22 deletions llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "llvm/CodeGen/MachineCombinerPattern.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/RegisterScavenging.h"
#include "llvm/IR/DebugInfoMetadata.h"
Expand Down Expand Up @@ -146,22 +145,16 @@ void RISCVInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
const DebugLoc &DL, MCRegister DstReg,
MCRegister SrcReg, bool KillSrc) const {
const RISCVRegisterInfo *RRI = STI.getRegisterInfo();

// sGPR -> sGPR move
if (RISCV::GPRRegClass.contains(DstReg, SrcReg) &&
RISCVRegisterInfo::hasSGPRs(RRI->getPhysRegClass(DstReg)) &&
RISCVRegisterInfo::hasSGPRs(RRI->getPhysRegClass(SrcReg))) {
if (RISCV::GPRRegClass.contains(DstReg, SrcReg)) {
BuildMI(MBB, MBBI, DL, get(RISCV::ADDI), DstReg)
.addReg(SrcReg, getKillRegState(KillSrc))
.addImm(0);
return;
}

// vGPR -> vGPR move
if (RISCV::VGPRRegClass.contains(DstReg, SrcReg) &&
RISCVRegisterInfo::hasVGPRs(RRI->getPhysRegClass(DstReg)) &&
RISCVRegisterInfo::hasVGPRs(RRI->getPhysRegClass(SrcReg))) {
if (RISCV::VGPRRegClass.contains(DstReg, SrcReg)) {
BuildMI(MBB, MBBI, DL, get(RISCV::VADD_VX), DstReg)
.addReg(SrcReg, getKillRegState(KillSrc))
.addReg(RISCV::X0);
Expand All @@ -170,40 +163,32 @@ void RISCVInstrInfo::copyPhysReg(MachineBasicBlock &MBB,

// vGPR -> sGPR move
if (RISCV::GPRRegClass.contains(DstReg) &&
RISCVRegisterInfo::hasSGPRs(RRI->getPhysRegClass(DstReg)) &&
RISCV::VGPRRegClass.contains(SrcReg) &&
RISCVRegisterInfo::hasVGPRs(RRI->getPhysRegClass(SrcReg))) {
RISCV::VGPRRegClass.contains(SrcReg)) {
BuildMI(MBB, MBBI, DL, get(RISCV::VMV_X_S), DstReg)
.addReg(SrcReg, getKillRegState(KillSrc));
return;
}

// vGPR -> sGPRF32 move
if (RISCV::GPRF32RegClass.contains(DstReg) &&
RISCVRegisterInfo::hasFGPRs(RRI->getPhysRegClass(DstReg)) &&
RISCV::VGPRRegClass.contains(SrcReg) &&
RISCVRegisterInfo::hasVGPRs(RRI->getPhysRegClass(SrcReg))) {
RISCV::VGPRRegClass.contains(SrcReg)) {
BuildMI(MBB, MBBI, DL, get(RISCV::VFMV_F_S), DstReg)
.addReg(SrcReg, getKillRegState(KillSrc));
return;
}

// sGPR -> vGPR move
if (RISCV::GPRRegClass.contains(SrcReg) &&
RISCVRegisterInfo::hasSGPRs(RRI->getPhysRegClass(SrcReg)) &&
RISCV::VGPRRegClass.contains(DstReg) &&
RISCVRegisterInfo::hasVGPRs(RRI->getPhysRegClass(DstReg))) {
RISCV::VGPRRegClass.contains(DstReg)) {
BuildMI(MBB, MBBI, DL, get(RISCV::VMV_V_X), DstReg)
.addReg(DstReg, RegState::Undef)
.addReg(SrcReg, getKillRegState(KillSrc));
return;
}

// sGPRF32 -> vGPR move
if (RISCV::GPRF32RegClass.contains(SrcReg) &&
RISCVRegisterInfo::hasFGPRs(RRI->getPhysRegClass(SrcReg)) &&
RISCV::VGPRRegClass.contains(DstReg) &&
RISCVRegisterInfo::hasVGPRs(RRI->getPhysRegClass(DstReg))) {
if (RISCV::GPRF32RegClass.contains(SrcReg) &&
RISCV::VGPRRegClass.contains(DstReg)) {
BuildMI(MBB, MBBI, DL, get(RISCV::VFMV_S_F), DstReg)
.addReg(DstReg, RegState::Undef)
.addReg(SrcReg, getKillRegState(KillSrc));
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ RISCVRegisterInfo::getPhysRegClass(MCRegister Reg) const {
&RISCV::SReg_32RegClass,
*/
&RISCV::VGPRRegClass,
&RISCV::GPRF32RegClass,
&RISCV::GPRRegClass,
};

Expand Down
6 changes: 1 addition & 5 deletions llvm/lib/Target/RISCV/RISCVRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace llvm {

// This needs to be kept in sync with the field bits in VentusRegisterClass.
enum RISCVRCFlags { IsVGPR = 1 << 0, IsSGPR = 1 << 1, IsFGPR = 1 << 2 }; // enum RISCVRCFlags
enum RISCVRCFlags { IsVGPR = 1 << 0, IsSGPR = 1 << 1 }; // enum RISCVRCFlags

struct RISCVRegisterInfo : public RISCVGenRegisterInfo {

Expand All @@ -37,10 +37,6 @@ struct RISCVRegisterInfo : public RISCVGenRegisterInfo {
return RC->TSFlags & RISCVRCFlags::IsSGPR;
}

static bool hasFGPRs(const TargetRegisterClass *RC) {
return RC->TSFlags & RISCVRCFlags::IsFGPR;
}

/// Return the 'base' register class for this register.
/// e.g. X5 => SReg_32, V3 => VGPR_32, X5_X6 -> SReg_32, etc.
const TargetRegisterClass *getPhysRegClass(MCRegister Reg) const;
Expand Down
10 changes: 4 additions & 6 deletions llvm/lib/Target/RISCV/VentusRegisterInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ class RVRegisterClass <string n, list<ValueType> rTypes, int Align, dag rList>
// vALU and sALU registers
field bit IsVGPR = 0;
field bit IsSGPR = 0;
field bit IsFGPR = 0;

let TSFlags{0} = IsVGPR;
let TSFlags{1} = IsSGPR;
let TSFlags{2} = IsFGPR;
}

class RISCVReg<bits<8> Enc, string n, list<string> alt = []> : Register<n> {
Expand Down Expand Up @@ -417,10 +415,10 @@ def VCSR : RegisterClass<"RISCV", [XLenVT], 32,
let RegInfos = XLenRI;
}

let RegInfos = XLenRI, IsFGPR = 1 in {
def GPRF16 : RVRegisterClass<"RISCV", [f16], 16, (add GPR)>;
def GPRF32 : RVRegisterClass<"RISCV", [f32], 32, (add GPR)>;
def GPRF64 : RVRegisterClass<"RISCV", [f64], 64, (add GPR)>;
let RegInfos = XLenRI in {
def GPRF16 : RegisterClass<"RISCV", [f16], 16, (add GPR)>;
def GPRF32 : RegisterClass<"RISCV", [f32], 32, (add GPR)>;
def GPRF64 : RegisterClass<"RISCV", [f64], 64, (add GPR)>;
} // RegInfos = XLenRI

let RegAltNameIndices = [ABIRegAltName] in {
Expand Down

0 comments on commit 2b376d1

Please sign in to comment.