Skip to content

Commit 014390d

Browse files
authored
[RISCV] Implement cross basic block VXRM write insertion. (#70382)
This adds a new pass to insert VXRM writes for vector instructions. With the goal of avoiding redundant writes. The pass does 2 dataflow algorithms. The first is a forward data flow to calculate where a VXRM value is available. The second is a backwards dataflow to determine where a VXRM value is anticipated. Finally, we use the results of these two dataflows to insert VXRM writes where a value is anticipated, but not available. The pass does not split critical edges so we aren't always able to eliminate all redundancy. The pass will only insert vxrm writes on paths that always require it.
1 parent 2c2fb8e commit 014390d

File tree

8 files changed

+1019
-17
lines changed

8 files changed

+1019
-17
lines changed

llvm/lib/Target/RISCV/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ add_llvm_target(RISCVCodeGen
3838
RISCVGatherScatterLowering.cpp
3939
RISCVInsertVSETVLI.cpp
4040
RISCVInsertReadWriteCSR.cpp
41+
RISCVInsertWriteVXRM.cpp
4142
RISCVInstrInfo.cpp
4243
RISCVISelDAGToDAG.cpp
4344
RISCVISelLowering.cpp

llvm/lib/Target/RISCV/RISCV.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ void initializeRISCVPostRAExpandPseudoPass(PassRegistry &);
7171
FunctionPass *createRISCVInsertReadWriteCSRPass();
7272
void initializeRISCVInsertReadWriteCSRPass(PassRegistry &);
7373

74+
FunctionPass *createRISCVInsertWriteVXRMPass();
75+
void initializeRISCVInsertWriteVXRMPass(PassRegistry &);
76+
7477
FunctionPass *createRISCVRedundantCopyEliminationPass();
7578
void initializeRISCVRedundantCopyEliminationPass(PassRegistry &);
7679

llvm/lib/Target/RISCV/RISCVInsertReadWriteCSR.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// of the RISC-V instructions.
1010
//
1111
// Currently the pass implements:
12-
// -Naive insertion of a write to vxrm before an RVV fixed-point instruction.
1312
// -Writing and saving frm before an RVV floating-point instruction with a
1413
// static rounding mode and restores the value after.
1514
//
@@ -58,25 +57,11 @@ char RISCVInsertReadWriteCSR::ID = 0;
5857
INITIALIZE_PASS(RISCVInsertReadWriteCSR, DEBUG_TYPE,
5958
RISCV_INSERT_READ_WRITE_CSR_NAME, false, false)
6059

61-
// This function inserts a write to vxrm when encountering an RVV fixed-point
62-
// instruction. This function also swaps frm and restores it when encountering
63-
// an RVV floating point instruction with a static rounding mode.
60+
// This function also swaps frm and restores it when encountering an RVV
61+
// floating point instruction with a static rounding mode.
6462
bool RISCVInsertReadWriteCSR::emitWriteRoundingMode(MachineBasicBlock &MBB) {
6563
bool Changed = false;
6664
for (MachineInstr &MI : MBB) {
67-
int VXRMIdx = RISCVII::getVXRMOpNum(MI.getDesc());
68-
if (VXRMIdx >= 0) {
69-
unsigned VXRMImm = MI.getOperand(VXRMIdx).getImm();
70-
71-
Changed = true;
72-
73-
BuildMI(MBB, MI, MI.getDebugLoc(), TII->get(RISCV::WriteVXRMImm))
74-
.addImm(VXRMImm);
75-
MI.addOperand(MachineOperand::CreateReg(RISCV::VXRM, /*IsDef*/ false,
76-
/*IsImp*/ true));
77-
continue;
78-
}
79-
8065
int FRMIdx = RISCVII::getFRMOpNum(MI.getDesc());
8166
if (FRMIdx < 0)
8267
continue;

0 commit comments

Comments
 (0)