[llvm] [SystemZ] Improve handling of memmoves. (PR #196285)

Ulrich Weigand via llvm-commits llvm-commits at lists.llvm.org
Fri May 8 07:53:54 PDT 2026


================
@@ -10820,6 +10832,89 @@ SystemZTargetLowering::emitMemMemWrapper(MachineInstr &MI,
   return MBB;
 }
 
+MachineBasicBlock *
+SystemZTargetLowering::emitMemmoveImm(MachineInstr &MI,
+                                      MachineBasicBlock *MBB) const {
+  MachineFunction &MF = *MBB->getParent();
+  const SystemZInstrInfo *TII = Subtarget.getInstrInfo();
+  MachineRegisterInfo &MRI = MF.getRegInfo();
+
+  DebugLoc DL = MI.getDebugLoc();
+  MachineOperand DstBase = earlyUseOperand(MI.getOperand(0));
+  uint64_t DstDisp = MI.getOperand(1).getImm();
+  MachineOperand SrcBase = earlyUseOperand(MI.getOperand(2));
+  uint64_t SrcDisp = MI.getOperand(3).getImm();
+  uint64_t Len = MI.getOperand(4).getImm();
+  assert(Len >= 1 && Len <= 256 &&
+         "Memmove of of unsupported constant length.");
+  assert(isUInt<12>(DstDisp) && isUInt<12>(SrcDisp) &&
+         "Unexpected large displacement.");
+
+  // Fold any displacement (or frame index reference) into a new register.
+  auto foldAddressIfNeeded = [&](MachineOperand &Base, uint64_t &Disp) -> void {
+    if (Disp || Base.isFI()) {
+      Register Reg = MRI.createVirtualRegister(&SystemZ::ADDR64BitRegClass);
+      unsigned Opcode = TII->getOpcodeForOffset(SystemZ::LA, Disp);
+      BuildMI(*MBB, MI, DL, TII->get(Opcode), Reg)
+          .add(Base).addImm(Disp).addReg(0);
+      Base = MachineOperand::CreateReg(Reg, false);
+      Disp = 0;
+    }
+  };
----------------
uweigand wrote:

I think a lot this complexity is because this function tries to do too much at once.  We should really push everything higher up into the EmitTargetCodeForMemmove routine, whenever possible.  I understand we need this custom inserter to we can create control flow.   But e.g. the decision whether to use VLL/VSTL or MVC/MVCRL can be made earlier.

If this routine only handles MVC/MVCRL, it can have proper arguments, e.g. src and dst address in a register to being with, so we don't have to do any extra folding here.

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


More information about the llvm-commits mailing list