Skip to content

Commit aa6a40d

Browse files
committed
Move down call to determineBaseAndStride to avoid generating code without passing the checks
1 parent 62eb32d commit aa6a40d

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,16 +353,19 @@ RISCVGatherScatterLowering::determineBaseAndStride(Instruction *Ptr,
353353
Value *Base = GEP->getPointerOperand();
354354
if (auto *BaseInst = dyn_cast<Instruction>(Base);
355355
BaseInst && BaseInst->getType()->isVectorTy()) {
356-
auto [BaseBase, Stride] = determineBaseAndStride(BaseInst, Builder);
357356
// If GEP's offset is scalar then we can add it to the base pointer's base.
358357
auto IsScalar = [](Value *Idx) { return !Idx->getType()->isVectorTy(); };
359-
if (BaseBase && all_of(GEP->indices(), IsScalar)) {
360-
Builder.SetInsertPoint(GEP);
361-
SmallVector<Value *> Indices(GEP->indices());
362-
Value *OffsetBase =
363-
Builder.CreateGEP(GEP->getSourceElementType(), BaseBase, Indices, "",
364-
GEP->isInBounds());
365-
return {OffsetBase, Stride};
358+
if (all_of(GEP->indices(), IsScalar)) {
359+
auto [BaseBase, Stride] = determineBaseAndStride(BaseInst, Builder);
360+
if (BaseBase) {
361+
Builder.SetInsertPoint(GEP);
362+
SmallVector<Value *> Indices(GEP->indices());
363+
Value *OffsetBase =
364+
Builder.CreateGEP(GEP->getSourceElementType(), BaseBase, Indices,
365+
"", GEP->isInBounds());
366+
OffsetBase->takeName(GEP);
367+
return {OffsetBase, Stride};
368+
}
366369
}
367370
}
368371

0 commit comments

Comments
 (0)