-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[Instcombine] Avoid widening trunc+sext to trunc+shl+ashr when not profitable #160483
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
e9d5680
1d0a139
4160bec
4b636bf
00d2e6e
001f07d
1c5d599
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 |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 | ||
| ; RUN: opt < %s -passes=instcombine -S | FileCheck %s | ||
|
|
||
| target datalayout = "i16:16:16-i32:32:32-i64:64:64-n16:32:64" | ||
|
|
||
| define i32 @test(i64 %i) { | ||
|
Member
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. Can you please add a test with It should be folded into
Contributor
Author
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.
Thanks for the suggestion. Done in 1c5d599. It requires an additional change to the part |
||
| ; CHECK-LABEL: define i32 @test( | ||
| ; CHECK-SAME: i64 [[I:%.*]]) { | ||
| ; CHECK-NEXT: [[A:%.*]] = trunc i64 [[I]] to i16 | ||
| ; CHECK-NEXT: [[B:%.*]] = sext i16 [[A]] to i32 | ||
| ; CHECK-NEXT: ret i32 [[B]] | ||
| ; | ||
| %a = trunc i64 %i to i16 | ||
| %b = sext i16 %a to i32 | ||
| ret i32 %b | ||
| } | ||
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 variable X is being reused for two different purposes. In the first block (lines 1532-1539), it's used to check the transformation condition, while later at line 1561 it's used to continue the existing trunc optimization. This creates unclear control flow since X's value depends on whether the match succeeded earlier. Consider using a separate variable name for the first check to make the code more readable.