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

Federico Bruzzone via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 24 00:38:50 PDT 2026


FedericoBruzzone wrote:

@efriedma-quic thanks for your review.

LLVM side the transformation you're referring to is already implemented sometime (e.g., [the argument marked as `returned`](https://godbolt.org/z/fz8nfesnb)).
However, by marking the _unary function_ as `const`/`pure` [inline happens](https://godbolt.org/z/jo4n875Wf).  So, I manually marked the _unary fn_ as `memory(none)` (see [CompilerExplorer](https://godbolt.org/z/EcYrWodYs)), and as you suspect TRE side nothing happens. By further run TRE (via `opt -passes=tailcallelim input.ll -S -o output.ll`) nothing happens, _again_. 
So, we should definitely cover this kind of opt TRE side when the _unary function_ is pure, but I believe that falls outside the scope of the PR. 

Do you suggest to changing the name prematurely? Instead of _pseudo-associative_, to something like _unary accumulator recurrence_?


P.S. LLVM lowers to `llvm.sin.*` only when [`-fno-math-errno` is passed](https://godbolt.org/z/Yavz51xnh) in accordance with the [LangRef](https://llvm.org/docs/LangRef.html#llvm-sin-intrinsic).





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


More information about the llvm-commits mailing list