Skip to content

[SLP] The order of store chains needs to consider the size of the values. #101810

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

Merged
merged 1 commit into from
Aug 7, 2024
Merged
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
6 changes: 6 additions & 0 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19123,6 +19123,12 @@ bool SLPVectorizerPass::vectorizeStoreChains(BoUpSLP &R) {
if (V->getPointerOperandType()->getTypeID() >
V2->getPointerOperandType()->getTypeID())
return false;
if (V->getValueOperand()->getType()->getScalarSizeInBits() <
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you also need to update the checks in AreCompatibleStores lambda

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to compare getTypeID() rather than size here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getTypeID has been compared above, but with the same TypeID, such as IntegerTyID, which can have different sizes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, getTypeID() above compared for pointer operands, which worked for typed pointers. You need to use getTypeID for value operand types

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you miss lines 19114 to 19122, which compare the value operand types?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes. Then there is a question, of why it did not work, because it should work correctly for compatible types

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i8 and i64 are not compatible types, but they have the same Type ID, IntegerTyID

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, missed it.

V2->getValueOperand()->getType()->getScalarSizeInBits())
return true;
if (V->getValueOperand()->getType()->getScalarSizeInBits() >
V2->getValueOperand()->getType()->getScalarSizeInBits())
return false;
// UndefValues are compatible with all other values.
if (isa<UndefValue>(V->getValueOperand()) ||
isa<UndefValue>(V2->getValueOperand()))
Expand Down
10 changes: 1 addition & 9 deletions llvm/test/Transforms/SLPVectorizer/X86/stores_mix_sizes.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,9 @@ define void @test(ptr %p) {
; CHECK-SAME: ptr [[P:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[IDX1:%.*]] = getelementptr i8, ptr [[P]], i64 1
; CHECK-NEXT: store i8 0, ptr [[IDX1]], align 4
; CHECK-NEXT: [[IDX_64_9:%.*]] = getelementptr i64, ptr [[P]], i64 9
; CHECK-NEXT: store i64 1, ptr [[IDX_64_9]], align 8
; CHECK-NEXT: [[IDX2:%.*]] = getelementptr i8, ptr [[P]], i64 2
; CHECK-NEXT: store <4 x i8> zeroinitializer, ptr [[IDX2]], align 4
; CHECK-NEXT: [[IDX6:%.*]] = getelementptr i8, ptr [[P]], i64 6
; CHECK-NEXT: store i8 0, ptr [[IDX6]], align 4
; CHECK-NEXT: [[IDX7:%.*]] = getelementptr i8, ptr [[P]], i64 7
; CHECK-NEXT: store i8 0, ptr [[IDX7]], align 4
; CHECK-NEXT: [[IDX8:%.*]] = getelementptr i8, ptr [[P]], i64 8
; CHECK-NEXT: store i8 0, ptr [[IDX8]], align 4
; CHECK-NEXT: store <8 x i8> zeroinitializer, ptr [[IDX1]], align 4
; CHECK-NEXT: ret void
;
entry:
Expand Down
Loading