[llvm] 035c154 - [RISCV] Refactor RISCVPostRAExpandPseudo::expandMovImm and RISCVInstrInfo::movImm to prepare for merging.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 27 13:36:06 PDT 2023
Author: Craig Topper
Date: 2023-10-27T13:35:56-07:00
New Revision: 035c154f4f6ebf7d7c5cc4a21c267b3a08bfb062
URL: https://github.com/llvm/llvm-project/commit/035c154f4f6ebf7d7c5cc4a21c267b3a08bfb062
DIFF: https://github.com/llvm/llvm-project/commit/035c154f4f6ebf7d7c5cc4a21c267b3a08bfb062.diff
LOG: [RISCV] Refactor RISCVPostRAExpandPseudo::expandMovImm and RISCVInstrInfo::movImm to prepare for merging.
Fix small bug where RISCVPostRAExpandPseudo::expandMovImm set the
kill flag on X0.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
llvm/lib/Target/RISCV/RISCVPostRAExpandPseudoInsts.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
index 9e4e86100a2115b..d430524bb11e1f4 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -787,6 +787,7 @@ void RISCVInstrInfo::movImm(MachineBasicBlock &MBB,
assert(!Seq.empty());
for (const RISCVMatInt::Inst &Inst : Seq) {
+ unsigned SrcRegState = getKillRegState(SrcReg != RISCV::X0);
switch (Inst.getOpndKind()) {
case RISCVMatInt::Imm:
BuildMI(MBB, MBBI, DL, get(Inst.getOpcode()), DstReg)
@@ -795,19 +796,19 @@ void RISCVInstrInfo::movImm(MachineBasicBlock &MBB,
break;
case RISCVMatInt::RegX0:
BuildMI(MBB, MBBI, DL, get(Inst.getOpcode()), DstReg)
- .addReg(SrcReg, getKillRegState(SrcReg != RISCV::X0))
+ .addReg(SrcReg, SrcRegState)
.addReg(RISCV::X0)
.setMIFlag(Flag);
break;
case RISCVMatInt::RegReg:
BuildMI(MBB, MBBI, DL, get(Inst.getOpcode()), DstReg)
- .addReg(SrcReg, getKillRegState(SrcReg != RISCV::X0))
- .addReg(SrcReg, getKillRegState(SrcReg != RISCV::X0))
+ .addReg(SrcReg, SrcRegState)
+ .addReg(SrcReg, SrcRegState)
.setMIFlag(Flag);
break;
case RISCVMatInt::RegImm:
BuildMI(MBB, MBBI, DL, get(Inst.getOpcode()), DstReg)
- .addReg(SrcReg, getKillRegState(SrcReg != RISCV::X0))
+ .addReg(SrcReg, SrcRegState)
.addImm(Inst.getImm())
.setMIFlag(Flag);
break;
diff --git a/llvm/lib/Target/RISCV/RISCVPostRAExpandPseudoInsts.cpp b/llvm/lib/Target/RISCV/RISCVPostRAExpandPseudoInsts.cpp
index 407e7cfd6fef830..2a5b693a5b4f59d 100644
--- a/llvm/lib/Target/RISCV/RISCVPostRAExpandPseudoInsts.cpp
+++ b/llvm/lib/Target/RISCV/RISCVPostRAExpandPseudoInsts.cpp
@@ -101,36 +101,32 @@ bool RISCVPostRAExpandPseudo::expandMovImm(MachineBasicBlock &MBB,
for (RISCVMatInt::Inst &Inst : Seq) {
bool LastItem = ++Num == Seq.size();
+ unsigned DstRegState = getDeadRegState(DstIsDead && LastItem) |
+ getRenamableRegState(Renamable);
+ unsigned SrcRegState = getKillRegState(SrcReg != RISCV::X0) |
+ getRenamableRegState(SrcRenamable);
switch (Inst.getOpndKind()) {
case RISCVMatInt::Imm:
BuildMI(MBB, MBBI, DL, TII->get(Inst.getOpcode()))
- .addReg(DstReg, RegState::Define |
- getDeadRegState(DstIsDead && LastItem) |
- getRenamableRegState(Renamable))
+ .addReg(DstReg, RegState::Define | DstRegState)
.addImm(Inst.getImm());
break;
case RISCVMatInt::RegX0:
BuildMI(MBB, MBBI, DL, TII->get(Inst.getOpcode()))
- .addReg(DstReg, RegState::Define |
- getDeadRegState(DstIsDead && LastItem) |
- getRenamableRegState(Renamable))
- .addReg(SrcReg, RegState::Kill | getRenamableRegState(SrcRenamable))
+ .addReg(DstReg, RegState::Define | DstRegState)
+ .addReg(SrcReg, SrcRegState)
.addReg(RISCV::X0);
break;
case RISCVMatInt::RegReg:
BuildMI(MBB, MBBI, DL, TII->get(Inst.getOpcode()))
- .addReg(DstReg, RegState::Define |
- getDeadRegState(DstIsDead && LastItem) |
- getRenamableRegState(Renamable))
- .addReg(SrcReg, RegState::Kill | getRenamableRegState(SrcRenamable))
- .addReg(SrcReg, RegState::Kill | getRenamableRegState(SrcRenamable));
+ .addReg(DstReg, RegState::Define | DstRegState)
+ .addReg(SrcReg, SrcRegState)
+ .addReg(SrcReg, SrcRegState);
break;
case RISCVMatInt::RegImm:
BuildMI(MBB, MBBI, DL, TII->get(Inst.getOpcode()))
- .addReg(DstReg, RegState::Define |
- getDeadRegState(DstIsDead && LastItem) |
- getRenamableRegState(Renamable))
- .addReg(SrcReg, RegState::Kill | getRenamableRegState(SrcRenamable))
+ .addReg(DstReg, RegState::Define | DstRegState)
+ .addReg(SrcReg, SrcRegState)
.addImm(Inst.getImm());
break;
}
More information about the llvm-commits
mailing list