[llvm] [TailRecElim] Introduce support for shift accumulator optimization (PR #181331)

via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 21 07:35:49 PST 2026


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/Scalar/TailRecursionElimination.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/Scalar/TailRecursionElimination.cpp b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
index 51f1143de..5d77e422e 100644
--- a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
@@ -381,9 +381,9 @@ static bool canMoveAboveCall(Instruction *I, CallInst *CI, AliasAnalysis *AA) {
 // This relation applies to left shifts as well as arithmetic/logical right
 // shifts when the shift amount is a constant.
 static bool isPseudoAssociative(Instruction *I) {
-    if (!I->isShift())
-      return false;
-    return isa<ConstantInt>(I->getOperand(1));
+  if (!I->isShift())
+    return false;
+  return isa<ConstantInt>(I->getOperand(1));
 }
 
 // Find the base-case return value for function F: examine all
@@ -406,10 +406,10 @@ static Constant *getReturnValue(Function &F) {
   Constant *BaseCaseVal = nullptr;
 
   // Local lambda with conservative bail-out: It isn't so trivial to perform TRE
-  // if the return value depends on the result of a recursive call, because the return value will be different
-  // for different iterations of the recursion. So we ignore return values
-  // that depend on recursive calls.
-  auto TryGetConstantBaseCase = [&](Value *RV) -> Constant* {
+  // if the return value depends on the result of a recursive call, because the
+  // return value will be different for different iterations of the recursion.
+  // So we ignore return values that depend on recursive calls.
+  auto TryGetConstantBaseCase = [&](Value *RV) -> Constant * {
     // Case 1: direct constant return.
     if (auto *C = dyn_cast<Constant>(RV))
       return C;

``````````

</details>


https://github.com/llvm/llvm-project/pull/181331


More information about the llvm-commits mailing list