Skip to content

[RISCV] Match constant indices of non-index type when forming strided ops #65777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,19 @@ RISCVGatherScatterLowering::determineBaseAndStride(Instruction *Ptr,
// We can't extract the stride if the arithmetic is done at a different size
// than the pointer type. Adding the stride later may not wrap correctly.
// Technically we could handle wider indices, but I don't expect that in
// practice.
// practice. Handle one special case here - constants. This simplifies
// writing test cases.
Value *VecIndex = Ops[*VecOperand];
Type *VecIntPtrTy = DL->getIntPtrType(GEP->getType());
if (VecIndex->getType() != VecIntPtrTy)
return std::make_pair(nullptr, nullptr);
if (VecIndex->getType() != VecIntPtrTy) {
auto *VecIndexC = dyn_cast<Constant>(VecIndex);
if (!VecIndexC)
return std::make_pair(nullptr, nullptr);
if (VecIndex->getType()->getScalarSizeInBits() > VecIntPtrTy->getScalarSizeInBits())
VecIndex = ConstantFoldCastInstruction(Instruction::Trunc, VecIndexC, VecIntPtrTy);
else
VecIndex = ConstantFoldCastInstruction(Instruction::SExt, VecIndexC, VecIntPtrTy);
}

// Handle the non-recursive case. This is what we see if the vectorizer
// decides to use a scalar IV + vid on demand instead of a vector IV.
Expand Down
Loading