Skip to content
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] remove unnecessary cast op #49919

Closed
rotateright opened this issue Jun 3, 2021 · 3 comments
Closed

[InstCombine] remove unnecessary cast op #49919

rotateright opened this issue Jun 3, 2021 · 3 comments
Labels
bugzilla Issues migrated from bugzilla

Comments

@rotateright
Copy link
Contributor

Bugzilla Link 50575
Resolution FIXED
Resolved on Jun 04, 2021 04:23
Version trunk
OS All
CC @LebedevRI,@RKSimon

Extended Description

Forking this off from bug 49543 - we can eliminate an intermediate cast in a sequence like this by using 'ashr' to replicate the signbit:

define i64 @​src(i32 %a0) {
%a = lshr i32 %a0, 24
%b = trunc i32 %a to i8
%c = sext i8 %b to i64
ret i64 %c
}

define i64 @​tgt(i32 %a0) {
%a = ashr i32 %a0, 24
%c = sext i32 %a to i64
ret i64 %c
}

@rotateright
Copy link
Contributor Author

We should also handle the case where the initial width is bigger than the destination:

define i26 @​src(i32 %a0) {
%a = lshr i32 %a0, 24
%b = trunc i32 %a to i8
%c = sext i8 %b to i26
ret i26 %c
}

Instead of a sext, we need to trunc:

define i26 @​tgt(i32 %a0) {
%a = ashr i32 %a0, 24
%c = trunc i32 %a to i26
ret i26 %c
}

We already handle the pattern where initial width == dest width by converting to shifts (lshr cancels out shl in that case).

@LebedevRI
Copy link
Member

@rotateright
Copy link
Contributor Author

Also see https://reviews.llvm.org/rG41b71f718b94c6f12bbaa670e97cabb070308ed2

Thanks! That goes a bit further than what I had drafted, so I pushed extra tests and a smaller patch as a first step:
https://reviews.llvm.org/rG8937450e8581
https://reviews.llvm.org/rG23a116c8c446

Hopefully, the basic cases here are fixed now.

I left TODO comments on the tests for the remaining part.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

2 participants