[llvm] [RISCV] Slightly improve expanded multiply emulation in getVLENFactoredAmount. (PR #84113)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 5 20:59:03 PST 2024
================
@@ -3130,30 +3130,37 @@ void RISCVInstrInfo::getVLENFactoredAmount(MachineFunction &MF,
.addReg(N, RegState::Kill)
.setMIFlag(Flag);
} else {
- Register Acc = MRI.createVirtualRegister(&RISCV::GPRRegClass);
- BuildMI(MBB, II, DL, get(RISCV::ADDI), Acc)
- .addReg(RISCV::X0)
- .addImm(0)
- .setMIFlag(Flag);
+ Register Acc;
uint32_t PrevShiftAmount = 0;
for (uint32_t ShiftAmount = 0; NumOfVReg >> ShiftAmount; ShiftAmount++) {
- if (NumOfVReg & (1LL << ShiftAmount)) {
+ if (NumOfVReg & (1U << ShiftAmount)) {
if (ShiftAmount)
BuildMI(MBB, II, DL, get(RISCV::SLLI), DestReg)
.addReg(DestReg, RegState::Kill)
.addImm(ShiftAmount - PrevShiftAmount)
.setMIFlag(Flag);
- if (NumOfVReg >> (ShiftAmount + 1))
- BuildMI(MBB, II, DL, get(RISCV::ADD), Acc)
- .addReg(Acc, RegState::Kill)
- .addReg(DestReg)
- .setMIFlag(Flag);
+ if (NumOfVReg >> (ShiftAmount + 1)) {
+ // If we don't have an accmulator yet, create it and copy DestReg.
+ if (!Acc) {
+ Acc = MRI.createVirtualRegister(&RISCV::GPRRegClass);
+ BuildMI(MBB, II, DL, get(RISCV::ADDI), Acc)
+ .addReg(DestReg)
+ .addImm(0)
+ .setMIFlag(Flag);
----------------
lukel97 wrote:
Could also do
```suggestion
Acc = MRI.createVirtualRegister(&RISCV::GPRRegClass);
BuildMI(MBB, II, DL, get(RISCV::COPY), Acc)
.addReg(DestReg)
.setMIFlag(Flag);
```
https://github.com/llvm/llvm-project/pull/84113
More information about the llvm-commits
mailing list