Skip to content

Commit 62eb32d

Browse files
committed
Check that the pointer operand is an Instruction
1 parent 3f0acb2 commit 62eb32d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,10 @@ RISCVGatherScatterLowering::determineBaseAndStride(Instruction *Ptr,
350350
SmallVector<Value *, 2> Ops(GEP->operands());
351351

352352
// If the base pointer is a vector, check if it's strided.
353-
if (GEP->getPointerOperand()->getType()->isVectorTy()) {
354-
auto [BaseBase, Stride] = determineBaseAndStride(
355-
cast<Instruction>(GEP->getPointerOperand()), Builder);
353+
Value *Base = GEP->getPointerOperand();
354+
if (auto *BaseInst = dyn_cast<Instruction>(Base);
355+
BaseInst && BaseInst->getType()->isVectorTy()) {
356+
auto [BaseBase, Stride] = determineBaseAndStride(BaseInst, Builder);
356357
// If GEP's offset is scalar then we can add it to the base pointer's base.
357358
auto IsScalar = [](Value *Idx) { return !Idx->getType()->isVectorTy(); };
358359
if (BaseBase && all_of(GEP->indices(), IsScalar)) {
@@ -366,7 +367,7 @@ RISCVGatherScatterLowering::determineBaseAndStride(Instruction *Ptr,
366367
}
367368

368369
// Base pointer needs to be a scalar.
369-
Value *ScalarBase = Ops[0];
370+
Value *ScalarBase = Base;
370371
if (ScalarBase->getType()->isVectorTy()) {
371372
ScalarBase = getSplatValue(ScalarBase);
372373
if (!ScalarBase)

0 commit comments

Comments
 (0)