-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[GlobalISel] Fix store merging incorrectly classifying an unknown index expr as 0. #90375
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 |
---|---|---|
|
@@ -162,6 +162,13 @@ | |
ret void | ||
} | ||
|
||
@G = external global [10 x i32] | ||
define void @invalid_zero_offset_no_merge(i64 %0) { | ||
%2 = getelementptr [10 x i32], ptr @G, i64 0, i64 %0 | ||
store i32 0, ptr %2, align 4 | ||
store i32 0, ptr getelementptr inbounds ([10 x i32], ptr @G, i64 0, i64 1), align 4 | ||
ret void | ||
} | ||
... | ||
--- | ||
name: test_simple_2xs8 | ||
|
@@ -582,13 +589,11 @@ liveins: | |
frameInfo: | ||
maxAlignment: 1 | ||
machineFunctionInfo: {} | ||
# The store to ptr2 prevents merging into a single store. | ||
# We can still merge the stores into addr1 and addr2. | ||
body: | | ||
bb.1 (%ir-block.0): | ||
liveins: $x0, $x1 | ||
|
||
; The store to ptr2 prevents merging into a single store. | ||
; We can still merge the stores into addr1 and addr2. | ||
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. Should these comments be removed? 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. No but I can't seem to get the update script to keep them. 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. You can try to move the comment above the |
||
|
||
; CHECK-LABEL: name: test_alias_4xs16 | ||
; CHECK: liveins: $x0, $x1 | ||
; CHECK-NEXT: {{ $}} | ||
|
@@ -639,10 +644,10 @@ liveins: | |
frameInfo: | ||
maxAlignment: 1 | ||
machineFunctionInfo: {} | ||
# Here store of 5 and 9 can be merged, others have aliasing barriers. | ||
body: | | ||
bb.1 (%ir-block.0): | ||
liveins: $x0, $x1, $x2 | ||
; Here store of 5 and 9 can be merged, others have aliasing barriers. | ||
; CHECK-LABEL: name: test_alias2_4xs16 | ||
; CHECK: liveins: $x0, $x1, $x2 | ||
; CHECK-NEXT: {{ $}} | ||
|
@@ -698,12 +703,11 @@ liveins: | |
frameInfo: | ||
maxAlignment: 1 | ||
machineFunctionInfo: {} | ||
# No merging can be done here. | ||
body: | | ||
bb.1 (%ir-block.0): | ||
liveins: $x0, $x1, $x2, $x3 | ||
|
||
; No merging can be done here. | ||
|
||
; CHECK-LABEL: name: test_alias3_4xs16 | ||
; CHECK: liveins: $x0, $x1, $x2, $x3 | ||
; CHECK-NEXT: {{ $}} | ||
|
@@ -767,12 +771,10 @@ stack: | |
- { id: 0, name: a1, size: 24, alignment: 4 } | ||
- { id: 1, name: a2, size: 4, alignment: 4 } | ||
machineFunctionInfo: {} | ||
# Can merge because the load is from a different alloca and can't alias. | ||
body: | | ||
bb.1 (%ir-block.0): | ||
liveins: $x0 | ||
|
||
; Can merge because the load is from a different alloca and can't alias. | ||
|
||
; CHECK-LABEL: name: test_alias_allocas_2xs32 | ||
; CHECK: liveins: $x0 | ||
; CHECK-NEXT: {{ $}} | ||
|
@@ -826,3 +828,43 @@ body: | | |
RET_ReallyLR | ||
|
||
... | ||
--- | ||
name: invalid_zero_offset_no_merge | ||
alignment: 4 | ||
tracksRegLiveness: true | ||
liveins: | ||
- { reg: '$x0' } | ||
frameInfo: | ||
maxAlignment: 1 | ||
machineFunctionInfo: {} | ||
body: | | ||
bb.1 (%ir-block.1): | ||
liveins: $x0 | ||
|
||
; CHECK-LABEL: name: invalid_zero_offset_no_merge | ||
; CHECK: liveins: $x0 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0 | ||
; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 2 | ||
; CHECK-NEXT: [[SHL:%[0-9]+]]:_(s64) = G_SHL [[COPY]], [[C]](s64) | ||
; CHECK-NEXT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @G | ||
; CHECK-NEXT: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[GV]], [[SHL]](s64) | ||
; CHECK-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 0 | ||
; CHECK-NEXT: G_STORE [[C1]](s32), [[PTR_ADD]](p0) :: (store (s32) into %ir.2) | ||
; CHECK-NEXT: [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 4 | ||
; CHECK-NEXT: [[PTR_ADD1:%[0-9]+]]:_(p0) = nuw G_PTR_ADD [[GV]], [[C2]](s64) | ||
; CHECK-NEXT: G_STORE [[C1]](s32), [[PTR_ADD1]](p0) :: (store (s32) into `ptr getelementptr inbounds ([10 x i32], ptr @G, i64 0, i64 1)`) | ||
; CHECK-NEXT: RET_ReallyLR | ||
%0:_(s64) = COPY $x0 | ||
%9:_(s64) = G_CONSTANT i64 2 | ||
%3:_(s64) = G_SHL %0, %9(s64) | ||
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 is similar to the reported issue, but G_MUL vs. G_SHL?!? 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. Yes |
||
%1:_(p0) = G_GLOBAL_VALUE @G | ||
%4:_(p0) = G_PTR_ADD %1, %3(s64) | ||
%6:_(s32) = G_CONSTANT i32 0 | ||
G_STORE %6(s32), %4(p0) :: (store (s32) into %ir.2) | ||
%8:_(s64) = G_CONSTANT i64 4 | ||
%7:_(p0) = nuw G_PTR_ADD %1, %8(s64) | ||
G_STORE %6(s32), %7(p0) :: (store (s32) into `ptr getelementptr inbounds ([10 x i32], ptr @G, i64 0, i64 1)`) | ||
RET_ReallyLR | ||
|
||
... |
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.
If IndexReg was only set if there was no offset found (so we decomposed into
base + index + constant
), and maybe we checked BasePtr0.getIndex() == BasePtr1.getIndex() below, then would it help solve the problem without needing to make Offset optional?It doesn't look like IndexReg is used at the moment, so it might be simpler for the time being to remove it and make the above mi_match match
m_GPtrAdd(m_Reg(BaseReg), m_ICst(RHSCst)))
?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 think I'd rather keep the optional offset, since this is actually getting closer to mirroring the equivalent analysis in SelectionDAG, and one day I think it'd be nice to have some abstraction over LLT-reg/EVT-SDValue for these things to share code.