-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[InstCombine] recognize missed i128 split optimization #129363
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
[InstCombine] recognize missed i128 split optimization #129363
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-llvm-transforms Author: Muhammad Bassiouni (bassiounix) ChangesThis pr fixes #126056, recognising a split i128 extension optimization. Proof for working optimization: define i128 @<!-- -->src(i32 noundef %x) {
entry:
%coerce.sroa.0.0.extract.trunc = sext i32 %x to i64
%0 = ashr i32 %x, 31
%coerce.sroa.2.0.extract.trunc = sext i32 %0 to i64
%x.sroa.2.0.insert.ext.i = zext i64 %coerce.sroa.2.0.extract.trunc to i128
%x.sroa.2.0.insert.shift.i = shl nuw i128 %x.sroa.2.0.insert.ext.i, 64
%x.sroa.0.0.insert.ext.i = zext i64 %coerce.sroa.0.0.extract.trunc to i128
%x.sroa.0.0.insert.insert.i = or disjoint i128 %x.sroa.2.0.insert.shift.i, %x.sroa.0.0.insert.ext.i
ret i128 %x.sroa.0.0.insert.insert.i
}
define i128 @<!-- -->tgt(i32 noundef %x) {
%x.sroa.0.0.insert.insert.i = sext i32 %x to i128
ret i128 %x.sroa.0.0.insert.insert.i
} Full diff: https://github.com/llvm/llvm-project/pull/129363.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 175c653f17f07..cff95338650f2 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -3119,6 +3119,13 @@ static Value *matchOrConcat(Instruction &Or, InstCombiner::BuilderTy &Builder) {
match(UpperSrc, m_BitReverse(m_Value(UpperBRev))))
return ConcatIntrinsicCalls(Intrinsic::bitreverse, UpperBRev, LowerBRev);
+ Value *X;
+ if (match(LowerSrc, m_SExt(m_Value(X))) &&
+ match(UpperSrc,
+ m_SExt(m_AShr(m_Specific(X), m_SpecificInt(HalfWidth / 2 - 1))))) {
+ return Builder.CreateSExt(X, Ty);
+ }
+
return nullptr;
}
|
Can you please add some tests? See https://llvm.org/docs/InstCombineContributorGuide.html#tests |
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.
Please can you add another starting type, maybe i16?
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.
LGTM - cheers
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.
One minor tweak
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.
LGTM
@bassiounix Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
…))), bw) -> (sext x) fold Minor tweak llvm#129363 which handled all the cases where there was a sext for the original source value, but not for cases where the source is already half the size of the destination type Another regression noticed in llvm#76524
This pr fixes llvm#126056, recognising a split i128 extension optimization. Proof for working optimization: ```llvm define i128 @src(i32 noundef %x) { entry: %coerce.sroa.0.0.extract.trunc = sext i32 %x to i64 %0 = ashr i32 %x, 31 %coerce.sroa.2.0.extract.trunc = sext i32 %0 to i64 %x.sroa.2.0.insert.ext.i = zext i64 %coerce.sroa.2.0.extract.trunc to i128 %x.sroa.2.0.insert.shift.i = shl nuw i128 %x.sroa.2.0.insert.ext.i, 64 %x.sroa.0.0.insert.ext.i = zext i64 %coerce.sroa.0.0.extract.trunc to i128 %x.sroa.0.0.insert.insert.i = or disjoint i128 %x.sroa.2.0.insert.shift.i, %x.sroa.0.0.insert.ext.i ret i128 %x.sroa.0.0.insert.insert.i } define i128 @tgt(i32 noundef %x) { %x.sroa.0.0.insert.insert.i = sext i32 %x to i128 ret i128 %x.sroa.0.0.insert.insert.i } ```
…) -> (sext x) case llvm#129363 handled all the cases where there was a sext for the original source value, but not for cases where the source is already half the size of the destination type Another regression noticed in llvm#76524
This pr fixes #126056, recognising a split i128 extension optimization.
Proof for working optimization: