[llvm] [RISCV][GlobalISel] Legalize Scalable Vector Loads and Stores (PR #84965)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 24 23:38:11 PDT 2024
================
@@ -651,6 +687,62 @@ bool RISCVLegalizerInfo::legalizeExt(MachineInstr &MI,
return true;
}
+bool RISCVLegalizerInfo::legalizeLoadStore(MachineInstr &MI,
+ LegalizerHelper &Helper,
+ MachineIRBuilder &MIB) const {
+ MachineRegisterInfo &MRI = *MIB.getMRI();
+ MachineFunction *MF = MI.getMF();
+ const DataLayout &DL = MIB.getDataLayout();
+ LLVMContext &Ctx = MF->getFunction().getContext();
+
+ Register DstReg = MI.getOperand(0).getReg();
+ Register PtrReg = MI.getOperand(1).getReg();
+ LLT DataTy = MRI.getType(DstReg);
+ if (!DataTy.isVector())
+ return false;
+
+ if (!(STI.hasVInstructions() &&
+ (DataTy.getScalarSizeInBits() != 64 || STI.hasVInstructionsI64()) &&
+ (DataTy.getElementCount().getKnownMinValue() != 1 ||
+ STI.getELen() == 64)))
+ return false;
+
+ if (!MI.hasOneMemOperand())
+ return false;
+
+ MachineMemOperand *MMO = *MI.memoperands_begin();
+ Align Alignment = MMO->getAlign();
+
+ const auto *TLI = STI.getTargetLowering();
+ EVT VT = EVT::getEVT(getTypeForLLT(DataTy, Ctx));
+
+ if (TLI->allowsMemoryAccessForAlignment(Ctx, DL, VT, *MMO))
+ return true;
+
+ unsigned EltSizeBits = DataTy.getScalarSizeInBits();
+ assert((EltSizeBits == 16 || EltSizeBits == 32 || EltSizeBits == 64) &&
+ "Unexpected unaligned RVV load type");
+
+ // Calculate the new vector type with i8 elements
+ unsigned NumElements =
+ DataTy.getElementCount().getKnownMinValue() * (EltSizeBits / 8);
+ LLT NewDataTy = LLT::scalable_vector(NumElements, 8);
+
+ MachinePointerInfo PI = MMO->getPointerInfo();
+ MachineMemOperand *NewMMO =
+ MF->getMachineMemOperand(PI, MMO->getFlags(), NewDataTy, Alignment);
+
+ if (isa<GLoad>(MI)) {
+ Helper.bitcast(MI, 0, NewDataTy);
+ } else {
+ assert(isa<GStore>(MI) && "Machine instructions must be Load/Store.");
+ Helper.bitcast(MI, 0, NewDataTy);
+ MIB.buildStore(MI.getOperand(0), PtrReg, *NewMMO);
----------------
topperc wrote:
Doesn't Helper.bitcast already rewrite the original store? Do we need to create a new one?
https://github.com/llvm/llvm-project/pull/84965
More information about the llvm-commits
mailing list