-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[InstCombine] Transform vector.reduce.add and splat into multiplication
#161020
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
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fa77c2c
[InstCombine] Transform `vector.reduce.add (splat %0, 4)` into `shl i…
spaits fb492be
Use getSplatValue and correctly construct APInt and add i64 test
spaits e9cc989
Address non power of 2 cases
spaits a8b32af
Update comments and move assertion to a more fitting place
spaits d11a108
Remove redundant power of 2 case
spaits 01eb571
Use ConstantInt::get instead of Constant::getIntegerValue
spaits 0adef1d
Add i1 test
spaits d2f235e
More small type tests
spaits 045f0ef
Throw out redundant i1 tests
spaits 027efe7
More consistent test naming
spaits 8e2c2e5
Use cast instead of static_cast
spaits ff6491b
Use BinaryOperator::CreateMul instead of using Builder and replaceIns…
spaits 38ca5ce
Extend testing
spaits 78a00dd
Remove assertion
spaits b86f985
Remove redundant variable and comment
spaits 2dd6052
Add a vscale test case
spaits 91e53d4
Formatting
spaits 8c31848
Rename a variable
spaits 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -64,6 +64,7 @@ | |||||
| #include "llvm/Support/KnownBits.h" | ||||||
| #include "llvm/Support/KnownFPClass.h" | ||||||
| #include "llvm/Support/MathExtras.h" | ||||||
| #include "llvm/Support/TypeSize.h" | ||||||
| #include "llvm/Support/raw_ostream.h" | ||||||
| #include "llvm/Transforms/InstCombine/InstCombiner.h" | ||||||
| #include "llvm/Transforms/Utils/AssumeBundleBuilder.h" | ||||||
|
|
@@ -3761,6 +3762,39 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) { | |||||
| return replaceInstUsesWith(CI, Res); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Handle the case where a splat is summarized. In that case we have a | ||||||
| // multpilication. For example: %2 = insertelement <4 x i32> poison, i32 | ||||||
| // %0, i64 0 %3 = shufflevector <4 x i32> %2, poison, <4 x i32> | ||||||
| // zeroinitializer %4 = tail call i32 @llvm.vector.reduce.add.v4i32(%3) | ||||||
| // => | ||||||
| // %2 = shl i32 %0, 2 | ||||||
| if (Value *Splat = getSplatValue(Arg)) { | ||||||
| // It is only a multiplication if we add the same element over and over. | ||||||
| assert(Arg->getType()->isVectorTy() && | ||||||
| "The vector.reduce.add intrinsic's argument must be a vector!"); | ||||||
| ElementCount ReducedVectorElementCount = | ||||||
| static_cast<VectorType *>(Arg->getType())->getElementCount(); | ||||||
|
||||||
| static_cast<VectorType *>(Arg->getType())->getElementCount(); | |
| cast<VectorType>(Arg->getType())->getElementCount(); |
And remove the assert.
spaits marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
spaits marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
spaits marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
spaits marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
spaits marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
spaits marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
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
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.
Uh oh!
There was an error while loading. Please reload this page.