-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[InstCombine] Handle scalable geps in EmitGEPOffset #71565
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,8 @@ Value *llvm::emitGEPOffset(IRBuilderBase *Builder, const DataLayout &DL, | |
for (User::op_iterator i = GEP->op_begin() + 1, e = GEP->op_end(); i != e; | ||
++i, ++GTI) { | ||
Value *Op = *i; | ||
uint64_t Size = DL.getTypeAllocSize(GTI.getIndexedType()) & PtrSizeMask; | ||
TypeSize TSize = DL.getTypeAllocSize(GTI.getIndexedType()); | ||
uint64_t Size = TSize.getKnownMinValue() & PtrSizeMask; | ||
if (Constant *OpC = dyn_cast<Constant>(Op)) { | ||
if (OpC->isZeroValue()) | ||
continue; | ||
|
@@ -70,10 +71,12 @@ Value *llvm::emitGEPOffset(IRBuilderBase *Builder, const DataLayout &DL, | |
// Convert to correct type. | ||
if (Op->getType() != IntIdxTy) | ||
Op = Builder->CreateIntCast(Op, IntIdxTy, true, Op->getName() + ".c"); | ||
if (Size != 1) { | ||
if (Size != 1 || TSize.isScalable()) { | ||
// We'll let instcombine(mul) convert this to a shl if possible. | ||
Op = Builder->CreateMul(Op, ConstantInt::get(IntIdxTy, Size), | ||
GEP->getName() + ".idx", false /*NUW*/, | ||
auto *ScaleC = ConstantInt::get(IntIdxTy, Size); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This expression should just be IRBuilder::getTypeSize(IntIdxTy, TSize). |
||
Value *Scale = | ||
!TSize.isScalable() ? ScaleC : Builder->CreateVScale(ScaleC); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion. It looks like the above CreateVectorSplat wouldn't handle scalable vectors either. That is actually a different form of scalable vector, but I'll try and address that in a separate patch. |
||
Op = Builder->CreateMul(Op, Scale, GEP->getName() + ".idx", false /*NUW*/, | ||
isInBounds /*NSW*/); | ||
} | ||
AddOffset(Op); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely clear on the role of PtrSizeMask, but it seems odd to be applying this to the known min value for a scalable vector and not the full dynamic type size. Doesn't seem to match the fixed vector semantics.