[llvm] [LoopIdiom] Add a range attribute to formed memset/memcpy/memmove (PR #226801)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 27 08:50:47 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Kuba (Brecka) Mracek (kubamracek)
<details>
<summary>Changes</summary>
Part 1 of optimizing a recognized memset (see example below): Adding a range attribute to the memset call so that the upper bound is carried in the IR. Part 2 will prevent lowering a (non-constant) llvm.memset with a small upper bound into a memset libcall (expensive) and instead emit a branch or per-size branches instead (cheap).
This PR:
> Attach a range attribute to the length (or, for memset.pattern, the count) operand. The upper bound comes from the loop's constant maximum backedge-taken count and conditions guarding the loop, which also hold at the new call in the preheader. For a loop like this...
>
> for (unsigned i = n; i < 4; ++i)
> dst[i] = -1;
>
> ...the memset gets `i64 range(i64 0, 17)`.
>
> LoopIdiomRecognize applies this to memset, memset.pattern, memcpy and memmove calls.
Assisted-by: Claude
---
Full diff: https://github.com/llvm/llvm-project/pull/226801.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp (+50-1)
- (added) llvm/test/Transforms/LoopIdiom/mem-intrinsic-length-range.ll (+74)
``````````diff
The server is unavailable at this time. Please wait a few minutes before you try again.
``````````
</details>
https://github.com/llvm/llvm-project/pull/226801
More information about the llvm-commits
mailing list