[llvm] [RISCV] Use shNadd for scalable stack offsets (PR #88062)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 10 07:24:07 PDT 2024


================
@@ -204,10 +204,21 @@ void RISCVRegisterInfo::adjustReg(MachineBasicBlock &MBB,
     uint32_t NumOfVReg = ScalableValue / 8;
     BuildMI(MBB, II, DL, TII->get(RISCV::PseudoReadVLENB), ScratchReg)
         .setMIFlag(Flag);
-    TII->mulImm(MF, MBB, II, DL, ScratchReg, NumOfVReg, Flag);
-    BuildMI(MBB, II, DL, TII->get(ScalableAdjOpc), DestReg)
-      .addReg(SrcReg).addReg(ScratchReg, RegState::Kill)
-      .setMIFlag(Flag);
+
+    if (ScalableAdjOpc == RISCV::ADD && ST.hasStdExtZba() &&
+        (NumOfVReg == 2 || NumOfVReg == 4 || NumOfVReg == 8)) {
+      unsigned Opc = NumOfVReg == 2 ? RISCV::SH1ADD :
+        (NumOfVReg == 4 ? RISCV::SH2ADD : RISCV::SH3ADD);
+      BuildMI(MBB, II, DL, TII->get(Opc), DestReg)
+          .addReg(ScratchReg, RegState::Kill)
+          .addReg(SrcReg, getKillRegState(KillSrcReg))
----------------
preames wrote:

Addressed in 5ae9ffbd18fd93edbbc8efebe140aeb24cd763c2.  Sorry for the confusion here, I misread my own code when looking at your comment.  I think it was a combination of the swapped operand order, and that the shXadd case below does use the KillSrcReg flag.  But still, sorry for the unhelpful and confusing initial response.  

https://github.com/llvm/llvm-project/pull/88062


More information about the llvm-commits mailing list