[llvm] [InstCombine] Added optimization for shift add (PR #163502)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 15 20:03:31 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index 85326bd5b..c81dad951 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -632,7 +632,8 @@ static bool canEvaluateShifted(Value *V, unsigned NumBits, bool IsLeftShift,
return false;
// Both operands must be shiftable, pass through CxtI to preserve shift type
- return canEvaluateShifted(I->getOperand(0), NumBits, IsLeftShift, IC, CxtI) &&
+ return canEvaluateShifted(I->getOperand(0), NumBits, IsLeftShift, IC,
+ CxtI) &&
canEvaluateShifted(I->getOperand(1), NumBits, IsLeftShift, IC, CxtI);
}
@@ -1679,8 +1680,8 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
// when the shift is exact and the add has nuw.
const APInt *ShAmtAPInt, *ShlAmt, *AddC;
if (match(Op1, m_APInt(ShAmtAPInt)) && I.isExact() &&
- match(Op0, m_c_NUWAdd(m_NUWShl(m_Value(X), m_APInt(ShlAmt)),
- m_APInt(AddC))) &&
+ match(Op0,
+ m_c_NUWAdd(m_NUWShl(m_Value(X), m_APInt(ShlAmt)), m_APInt(AddC))) &&
ShlAmt->uge(*ShAmtAPInt)) {
unsigned ShAmt = ShAmtAPInt->getZExtValue();
// Check if C is divisible by (1 << ShAmt)
``````````
</details>
https://github.com/llvm/llvm-project/pull/163502
More information about the llvm-commits
mailing list