-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SLPVectorizer][X86] Free load cost for stores with constant pointers #118016
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
Closed
antoniofrighetto
wants to merge
1
commit into
llvm:main
from
antoniofrighetto:feature/x86tti-skip-load-vector
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
llvm/test/Transforms/SLPVectorizer/X86/buildvector_store_constant.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt -mtriple=x86_64-unknown-linux-gnu --passes=slp-vectorizer -S -o - %s | FileCheck %s | ||
|
||
@arr = global [20 x i64] zeroinitializer, align 16 | ||
|
||
define void @store_from_constant_ptr() { | ||
; CHECK-LABEL: define void @store_from_constant_ptr() { | ||
; CHECK-NEXT: store <2 x i64> splat (i64 1), ptr @arr, align 16 | ||
; CHECK-NEXT: store <2 x i64> splat (i64 1), ptr getelementptr inbounds (i8, ptr @arr, i64 16), align 16 | ||
; CHECK-NEXT: store <2 x i64> splat (i64 1), ptr getelementptr inbounds (i8, ptr @arr, i64 32), align 16 | ||
; CHECK-NEXT: ret void | ||
; | ||
store i64 1, ptr @arr, align 16 | ||
store i64 1, ptr getelementptr inbounds (i8, ptr @arr, i64 8), align 8 | ||
store i64 1, ptr getelementptr inbounds (i8, ptr @arr, i64 16), align 16 | ||
store i64 1, ptr getelementptr inbounds (i8, ptr @arr, i64 24), align 8 | ||
store i64 1, ptr getelementptr inbounds (i8, ptr @arr, i64 32), align 16 | ||
store i64 1, ptr getelementptr inbounds (i8, ptr @arr, i64 40), align 8 | ||
ret void | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We're trying to account for the cost of the constant vector load, but you want to skip it if the store address is constant?
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.
Looking at #111126 - shouldn't we be checking to see if
OpInfo.isUniform()
and adjusting the Type accordingly?It looks like the test case thinks it has to load a
<20 x i64> splat(i64 1)
constant when it just has to load<2 x i64> splat(i64 1)
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.
Sorry if I'm missing something, where is the Type being
<20 x i64>
in this case? AFAICT, there isn't any load associated to the store when the store address is constant in x86, as it should just be needed to compute the memory address.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.
The cost you are disabling in the code above is for the constant load - not the memory address computation.
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.
That's correct. There is no cost for any constant load. There is only a memory address computation, which is not a load.
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.
That's only true for scalars - for vector constant it must be loaded from the constant pool unless rematerialized (which for x86 means 0 or -1 splats only). That is the issue in #111126 - the load from
LCPI0_0
is being overestimated (its just a <2 x i64> load that is reused in all 10 stores but we're treating it as a <20 x i64> load):I'm investigating an alternative patch but have run out of time tonight :/
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, isn't this just bad codegen? In principle, we should be able to store the constant in the floating-point register, why would we need to load it from memory? GCC seems to catch this: https://godbolt.org/z/6baWMK4cW.
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.
Uhmm, we still need a load when dealing with arbitrary 64-bit constants.
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 any, the check would need to take this into account (scalar <= INT_MAX), but feel free to assess if there's a more favourable approach here.