[llvm] [RISC-V][GISEL] Select G_BITCAST for scalable vectors (PR #101486)
Michael Maitland via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 24 08:07:32 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(
----------------
michaelmaitland wrote:
It [looks like AArch64](https://github.com/llvm/llvm-project/blob/3fbf6f8bb183ad8b9157e50c442479f4ca7a9b8d/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp#L2194) changes the type without building a PtrToInt. They say it works because all users have been selected already (bottom up selection) so the type does not matter for them. I think we can do the same thing, which is what you have done here.
I wonder if we really needed to build the PtrToInt above for the same reason. I can take a look at that in a follow up patch.
https://github.com/llvm/llvm-project/pull/101486
More information about the llvm-commits
mailing list