[llvm] [RISC-V][GISEL] Select G_BITCAST for scalable vectors (PR #101486)

Jiahan Xie via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 24 06:10:36 PDT 2024


================
@@ -757,13 +758,21 @@ bool RISCVInstructionSelector::replacePtrWithInt(MachineOperand &Op,
                                                  MachineIRBuilder &MIB,
                                                  MachineRegisterInfo &MRI) {
   Register PtrReg = Op.getReg();
-  assert(MRI.getType(PtrReg).isPointer() && "Operand is not a pointer!");
-
+  const LLT PtrTy = MRI.getType(PtrReg);
   const LLT sXLen = LLT::scalar(STI.getXLen());
-  auto PtrToInt = MIB.buildPtrToInt(sXLen, PtrReg);
-  MRI.setRegBank(PtrToInt.getReg(0), RBI.getRegBank(RISCV::GPRBRegBankID));
-  Op.setReg(PtrToInt.getReg(0));
-  return select(*PtrToInt);
+  if (PtrTy.isPointer()) {
+    auto PtrToInt = MIB.buildPtrToInt(sXLen, PtrReg);
+    MRI.setRegBank(PtrToInt.getReg(0), RBI.getRegBank(RISCV::GPRBRegBankID));
+    Op.setReg(PtrToInt.getReg(0));
+    return select(*PtrToInt);
+  }
+  assert(PtrTy.isPointerVector() &&
+         "Operand must be a pointer of a vector of pointers");
+  assert(PtrTy.isScalableVector() &&
+         "Currently only working for scalable vector of pointers now");
+  MRI.setType(PtrReg, LLT::scalable_vector(
----------------
jiahanxie353 wrote:

> We have a helper function called replacePtrWithInt. Maybe you can expand that to support vectors instead of doing it here in the code manually?

Not sure if makes sense to inplace update and return `true`, instead of building a new instruction like `G_PTRTOINT`. I didn't do it because there is no generic opcode for it and we have to go through `extract_elment` and apply each element with `G_PTRTOINT` which feels very cumbersome.

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


More information about the llvm-commits mailing list