-
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 1 commit
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 | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1528,7 +1528,17 @@ Instruction *InstCombinerImpl::visitSExt(SExtInst &Sext) { | |||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Try to extend the entire expression tree to the wide destination type. | ||||||||||||||||||||||||||||||
| if (shouldChangeType(SrcTy, DestTy) && canEvaluateSExtd(Src, DestTy)) { | ||||||||||||||||||||||||||||||
| bool shouldExtendExpression = true; | ||||||||||||||||||||||||||||||
| Value *X = nullptr; | ||||||||||||||||||||||||||||||
| // Do not extend expression in the trunc + sext pattern when destination type | ||||||||||||||||||||||||||||||
| // is narrower than original (pre-trunc) type: modern architectures typically | ||||||||||||||||||||||||||||||
| // provide efficient sign-extend instruction, so preserving the sext is | ||||||||||||||||||||||||||||||
| // preferable here. | ||||||||||||||||||||||||||||||
| if (match(Src, m_Trunc(m_Value(X)))) | ||||||||||||||||||||||||||||||
| if (X->getType()->getScalarSizeInBits() > DestBitSize) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| Value *X = nullptr; | |
| // Do not extend expression in the trunc + sext pattern when destination type | |
| // is narrower than original (pre-trunc) type: modern architectures typically | |
| // provide efficient sign-extend instruction, so preserving the sext is | |
| // preferable here. | |
| if (match(Src, m_Trunc(m_Value(X)))) | |
| if (X->getType()->getScalarSizeInBits() > DestBitSize) | |
| Value *TruncSrc = nullptr; | |
| // Do not extend expression in the trunc + sext pattern when destination type | |
| // is narrower than original (pre-trunc) type: modern architectures typically | |
| // provide efficient sign-extend instruction, so preserving the sext is | |
| // preferable here. | |
| if (match(Src, m_Trunc(m_Value(TruncSrc)))) | |
| if (TruncSrc->getType()->getScalarSizeInBits() > DestBitSize) |
Copilot
AI
Sep 24, 2025
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.
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.
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.
done